Skip to content
Guide

How to track LLM costs by service, model and customer

By the Alye team · Updated

Short answer
Record each model call where it happens, with its tokens, model, region and the service and customer it served, then price it from the provider's price list. That turns one invoice total into spend per service, model and customer that you can budget and alert on.

Why the invoice isn't enough

OpenAI, Anthropic, Google and the cloud marketplaces bill per API key or project. They can't tell which of your services, features or customers made each call. When the bill goes up, the question “what changed?” has no answer unless you recorded it at the call site.

How the cost of one call is calculated

cost = uncached input tokens × input price
     + cached input tokens   × cached input price
     + cache write tokens    × cache write price
     + output tokens         × output price   (reasoning tokens count as output)

The price depends on where the call ran, not just the model name:

Where the call ranWhat changes
Provider API (global)The provider's list price
Azure OpenAIGlobal, data zone and regional deployments are priced differently
Google Vertex AIRegional endpoints can cost more than global
Amazon BedrockPrices vary by region, and cross-region inference profiles have their own
Your fine-tunes or negotiated ratesYour own price, not the list price

Alye picks the most specific price it knows for each call and records which one it used, so estimates are labelled as estimates.

Split spend by service, model and customer

Name each service when you start the SDK. To see spend per customer, tag requests with your own customer ID (an account or tenant ID, not a name or email):

# Python
with alye.context(customer_id="northwind"):
    answer = run_agent(ticket)

// Node.js
await alye.context({ customerId: "northwind" }, () => runAgent(ticket));

Every call is then priced and counted under its service, model and customer, and each request becomes a trace you can open to see which steps cost the most.

Set budgets and alerts

  • A spend alert when a service, model or customer passes a limit in an hour or a day.
  • A forecast alert when the month is on track to exceed your budget.
  • A monthly budget per customer, so you know before a customer's usage outgrows their plan.
  • Delivery by email, Slack or Microsoft Teams, checked every minute.

Where the savings usually are

  • One service or prompt is often most of the bill. Sort spend by service, then open its most expensive traces.
  • Retries cost twice. Rising rate-limit errors usually mean paying for calls that failed.
  • A smaller model is often enough for classification, routing and extraction steps.
  • Cached input tokens are cheaper. Keep long, stable instructions at the start of the prompt so they can be cached.
  • Watch tokens per call after each prompt change; growth there is easy to miss.

Start tracking

Add the SDK to one service and your first priced calls show up within minutes. See the docs and pricing, or read what LLM observability covers beyond cost.

Questions

Why doesn't my OpenAI or Anthropic invoice show cost per feature?

Provider invoices total usage per API key or project. They don't know which of your services, features or customers made each call, so you need to record that at the call site, which is what an LLM cost tracking tool does.

How is the cost of an LLM call calculated?

Uncached input tokens times the input price, plus cached input tokens times the cache price, plus output tokens (including reasoning tokens) times the output price. Prices differ by model, region and provider marketplace, so use the price for where the call ran.

Can I set a monthly budget per customer for LLM usage?

Yes. In Alye, tag requests with your customer ID, then set a monthly budget on the Customers page and an alert to warn you before a customer goes over it.

Try it on one service. Free for 500,000 calls a month, set up in about five minutes.