A set of scripts for querying users in an OpenAI organization, downloading user usage to csv, and plotting cost over time.
External resources: Pandas, Matplotlib
Tested on Mac OS 12.6.7 with Python 3.10.9
To use, create .env file at root with the following information:
openai_org_id
- can find here - requiredopenai_api_key
- API key of a user with owner privileges in the org - requireddata_dir
- path to your data directory - optionalfinetune_models
- list of text strings that are names of any finetune models your organization uses - optionaldate_range
- list of text strings for dates to get usage from in the format ofYYYY-MM-DD
- optional
After your .env file is setup:
- Run
python openai_usage.py
to get the users in your org and then download their data for specified date_range OR yesterday - Run
python openai_analysis.py
to clean up the usage data, attach cost values, and plot per user costs
Credit to this thread for kickstarting the process of exposing the less well documented OpenAI API usage endpoints.