← All posts

Cutting Your LLM API Bill: 5 Levers, Measured

2026-12-01 · GDE #13 / LLM API cost reduction (5 levers, measured — prompt caching, batching, routing, token discipline, self-hosting)

Token prices keep falling and your bill keeps rising. That is not a paradox — it is arithmetic. Agentic workflows burn 5 to 30 times more tokens per task than a chatbot query, so consumption outruns the price drop. Enterprise generative AI spend hit $37 billion in 2025, up 3.2x in a year, and a 2026 survey of 101 enterprise technology leaders found 43% already spending more on AI than they budgeted. The fix is not a cheaper model. It is five levers, each with a measured payoff, that stack. This is GDE post #13, and it answers one question: what does each lever actually save on a real workload?

The numbers below are measured arithmetic, not quoted: every figure comes from the companion notebook, computed from published provider list prices checked Nov 30, 2026. The workload is a support agent doing 1,000,000 requests a month — 2,400 input tokens per request (1,800 stable system prompt and docs, 600 fresh) and 500 output tokens, on Claude Sonnet 5.5. The headline: the baseline bill is $9,800 a month, and the four cheap levers cut it to $3,088 — a 68.5% cut — before self-hosting is even on the table.

The ELI5 version

An LLM bill is two numbers multiplied: tokens times price per token. Input tokens cost less than output tokens — on Sonnet 5.5, $2 versus $10 per million — and every lever attacks one side of that multiplication. Caching makes repeated input tokens nearly free. Batching halves the price of work that can wait. Routing sends easy requests to cheap models. Token discipline sends fewer tokens. Self-hosting replaces the price per token with a GPU you own. None of these is exotic. The expensive habit is the default: every request to the frontier model, uncached, synchronously, with the full conversation history attached.

Lever 1: prompt caching — the cheapest 33%

Every time you resend a system prompt, tool definitions, or a document, you pay full input price for the model to read it again. Caching lets the provider skip the re-read — and the discount is the largest of any lever on the tokens it touches.

Cache read price versus full input price by provider: Sonnet 5.5 $0.10 vs $2.00, GPT-5 $0.125 vs $1.25, Gemini 2.5 Pro $0.125 vs $1.25, Gemini 2.5 Flash $0.03 vs $0.30.

On Sonnet 5.5 a cache read costs $0.10 per million tokens against a $2.00 input price — 5% of the price, a 95% discount. OpenAI caches automatically at roughly 50% off, and its cached GPT-5 tokens list at $0.125 against $1.25 input. Gemini 2.5 Pro lists cached input at $0.125 against $1.25, and explicit caching through Vertex AI drops cached tokens to 10% of the standard input rate. The rule that makes it work: put stable content first. System prompts, tool definitions, and reference documents go at the top of the context window, before anything that changes request to request.

On the workload, 75% of input is a stable prefix. Caching takes the bill from $9,800 to $6,605 — a 32.6% cut from one change. The honest caveat is the write cost: writing the cache costs 1.25x the input price, so churn matters. The notebook runs the sensitivity: even if 20% of cached tokens are re-written every month, the bill is $7,280 — still a 25.7% cut. At 50% churn it is $8,630, and the lever is nearly dead. Caching pays when the same prefix is re-read many times between writes, which is exactly what chat and agent workloads do. One-off requests with no repeated structure get nothing from it.

Lever 2: batching — the free 50%

If a workload can tolerate a delay, batching is close to a free discount. OpenAI's Batch API and Anthropic's Message Batches API both cut input and output token prices by 50% in exchange for a processing window of up to 24 hours instead of a real-time response.

Good candidates: model evals and offline test runs, bulk classification, document summarization that does not feed a live user, nightly data enrichment. Bad candidates: anything a user is waiting on — live chat, real-time agent responses, interactive coding assistants. The mistake teams make is leaving async-eligible work on the synchronous API out of habit.

On the workload, 35% of requests are async-eligible. Moving them to batch takes the bill from $6,605 to $5,449 — a 44.4% cumulative cut — with zero quality tradeoff. Same model, same tokens, half the price. This is the lever with the least to argue about: if the work does not need an answer now, it should not pay the synchronous price.

Lever 3: model routing — the 100x spread

The price spread between the cheapest usable model and the frontier runs to roughly 100x, and on the models in the notebook it is 300x: GPT-5 nano lists $0.05 per million input tokens, GPT-5 Pro lists $15. Most requests do not need the $15 model. Routing is the lever that exploits that spread.

Input price per million tokens across ten models, log scale: GPT-5 nano $0.05, Gemini 2.5 Flash-Lite $0.10, GPT-5 mini $0.25, Gemini 2.5 Flash $0.30, DeepSeek V4 Pro $0.435, GPT-5 $1.25, Gemini 2.5 Pro $1.25, Claude Sonnet 5.5 $2.00, Claude Sonnet 4.5 $3.00, GPT-5 Pro $15.00.

Two approaches work. Static rules classify requests ahead of time: simple extraction and formatting go to a cheap model, multi-step reasoning goes to the frontier model. Learned routers do it per request: the RouteLLM framework showed a trained router choosing between a strong and weak model cut costs by more than 2x on benchmarks without compromising response quality, and the result held up even when the underlying models were swapped at test time. In production, teams running a tuned routing layer report bill reductions of 40 to 85%. Ramp's internally built router processes more than 2.75 trillion tokens a month and cut internal LLM costs by 30% with no drop in performance.

