How to Track OpenAI API Costs by Customer (And Why Your Current Setup Won't Tell You)
We found out the hard way. One customer — account 4,781 in our system — was responsible for 41% of our entire OpenAI bill. We had been treating AI spend as a single company-wide line item for eight months. We were effectively subsidising them, and we had absolutely no idea.
The OpenAI dashboard tells you total spend, spend by model, and daily usage trends. It does not tell you which of your customers is running up the bill. That visibility gap is the default state for almost every team building with AI. You know what you're paying OpenAI. You have no idea who in your product is causing it.
The first thing most teams try: metadata tagging
The OpenAI API accepts a user field in every request. Pass your customer ID there and, in theory, you can filter usage by customer. It's a good idea. In practice, it almost never works cleanly.
The problem is consistency. Metadata tagging requires every engineer, on every AI feature, in every part of the codebase, to pass the right ID every time. Legacy features miss it. Third-party integrations don't support it. Someone deploys a new chat flow and forgets. Six months later, 40% of your calls are untagged. You have partial visibility — which is almost worse than none. You start making decisions on incomplete data and don't realise it.
The second approach: build a logging pipeline
The more robust solution is to intercept every API call, log it to your own database, join it to your customer table, and build a reporting layer on top. This works. It takes a data engineer two to three months to build correctly, another month to make reliable, and ongoing maintenance every time you add a new AI feature or switch providers.
We went down this road. By the time we had the first version running, our bill had grown another 30%. We were spending engineering time building cost visibility infrastructure instead of the product customers were paying for. And we still had gaps: historical data before we added logging, features served through third-party wrappers, and Anthropic calls that needed a separate pipeline entirely.
What actually works without three months of infrastructure
The approach that skips the data pipeline is direct API sync combined with a customer tagging layer. Instead of logging every call yourself, you connect your AI provider accounts directly to an attribution service. That service pulls your usage from OpenAI and Anthropic, maps it to your customer IDs using the metadata conventions you already have, and surfaces the breakdown — without you building any storage or query infrastructure.
The practical result: cost by customer, by feature, and by pricing tier, updating continuously. Not as a one-off analysis but as an ongoing view. Once we had that, the decisions followed quickly. We found three customers each generating over $1,800/month in AI costs on flat-rate plans. We found one feature used by 4% of customers driving 31% of total cost. We raised prices on the first group and gated the second behind a higher plan. The bill didn't shrink — but our margin on it improved substantially, because we were finally charging in proportion to what we were actually spending.
That is exactly the problem PerUnit is built to solve — cost attribution by customer, feature, and pricing tier, connected directly to your OpenAI, Anthropic, and Google accounts. No pipelines, no data engineering. If you want to understand your margins before going deeper, our free AI margin calculator is a useful first step.