Skip to content
AISpendbook

Guide · 10 min read

Track AI spend across OpenAI, Anthropic and Gemini

By AI Spendbook · Published · Updated

Short answer

Pull billed cost from each provider: the OpenAI Costs API, Anthropic's usage and cost reports, and the Google Cloud Billing export to BigQuery for Gemini. All need read-only admin credentials. Then attach request data from your app, with customer and feature ids, so each billed dollar can be traced to who used it.

Key takeaways

  • OpenAI and Anthropic cost and usage reports need an admin key, not a normal API key.
  • Gemini API cost is read from the Cloud Billing export to BigQuery; the last day or two is always incomplete.
  • Provider billing sets the total; request data with customer and feature ids splits it. Never add the two together.
  • One OpenAI project or Anthropic workspace per product and environment makes every provider report more useful.
Three colored trails of tokens converge on an open ledger beside a stone bridge.

Most teams start by checking each provider's dashboard once a month. That works until there are three providers, a dozen models and a question from finance about which customers caused last month's increase. Tracking AI spend properly takes two layers of data: what the provider bills, and what your app knows about each request.

Where does each AI provider report usage and cost?

From each provider's documentation, checked 2026-11-29.
ProviderWhere cost comes fromCredentialBreakdowns
OpenAICosts API (daily cost) and Usage API (tokens)Admin keyProject, line item, API key, model
AnthropicUsage report and cost report (Admin API)Admin API keyModel, workspace, API key, service tier
Google Gemini and Vertex AICloud Billing export to BigQueryRead-only service accountProject, service, SKU, labels

OpenAI

OpenAI's organization Costs API returns daily cost buckets that can be grouped by project, line item and API key. The Usage API returns token counts per model. Both need an admin key, not a normal API key. Using one project per product or environment makes the grouping more useful.

Anthropic

Anthropic's usage and cost reports give historical token usage and cost for the organization, with breakdowns by model, workspace and API key. They need an Admin API key; workspace API keys do not work. Separate workspaces per product play the same role as OpenAI projects. Anthropic now also offers a newer Usage and Cost Analytics API with more grouping options and recommends it for new integrations.

Google Gemini

Gemini API charges appear in Google Cloud Billing. The reliable way to read them programmatically is the Cloud Billing export to BigQuery, then a read-only service account that can query the export table. Exported rows usually arrive within a day, so the last day or two is always incomplete.

Keep admin keys and service accounts read-only and stored in a secret manager. Spend tracking never needs permission to send requests or change settings.

How do I get Anthropic API usage grouped by API key?

Call the usage report endpoint with an Admin API key, a date range, a daily bucket and group_by[]=api_key_id. One request returns a bucket per day and key with uncached input, cached input, cache creation and output tokens:

  1. GET https://api.anthropic.com/v1/organizations/usage_report/messages?starting_at=2026-11-01T00:00:00Z&ending_at=2026-11-08T00:00:00Z&bucket_width=1d&group_by[]=api_key_id&group_by[]=model
  2. Headers: x-api-key: $ANTHROPIC_ADMIN_KEY and anthropic-version set to the version in Anthropic's docs.
  3. If the response has has_more: true, repeat the request with page set to the returned next_page until it is false. Daily buckets return 7 per page by default and 31 at most.
  4. Turn key ids into names with the List API Keys endpoint. Console playground usage has no key, so its api_key_id is null.

This gives tokens, not dollars. The legacy cost report groups by workspace and description, not by key; for cost per key, Anthropic's docs point to the newer analytics cost endpoint grouped by api_key_id. Price token counts yourself only as an estimate, and keep it apart from the billed figure, as billed vs estimated AI spend explains.

Which request fields do you need for cost by customer?

Provider billing tells you how much and on which model. It cannot tell you which customer, feature or user made the request. Only your application knows that. For each AI call, record:

  • provider, model, input tokens, output tokens and cached tokens (every provider returns these in the response),
  • a customer or account id, the product feature, and optionally an end user id,
  • a timestamp, latency and whether the call succeeded.

You don't need prompt or completion text for cost tracking, and leaving it out keeps the data far less sensitive. Many teams already log these fields to their own database; others send them with an SDK, a gateway or OpenTelemetry spans, compared in gateway, SDK or OpenTelemetry for LLM cost tracking.