On the workload, 55% of synchronous requests are simple — classification, extraction, FAQ — and they move to Gemini 2.5 Flash at $0.30/$2.50. One request costs $0.006605 on Sonnet 5.5 and $0.001518 on Flash, 4.4x cheaper. The bill goes from $5,449 to $3,630, a 63.0% cumulative cut. The risk is quality regression: a router tuned on the wrong signal sends hard requests to a cheap model. Test it against a held-out set of your actual hard cases, not average traffic, before you trust it in production.

Lever 4: token discipline — free, and it compounds

This lever costs nothing to implement. If your system prompt is 2,000 tokens and you resend it uncached on every one of 200 calls in a session, that is 400,000 tokens spent re-reading the same instructions. Three habits fix most of the waste: trim conversation history — summarize or truncate once a conversation passes a reasonable length instead of sending the whole log; set output token limits — an unbounded max-tokens setting on a verbose model is an invitation to overpay for output nobody reads; and compact context in agentic loops — periodically compress accumulated tool outputs and intermediate reasoning into a summary instead of carrying the full trace forward.

On the workload, trimming fresh input 20% (600 to 480 tokens) and capping output 15% (500 to 425) takes the bill from $3,630 to $3,088. It is the smallest single cut, but it compounds with every other lever because it shrinks the tokens the other levers price. None of this requires new infrastructure. It requires someone to actually look at what is in the context window on a representative request and ask whether it needs to be there.

Lever 5: self-hosting — only past the threshold

Self-hosting is the lever with the highest setup cost and the biggest potential payoff, but only past a real volume threshold. The notebook does the crossover math on owned hardware: one RTX 4090-class GPU ($1,600) runs Gemma 3 27B in 4-bit at about 60 tokens/s sustained — 5.18M tokens a day. Amortized over 24 months plus power at $0.12/kWh, that GPU costs about $3.20 a day. The API charges this workload $3.38 per million tokens blended. Divide one by the other and the crossover is about 0.95M tokens a day: below it the API wins, above it owned hardware wins.

Monthly cost versus daily token volume, log-log: the API line and the owned-GPU step line cross at about 0.95M tokens per day.

The payback numbers explain why the threshold is where it is. A single GPU pays for itself in about 91 days against Sonnet 5.5's blended price — and in about 10 days against a premium API at roughly $30 per million blended, which is where the often-quoted 0.3-month break-even for small open models comes from. But the workload tells the harder truth: this workload burns 96.7M tokens a day, which needs 19 GPUs. Rented at $1 an hour, that fleet costs $13,680 a month — worse than the tuned API bill of $3,088. Owned, it costs $1,841 a month — but that takes $30,400 of capex, operations labor, and a model-quality swap: a 27B open model is not Sonnet 5.5. Self-hosting is the right lever when volume is high, the open model is good enough for the task, and you are willing to operate GPUs. It is the wrong lever as a first move.

The stack, in order

Monthly bill after each lever: baseline $9,800, caching $6,605, batching $5,449, routing $3,630, token discipline $3,088, self-hosting owned $1,841 with $30,400 capex.

The levers stack, and they stack in a sensible order. Start with caching and token discipline — near-zero implementation cost, applies to almost any workload immediately. Add batching for anything async-eligible. Add routing once traffic has volume and variety, because a router only pays off once you have enough request diversity to tell easy from hard. Consider self-hosting only past the volume or compliance threshold — below roughly 1 to 2 million tokens a day, the API is still cheaper once labor is counted. A team running the first four levers is not doing anything exotic. It is just not leaving money on the table at any layer of the stack — $9,800 down to $3,088, and $1,841 if the volume and the model justify owning the hardware.

Takeaways

Honesty note: all dollar figures are computed in the notebook from published provider list prices checked Nov 30, 2026 (Anthropic Sonnet 5.5 $2/$10, cache read $0.10, batch $1/$5; OpenAI GPT-5 $1.25/$10, cached $0.125; Gemini 2.5 Pro $1.25/$10, Flash $0.30/$2.50, cached $0.03; DeepSeek V4 Pro $0.435/$0.87 from a June 2026 listing). Sonnet 4.5 ($3/$15) retired Nov 30, 2026, so Sonnet 5.5 is the anchor. The workload is a stated model — 1M requests/month, 2,400 in / 500 out tokens — not production telemetry; cache churn (5%), async share (35%), and routed share (55%) are stated assumptions, with a churn sensitivity table in the notebook. GPU throughput (60 tok/s sustained) is a working number under the GDE #12 roofline of ~74 tok/s; GPU rental at $1/hr and power at $0.12/kWh are stated assumptions. Enterprise spend and survey figures are reported figures from a 2026 survey of 101 enterprise technology leaders, not this notebook's measurements. Prices move — re-check the provider pages before you budget. No Meta content per the standing exclusion.

Companion notebook: llm_api_cost_levers.ipynb — published price table with blended 3:1 costs and the 300x routing spread, baseline bill, caching with churn sensitivity, batching, routing by per-request cost, token discipline, the stacked waterfall, and the self-hosting crossover and payback math, all exec-tested.

Companion notebook

llm_api_cost_levers.ipynb — the runnable tutorial for this post (download, or open it in Colab/Jupyter).

← All posts