Home › Blog › How to Calculate LLM Cost Per Request

How to Calculate LLM Cost Per Request

By Victor, founder of apicuts

Your total API bill goes up when your product grows, which is good. Cost per request tells you whether each request is getting cheaper or more expensive, which is what you actually control.

Quick answer

Cost per request = (input tokens × input price + output tokens × output price) ÷ 1,000,000, with cached input tokens priced at the lower cached rate. Track it per route, every day.

The formula

cost per request = ( uncached input tokens × input price + cached input tokens × cached input price + output tokens × output price ) ÷ 1,000,000

A worked example

Example prices: $2.50 per million input tokens, $0.25 per million cached input tokens, $10 per million output tokens. One request sends 3,000 input tokens, 2,000 of them read from the cache, and gets 500 tokens back.

PartTokensPrice per 1MCost
Uncached input1,000$2.50$0.0025
Cached input2,000$0.25$0.0005
Output500$10.00$0.0050
Total per request$0.0080

At 50,000 requests a day, that's $400 a day, or about $12,000 a month. Without the cache, the same request costs $0.0125, more than 50% more.

Why it beats watching the total bill

Pick the right unit of work

A request isn't always the right unit. A chat app may care about cost per conversation, a document tool about cost per document, and a B2B product about cost per active user. For agents, measure cost per completed task, including retries and every tool call it took to finish.

How to track it

  1. Log the usage data from every response with the route name, model and release version.
  2. Compute the daily average cost per request for each route.
  3. Chart it, and alert when a route jumps after a deploy. That's cost regression protection.

Want us to find your 20%?

Book a free 15-minute API cost teardown. Bring last month's provider usage and we'll show you your biggest waste and the first fix we'd ship.

Get My Free 15-Minute API Cost Teardown

Frequently asked questions

What's a good cost per request?

It depends on what the request earns you. Compare it with revenue per request or per user rather than with other companies.

Should I count failed requests?

Yes. You pay for errors and retries too, so include them, or measure cost per completed task.

How do I count cached tokens?

OpenAI and Anthropic both report cached input tokens separately in the usage data. Price them at the cached rate.

Related