OpenAI Cost Attribution: 3 Approaches We Tried (and What the Trade-offs Actually Are)
It was mid-March and our OpenAI bill had just hit $11,400 for the month. For the first time, that number scared us — not because it was unmanageable, but because we realised we had no idea where it was coming from. We knew the total. We knew which models. We did not know which customers, which features, or whether this number would double in two months.
What followed was three months of trying different approaches to cost attribution. Each worked, with real trade-offs. Here's what we learned.
Approach 1: Metadata tagging in API calls
The simplest approach: pass a customer identifier in every API request. OpenAI accepts a user field. Anthropic supports metadata. Tag every call with your customer ID and you can, in theory, filter usage in the provider dashboard.
In practice, this is a discipline problem as much as an engineering one. Consistent tagging requires every developer on every feature to pass the right ID every time. Legacy features don't have it. New features get added without it. A third-party integration you use doesn't support it. Three months in, 60% coverage is a good day. The untagged 40% is not random — it clusters around your oldest and most-used features. You end up with partial visibility and decisions based on data you're not sure you can trust.
Verdict: worth doing as a foundation, but insufficient on its own.
Approach 2: Build a logging and attribution pipeline
The robust option: intercept every API call, log it with customer and feature context, join it to your billing data, and build reporting on top. This gives you full control, historical data, and exactly the breakdown you want.
The cost: four to six weeks of engineering time to build, three months before it was reliable enough to trust. Separate pipelines needed for OpenAI and Anthropic. Every new AI feature required updates to the logging layer. Ongoing maintenance indefinitely. We also discovered mid-build that our bill kept growing while we were building the thing that was supposed to explain it.
Verdict: correct if you have a dedicated data engineering team and a bill large enough to justify the investment. For most product teams, the opportunity cost is too high.
Approach 3: Direct API sync with an attribution layer
The third approach skips the pipeline entirely. Instead of logging calls yourself, you connect your provider accounts to an attribution service that pulls usage directly from OpenAI and Anthropic. It maps usage to your customers via the metadata you already tag, or via a lightweight SDK that adds customer context at the call level. The result — cost by customer, by feature, by pricing tier — without building or owning any infrastructure.
Historical data is available from the day you connect. New providers or features appear automatically. There's no query layer to maintain, no pipeline to debug, and no data engineering team required.
This is what PerUnit does. We built it after going through approaches 1 and 2 ourselves. Direct sync to your OpenAI, Anthropic, and Google accounts, with customer attribution and Stripe integration to see revenue next to cost. No pipelines, no infrastructure work. If you want to run the numbers first, our free AI cost calculator estimates what attribution visibility would be worth at your current usage volume.