Proxy-based vs billing-API cost tracking
Last verified
The choice is about what you can tolerate failing. A proxy sits in your request path and sees everything. A billing reader sits outside it and sees only aggregates. Neither is safer in general — they fail in different directions.
How each works
Proxy. You point your SDK at the vendor instead of the provider. Every request passes through them; they count tokens and multiply by a price table.
client = OpenAI(base_url="https://gateway.example.com/v1", api_key=KEY)
Billing API. A tool authenticates to the provider's billing endpoint with an admin credential and reads what you were charged. Your application is untouched and unaware.
GET /v1/organization/costs → daily buckets of dollars
Side by side
| Proxy | Billing API | |
|---|---|---|
| Code change | Base URL, or a full SDK | None |
| In your request path | Yes | No |
| Latency added | Yes, an extra hop | None |
| Can take your app down | Yes | No |
| Sees prompts and responses | Yes | No |
| Granularity | Per request | Daily |
| Freshness | Seconds | Daily |
| Per-customer attribution | Yes, with tagging | No |
| Per-feature attribution | Yes | Only via key or project structure |
| Sees untracked traffic | No | Yes — everything on the account |
| Cost figures are | Computed from a price table | What you are billed |
| Extra capabilities | Caching, fallbacks, routing | None |
| Credential needed | Their API key | Provider admin key |
Two rows decide most cases: "can take your app down" and "sees untracked traffic".
The failure modes
A proxy fails loudly. If it degrades, your product degrades. That's a real availability decision, not a theoretical one — you're adding a dependency to the hot path in exchange for observability.
A billing reader fails quietly. If it breaks, you stop getting numbers and your application never notices. Much safer, and the reason it's a reasonable default.
A proxy has a coverage hole. It only sees what was routed through it. The prototype key from March, the script a teammate runs locally, the notebook, the cron job someone set up and forgot — none of it appears. That is very often exactly the spend that surprises you, so the tool built to prevent surprises is structurally blind to the most common cause.
A billing reader has a resolution hole. It cannot tell you which endpoint or which customer. If that's your question, no amount of billing data answers it.
Prompt visibility
Worth separating from performance, because it's frequently the deciding factor.
A proxy must see request and response content to do its job. For most applications that's fine — it's the same trust you already extend to the model provider. For applications handling health data, legal documents, or anything under a data-processing agreement, adding a second processor is a compliance question, not a preference.
Billing data contains no content. Dollars, tokens, model names, dates. Nothing else.
This is also why Langfuse's self-hosting option matters: it resolves the objection by keeping the data inside your own estate.
Cost accuracy
Slightly counter-intuitive: the proxy is faster but less accurate.
A proxy computes cost from tokens it observed times a price it has on file. That price table can go stale after a provider change. It can't know about your negotiated discounts, your credits, or prompt-caching hits priced differently. It's a very good estimate.
The billing API returns what the provider will invoice. It is the number, several hours late.
For alerting, the estimate is fine. For reconciliation or reporting a real figure, use billing data.
Which to pick
Proxy, if you need: cost per customer or per feature · prompt-level debugging with cost attached · caching or automatic failover · to catch a runaway within minutes.
Billing API, if you need: no third party in production · prompt confidentiality · zero integration work · coverage of _all_ account spend including things you forgot · the actual billed figure · several providers in one number.
Both, if: you're optimising a production service _and_ want a total that catches everything outside it. This is the setup most teams converge on, and the two tools genuinely don't overlap.
Where TKN sits
TKN is a billing-API reader, so everything in the right-hand column applies — including the limitations. It is daily. It cannot tell you what one request cost. If you need per-feature attribution, use Helicone and we'd tell you the same thing in person.
What TKN adds beyond reading: several providers in one figure, spend rules checked against live daily spend, keys held in the device Keychain rather than on a server, and a kill switch that revokes at the provider — the one thing neither architecture normally does at all.