OpenAI usage export
How to pull token counts and cost from the OpenAI Usage and Costs APIs.
OpenAI reports API usage in the Usage Dashboard and through the organisation Usage and Costs APIs. The APIs give token counts per model, project, user and key at up to one-minute resolution, so use them where you can. The dashboard is the fallback and has an export of its own.
Usage API and Costs API
You need an Admin API key for the organisation, created by an organisation owner in the organisation settings. Usage endpoints exist for each capability; completions covers the Responses and Chat Completions traffic that most AI workloads produce.
- Create an Admin API key and store it in your secrets manager.
- Call
GET https://api.openai.com/v1/organization/usage/completionswithstart_timeandend_timeas Unix seconds,bucket_width=1d, andgroup_by[]=model. Addproject_id,user_idorapi_key_idto the grouping if you want attribution. - Set
limitto the number of buckets you want, up to 31 at daily width, and page withnext_page. - Repeat for the other usage endpoints you use, then call
GET https://api.openai.com/v1/organization/costsfor spend.
curl "https://api.openai.com/v1/organization/usage/completions?\
start_time=1790812800&end_time=1793491200&bucket_width=1d&group_by[]=model&limit=31" \
-H "Authorization: Bearer $OPENAI_ADMIN_KEY" \
-H "Content-Type: application/json"Each bucket's results carry input_tokens, input_cached_tokens, input_uncached_tokens, output_tokens, audio and image token counts, num_model_requests, and the model, project_id, user_id, api_key_id, batch and service_tier you grouped by. The other usage endpoints are embeddings, images, audio_speeches, audio_transcriptions, moderations, vector_stores, code_interpreter_sessions, file_search_calls and web_search_calls, under the same /v1/organization/usage/ path. The Costs API returns amount.value in US dollars per line_item, daily only, up to 180 buckets per call.
Usage Dashboard export
You must be an organisation owner, or hold the Usage Dashboard permission, to open the dashboard. All data is shown in UTC.
- Open the Usage Dashboard and select the organisation. Sub-organisations are reported separately, so repeat for each.
- Use the dashboard's own project selector to choose projects, or clear it to see the whole organisation.
- Choose the reporting period. There is no limit on the export date range, though long periods may arrive as several files.
- Export the usage data. Use the cost data for billed amounts, and treat any negative activity rows as adjustments to compare by unit and date rather than as credits.
Under API capabilities, Responses and Chat Completions lets you filter by user and drill down to one-minute intervals. If Scale Tier is enabled, its subscription cost sits at organisation level under Spend categories rather than against a project.
Check the export worked
You should have:
- One bucket per day per model for the full date range from the completions endpoint, with
input_tokens,input_cached_tokensandoutput_tokenspopulated. - The same for any other usage endpoints your workloads use, such as embeddings or images.
- A daily costs file for the same range, one per organisation if you run sub-organisations.
Next steps
Once you have the export, send it to Greenpixie for enrichment with energy, carbon and water metrics, or enrich it yourself using the API.
Enriching your usage data using the API →
Pull the rate card and enrich the data yourself, in your own environment.
Connect your data for Greenpixie to enrich it →
Grant Greenpixie access to your bucket or container for managed enrichment.