How do you combine billing and request data without double counting?

Three rows of colored counters flow into adjacent columns of a ledger.

The common mistake is to add billed cost and estimated cost together, or to treat token math as the bill. A sound setup uses billing as the total for each day and provider, and uses request data to split that total by customer and feature. Whatever request data doesn't cover is shown as unattributed spend, not hidden.

Worked example: one day of Anthropic spend

  1. Take the bill as the total. Anthropic's cost report shows $1,000.00 for the day. That is the number that will reach the invoice.
  2. Price the request data. Your request logs, priced at list rates, come to $900.00: customer A $450.00, customer B $270.00, and $180.00 with no customer id.
  3. Turn the estimate into shares. A is $450 / $900 = 50%, B is $270 / $900 = 30%, untagged is $180 / $900 = 20%.
  4. Apply the shares to the bill. A gets 50% x $1,000 = $500.00, B gets 30% x $1,000 = $300.00, and $200.00 stays unattributed.

The parts add back to exactly $1,000.00, the billed figure. The $100.00 gap between bill and estimate (cache writes, a rounding difference, a call the logs missed) is spread across customers in proportion instead of being added on top. Had you added the $900 estimate to the $1,000 bill, the day would show $1,900. If the untagged share stays above a few percent, find the call sites without a customer id before trusting the per-customer figures; AI cost per customer covers the allocation rules in more depth.

Getting the numbers into a spreadsheet

Finance teams often want the reconciled daily figures in Google Sheets or Excel. Either a scheduled script calls each provider's cost API with an admin key, or a tool publishes the table as a CSV URL that IMPORTDATA reads; AI Spendbook does the latter with spreadsheet feeds. Getting AI spend into Google Sheets, Looker or a warehouse compares the routes and their trade-offs.

What are the common mistakes when tracking AI spend?

  • Reading the current month's last two days as final. Provider reports and the BigQuery export keep moving for a day or more. Label recent days as estimates.
  • Using a full-access API key for reporting. Cost reports need an admin key; keep it in a secret manager, use it only for reading, and never in application code.
  • One project or workspace for everything. Every provider breakdown then says "default". Split by product and environment before the data piles up.
  • Logging prompt text to get attribution. Cost needs token counts and ids only.
  • Forgetting providers billed through a cloud. Claude on Bedrock or Vertex AI appears on the AWS or Google bill, not in Anthropic's reports; see tracking Bedrock and Azure OpenAI costs.

When is a provider dashboard enough?

With one provider, a small bill and no question about which customer or feature drove it, the provider's own usage page and a monthly look at the invoice are enough. Build the two-layer setup when there are several providers, when AI is part of the cost of serving customers, or when finance has to close the month on these numbers.

A one-week setup checklist

  1. Create read-only admin keys for OpenAI and Anthropic, and enable the Cloud Billing export to BigQuery for Gemini.
  2. Split traffic into OpenAI projects and Anthropic workspaces by product and environment.
  3. Add customer and feature ids to every AI call your app makes, or map them from tables you already have.
  4. Load both layers into one place, keeping billed and estimated amounts in separate columns.
  5. Review unattributed spend weekly until it is small and stable.

AI Spendbook does steps 1, 4 and 5 for you: it connects to the OpenAI, Anthropic and Google Gemini billing sources, reads attribution from its Python and Node.js SDKs, gateways, OpenTelemetry, the ingestion API, CSV imports or a read-only database connection, and reconciles the two. Each connector is built from the provider's public documentation and tested with recorded responses. The integrations list shows what each one reads.

Frequently asked questions

Can a normal OpenAI API key read the OpenAI Costs API?

No. The organization Costs and Usage APIs need an admin key created by an organization owner. Keep it read-only in purpose, store it in a secret manager, and never use it to send model requests.

How fresh is Anthropic usage and cost data?

Anthropic's documentation says usage and cost data typically appears within five minutes of a request completing, though delays can be longer. Its cost report is daily, so the current day keeps changing until it ends.

Why is yesterday's Gemini cost missing from the BigQuery billing export?

Cloud Billing export rows usually arrive within a day, and late adjustments can follow. Treat the last day or two as incomplete, label those days as estimates, and replace them when the export catches up.

Start with your own numbers.

Every plan is free during launch. No credit card.