If you sell a product that calls OpenAI, Anthropic or Gemini, your AI bill arrives as one number for the month. Your revenue doesn't. It comes customer by customer, plan by plan.
That gap matters. A customer on your ₹2,000 plan who uses a feature heavily can cost you more in API spend than they pay you, and the provider's bill will never tell you which customer it was.
This post covers three ways to get cost per customer, what each one gets wrong, and how to check that your numbers are right.
Why the provider dashboard can't answer this
OpenAI and Anthropic both give you usage and cost reports. They are useful, but they group spend by things the provider knows about: your projects, workspaces, API keys and models.
- OpenAI's Costs API groups by
project_id,line_itemandapi_key_id. - Anthropic's Cost API groups by workspace or description. Its Usage API can filter and group by API key, workspace, model and a few other fields. It needs an Admin API key, and it isn't available on individual accounts.
Neither knows who your customers are. That information lives in your app. So to get cost per customer, you either make the provider's structure match your customers, or you record it yourself.
Option 1: One API key (or project) per customer
Create a separate OpenAI project or API key, or an Anthropic workspace, for each customer, and use that key whenever you call the model for them. The provider's cost report then gives you spend per key, which is spend per customer.
Works well when: you have a handful of large customers, or each customer brings their own key anyway.
Where it breaks:
- Key management grows with every customer: creating, storing, rotating and revoking.
- It doesn't tell you which feature drove the cost, only which customer.
- Customers on a free or shared plan usually end up on a shared key, which is exactly where the surprises hide.
- The reports come from the provider's billing data, so you are looking at yesterday, not stopping anything today.
Option 2: Log usage on every request and price it yourself
Every response from OpenAI and Anthropic includes a usage object with token counts. Log it next to the customer ID and the feature name, multiply by the model's price, and sum per customer.
This is what most teams do first, and it's the right instinct. It's also where the numbers quietly drift. The common causes:
- Streaming. With OpenAI's Chat Completions API, a streamed response only includes usage if you ask for it with
stream_options: {"include_usage": true}. Anthropic sends usage in the stream events, which your code has to read. Miss this and streamed calls look free. - Retries. If your client or framework retries a call, each attempt that reaches the model can be billed. Your log often records only the final success.
- Cached and reasoning tokens. Cached input tokens are priced differently from normal input. Reasoning models bill their reasoning tokens as output. A single "input × price + output × price" formula gets both wrong.
- Stale prices. Prices change and new models appear. A price table hard-coded six months ago is probably wrong for at least one model you use today.
- Calls outside the app. Scripts, batch jobs, evals and other teams using the same account show up on the bill but not in your app's log.
None of these are hard to fix one by one. Together they mean your per-customer total and the provider's invoice rarely match, and when they don't, you can't tell which side is wrong.
Option 3: Put a metering layer in front of the provider
The third way is to send calls through a layer that sits between your app and the provider. Your app tags each call with the customer and feature, the layer records tokens and cost, and you get a breakdown without writing the logging yourself.
This is what we built TOLVYN to do. You add your provider key to TOLVYN once, change the base URL, use a TOLVYN key, and add a header such as X-Tolvyn-End-Customer (and optionally feature, team or service). TOLVYN records model, tokens, latency and cost for the calls that go through it, and shows spend per feature and per customer (your top 100 customers by spend). It never stores prompts or responses.
Because it's in the request path, it can also do something logs can't: block a call before the provider is charged, once a hard budget for an organisation, team, service or agent would be exceeded. The check uses an estimate of the call's cost, and hard budgets are on paid plans (Starter and up).
Trade-offs, honestly:
- It's one more service in the request path. Start with one non-critical service and measure the latency yourself.
- Hard budgets today work per organisation, team, service or agent, not per individual end customer yet.
- It supports OpenAI, Anthropic, Google Gemini and DeepSeek. Not Bedrock or Vertex today, and Azure OpenAI only in a limited way.
- Calls that bypass TOLVYN, for example an SDK falling back to the provider directly while TOLVYN is unreachable, aren't recorded.
Whatever you choose: check against the invoice
Cost per customer is only useful if the total adds up to what you actually paid. Once a month:
- Export the invoice or usage CSV from your provider's console.
- Sum your per-customer numbers for the same period and the same provider.
- If they differ by more than a small margin, look for the causes in Option 2: streaming without usage, retries, cached or reasoning tokens, stale prices, or calls from outside the app.
TOLVYN does this step for you: upload the usage export from your provider's console (the CSV with model and cost per line) and it compares it, month by month, against what TOLVYN recorded. (OpenAI on every plan; Anthropic and Google on Growth and above.)
The short version
- The provider's dashboard groups by key, project and model, never by your customers.
- One key per customer works for a few customers and stops working as you grow.
- Logging usage yourself works if you handle streaming, retries, cached and reasoning tokens, and price changes.
- A metering layer does the recording for you and can stop spend before it happens, at the cost of being in the request path.
- In every case, reconcile against the invoice every month.
If you want to see your own cost per customer, TOLVYN is free up to 10,000 requests a month, no card needed: tolvyn.io.
Sources: OpenAI Costs API reference · OpenAI Usage and Cost API cookbook · Anthropic Usage and Cost API