How to use the OpenAI Costs API (and when a dashboard still helps)

OpenAI’s Costs API lets organization admins pull dollar spend for a date range — including grouping by project, user, line item, and API key. OpenAI’s usage cookbook and Usage Dashboard export help cover the same job from the UI. Enterprise invoice detail changes in 2026 also push teams toward exports rather than relying on invoice line dumps alone.

View Spend sits one layer up: connect read-only usage keys for OpenAI, Anthropic, and xAI so finance and eng share one spend view. More insight. Less waste.

What the Costs API is for

  • Reconcile monthly spend to invoices
  • Break cost down by project or API key
  • Feed BI tools or internal FinOps scripts

It is not a substitute for request tracing or prompt debugging. For that, use observability tools.

Minimal DIY pattern

  1. Create an organization admin key with the least privilege you need for usage/cost reads.
  2. Call GET /v1/organization/costs with start_time (Unix seconds) and optional end_time, group_by, and filters.
  3. Store results by day; re-pull recent days because late adjustments happen.
  4. Map project_id / api_key_id to internal teams (see track OpenAI costs per team).

Always verify field names and auth against the current OpenAI docs — they evolve.

Usage Dashboard vs Costs API

PathBest when
Usage Dashboard + CSV exportOne-off month reconciliation, finance prefers files
Costs APIAutomation, daily syncs, custom grouping
View SpendMulti-provider + team attribution + budgets without owning the pipeline

Gaps a script usually hits

  • Anthropic and xAI are separate APIs and schemas
  • Team names are not native — you must map keys/projects
  • Alerts and budgets are your problem
  • Secret handling and retries become production work

How View Spend uses the same idea

View Spend reads provider usage/cost paths with read-only keys, attributes spend to teams, and surfaces budgets/alerts. It does not put a proxy in your request path and does not need prompts. Related: OpenAI usage dashboard (planned sibling), LLM cost tracking, prevent OpenAI bill shock.

FAQ

What is the OpenAI Costs API?

An organization admin endpoint that returns cost details for a time range, with optional grouping by project, user, line item, API key, and more. See OpenAI’s Costs API reference.

Do I need an admin key?

Yes — organization cost endpoints require appropriately privileged admin credentials. Prefer scoped, read-oriented keys and rotate them.

Can the Costs API replace a product like View Spend?

It is excellent for DIY exports and scripts. A product helps when you also need Anthropic and xAI, team attribution, budgets, and alerts without maintaining the glue.

Does View Spend proxy my OpenAI traffic?

No. View Spend uses read-only usage keys and billing/usage APIs — not a request-path proxy.

CTA

View Spend helps teams track and cut spend on OpenAI, Anthropic, and xAI with read-only usage keys. More insight. Less waste. Join early access or see pricing.