Getting your usage data

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.

  1. Create an Admin API key and store it in your secrets manager.
  2. Call GET https://api.openai.com/v1/organization/usage/completions with start_time and end_time as Unix seconds, bucket_width=1d, and group_by[]=model. Add project_id, user_id or api_key_id to the grouping if you want attribution.
  3. Set limit to the number of buckets you want, up to 31 at daily width, and page with next_page.
  4. Repeat for the other usage endpoints you use, then call GET https://api.openai.com/v1/organization/costs for 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.

  1. Open the Usage Dashboard and select the organisation. Sub-organisations are reported separately, so repeat for each.
  2. Use the dashboard's own project selector to choose projects, or clear it to see the whole organisation.
  3. Choose the reporting period. There is no limit on the export date range, though long periods may arrive as several files.
  4. 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_tokens and output_tokens populated.
  • 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.

References

On this page