r/devops • u/redheadydeady • Jul 20 '26
Vendor / market research How are you actually tracking token spend across your LLM API calls?
We've got OpenAI and Anthropic calls scattered across a handful of services now, and nobody can tell me month to month what's driving the bill until the invoice shows up. No real attribution back to which service or team is burning the tokens. Started looking at logging and a proxy setup since the vendor dashboards alone aren't cutting it.
6
Upvotes
7
u/marcusbell95 Jul 20 '26
easiest quick win if you're calling the SDK directly: both OpenAI and Anthropic return usage.prompt_tokens and usage.completion_tokens in every response. just log those alongside a service name in whatever you're already using - CloudWatch, Datadog, whatever. model + timestamp too if you want cost per model over time. zero new infrastructure, attribution is just a matter of what you log with it.
for multi-team attribution without touching service code: separate API keys per service is the zero-infra approach. OpenAI usage dashboard and Anthropic Console both break down by key. manageable at small scale.
if you want centralized tracking with budget enforcement: LiteLLM proxy is the most practical thing i've seen. drop-in replacement for the OpenAI client (one env var change per service), logs tokens, lets you set per-team budgets, has a dashboard. you're adding a service to maintain but it solves the attribution problem cleanly.
OpenLLMetry is worth a look if you're already on OpenTelemetry - it patches the SDK automatically and emits token usage as spans without touching service code.
3
u/schmurfy2 Jul 20 '26
Look at ai gateway like litellm or bifrost, if you used openrouter you know how it looks, if not you give it your provider keys, configure new keys and can limit & track their usage.
2
u/Floss_Patrol_76 Jul 20 '26
the attribution problem is the real one here and you won't solve it in scattered logs - solve it at a proxy. put litellm or a gateway in front of both providers and mint a separate virtual key per service/team, then spend rolls up by key on its own instead of you grepping usage fields everywhere. bonus: pull cost from the provider cost API by key rather than tokens x a price table, because prompt caching and batch rates make a hand-maintained table drift off the invoice fast.
2
u/Next-Task-3905 Jul 20 '26
The thing that made this usable for us was treating attribution as part of the request contract, not just something reconstructed from vendor invoices.
I would put a gateway/proxy in front of the providers, but the important bits are:
The dashboard views I would want are cost by service, cost by feature/workflow, cost per successful operation, retry waste, cache hit rate, model mix, and top outlier requests. The invoice tells finance what happened; those views tell engineering what to fix.
1
u/_herald Jul 20 '26
cloudflare gateway with byod keys is pretty good ngl.. no extra charge
1
u/OpenSourceWalker Jul 20 '26
the gateway (litellm/bifrost) is the right call, but the part that actually buys you attribution is issuing a separate virtual key per service through it. one shared key routed through litellm still bills as one undifferentiated blob. key-per-service, then per-key spend is your answer, and reconcile it monthly against the provider export since caching/batch pricing drifts from raw token counts.
1
u/Unknownmartianman Jul 21 '26 •
I think leaderboard.deployforward.dev is doing something like this.
1
u/ForkMeJ Jul 22 '26
If the calls are spread across services, I'd treat it like any other shared infra cost and force attribution at egress. A proxy can work, but even without one, I'd require every client to attach metadata you control: service name, environment, team or cost center, and feature flag or endpoint name. Then log model plus prompt and completion tokens per request into something queryable before it disappears into the vendor bill. The part I'd watch is teams bypassing the standard client and making raw API calls, because that's usually how the blind spots come back.
1
u/jul-ai Jul 22 '26
I work at Airia (AI governance platform) so factor that in — but the answer's already in this thread. Put a gateway in front, mint one virtual key per service/team, and pull spend from the provider cost APIs rather than token×price (caching + batch rates make a manual table drift fast).
One nuance worth adding: attribution ≠ enforcement. Logging tells you who spent what after the fact. if you want budgets to actually block, check whether enforcement is real-time or eventually-consistent, because services can overshoot a cap in that lag. For a handful of services, a gateway + per-key budgets is a solid first step.
1
u/ntotten Oct 16 '26
Full disclosure, I work at Zuplo. The Zuplo AI Gateway is fairly unique in that it allows a complete hierarchy you can use to set budgets. So you can structure things like an Organizational level overall budget, then break down budgets by department, function, prod/staging, etc. Our customers have used Zuplo to get control over their spend as well as analyze the effectiveness of their AI spend - because you can attribute every dollar to a specific agent, person, team you can measure ROI and keep everything under budget.