Sign inSign up

obeoneorg/openai-usage-report

By obeoneorg

β€’Updated about 1 month ago

Image
0

2.3K

obeoneorg/openai-usage-report repository overview

⁠openai-usage-report πŸ“Š

Python PyPI Docker License

A command-line tool to inspect token usage and estimated cost for your OpenAI projects.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ OPENAI_ADMIN_API_KEY β”‚     β”‚ litellm Pricing  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚                          β”‚
          β–Ό                          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Fetch Projects &    β”‚     β”‚   Local Cache    β”‚
β”‚ Usage Data          β”‚     β”‚  (~/.cache/...)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚                          β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β–Ό
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚   Calculate Costs    β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β–Ό
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚ Color-coded Terminal β”‚
          β”‚       Table          β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β πŸš€ Features

FeatureDescription
πŸ“‹ List ProjectsSee all projects accessible with your admin API key
πŸ“Š Detailed UsageUsage data broken down by day or month, model, and API key
πŸ’° Auto-Updated PricingPricing fetched from litellm⁠ and cached locally
πŸ”€ Flexible GroupingGroup and sort by day, month, project, key, or model
πŸ“… Custom Date RangesFocus on a specific time period
🎨 Colorful OutputClear, color-coded table for easy reading

β πŸ“¦ Installation

# With uv (recommended)
uv tool install openai-usage-report

# With pipx
pipx install openai-usage-report
⁠From GitHub
# With uv
uv tool install git+https://github.com/obeone/scripts#subdirectory=openai-usage

# With pipx
git clone https://github.com/obeone/scripts
cd scripts
pipx install ./openai-usage
⁠Docker
docker run --rm -e OPENAI_ADMIN_API_KEY="..." obeoneorg/openai-usage-report
⁠Environment Variable

This tool requires an admin-level OpenAI API key:

export OPENAI_ADMIN_API_KEY="your_admin_api_key_here"

β πŸ”§ Usage

⁠List Available Projects
openai-usage --list-projects
⁠View Usage for All Projects
openai-usage
⁠View Usage for Specific Projects and a Date Range
openai-usage --projects proj_xxxxxxxxxxxx --start-date 2024-01-01 --end-date 2024-01-31
⁠Group and Sort Results
openai-usage --group-by project day
⁠Manage Pricing Data

Pricing is automatically fetched from litellm on first run and cached locally (~/.cache/openai-usage/pricing.json). To update manually:

openai-usage --update-pricing

To check cache status:

openai-usage --pricing-info

A warning is displayed if the cache is older than 30 days.


⁠🐳 Docker Usage

CommandDescription
docker run --rm -e OPENAI_ADMIN_API_KEY="..." obeoneorg/openai-usage-reportView all projects usage
docker run --rm -e OPENAI_ADMIN_API_KEY="..." obeoneorg/openai-usage-report -lList projects
docker run --rm -e OPENAI_ADMIN_API_KEY="..." obeoneorg/openai-usage-report -p proj_xxxSpecific project

Build locally:

docker build -t openai-usage-report ./openai-usage

β βš™οΈ Options

ArgumentShortDescriptionDefault
--help-hShow the help message and exit
--list-projects-lList available projects and exit
--projects [ID ...]-pOne or more project IDs to analyzeAll projects
--start-date YYYY-MM-DD-sdStart date for the usage reportStart of current month
--end-date YYYY-MM-DD-edEnd date for the usage reportEnd of current month
--group-by [CRITERIA ...]-gbCriteria to group and sort results (order matters)day
--update-pricingFetch latest pricing from litellm and update local cache
--pricing-infoShow pricing cache path, last update date, and model count

Available Grouping Criteria: day, month, project, key, model


β πŸ“„ License

MIT β€” GrΓ©goire Compagnon (@obeone⁠)

Tag summary

Content type

Image

Digest

sha256:ea1f9b32e…

Size

44 MB

Last updated

about 1 month ago

docker pull obeoneorg/openai-usage-report