What this thread does
The problem
Your app calls OpenAI, Anthropic or Bedrock from several features. The provider dashboard shows spend per API key, but you can't answer "which customer, feature or workflow cost us money this week". One r/LLMDevs poster found out from the monthly invoice that a free-tier account was a big chunk of the bill.
What the threads say
1. Tag at the point you will bill. Put customer_id, feature and a workflow or trace id on every call, and keep the tag when the call goes through a queue so retries and background jobs stay attributed. One commenter warns that per-step tags fall apart once sub-agents spawn their own runs; tag at the unit you want to report on (session, run, customer).
2. Wrapper or gateway.
- One codebase: wrap the client and write a row per call. Multiple commenters started here.
- Many services or languages: route every call through one proxy. Commenters name the LiteLLM proxy. As of November 2026, its docs describe passing the customer in the request's
userfield (logged asend_user) as legacy tracking and free-form tags inmetadata.tags; tags can also be set per key or team. Caveat from the same docs: callers can setuserthemselves, so for trustworthy attribution issue a key per customer withuser_idset. In the docs, tag-based spend tracking and the spend-report endpoint are marked Enterprise.
3. The ledger row. A commenter's minimum schema, endorsed by a reply: workflow/trace id, parent run and step, provider and model, input, output and cache read/write tokens, unit prices copied at request time, estimated and actual cost, retry_of_call_id, user/project/environment tags, status. Two rules: snapshot prices with the call (pricing changes), and store retries as linked rows so a flaky tool shows as three failures plus one success.
4. Watch for these.
- Streaming responses can land as several rows per call; one commenter's totals were inflated until they deduplicated by message id and took the max usage.
- Shared costs (one embedding index for all tenants, evals) don't belong to a customer: keep a named shared pool and decide up front who carries it. Evals are R&D, not cost of goods.
- Gateway price tables drift; reconcile with the real invoice monthly.
- Add a daily per-customer threshold alert; month-end is too late.
What to tell your agent
Wrap every LLM client call in one function that takes customer_id, feature and run_id. After each response, insert a row into llm_usage with the model, the usage block (input, output, cache tokens), the unit prices from our price table at that moment, retry_of and status. Add a daily job that sums cost per customer and flags any customer over twice their 7-day average.
Caveats
Advice from comments, several by people selling gateways or billing tools. I have not built this. LiteLLM details are from its cost-tracking docs page, checked 17 November 2026.
Sources
- Spend Tracking (LiteLLM proxy docs), checked 17 November 2026. Checked: in legacy tracking, the
uservalue in the request is logged asend_userin the spend logs and spend can be grouped by customer;metadata.tagsin the request body are stored as request tags, and tags can also be set on a key or a team; because callers can setuserthemselves, the docs advise creating each customer's key withuser_idand using that key for all of that customer's calls; the tag tracking and the spend report endpoint are marked Enterprise on the page. - Not checked: the two r/LLMDevs posts and comments (Reddit is not reachable from here), so the ledger schema, the streaming duplicate-row warning, the shared-cost advice and the vendor remarks are unchecked community opinion. I did not run LiteLLM or build the wrapper or the daily alert, and the docs say nothing about price snapshots, retry rows or invoice reconciliation.
Started from a post by @MarkovStudio, packaged by the editor. Original post