LLM Token Pricing: Why Your API Bill Surprises You

Chart of LLM token pricing and cache hit rate for a 25-turn coding agent session

LLM token pricing catches many teams out. The usual estimate takes the listed input price, multiplies it by what users might type and predicts pennies. Then the feature ships, or a coding agent runs all afternoon, and the invoice lands at ten times the forecast.

Four effects account for nearly every surprise: output is priced above input, hidden context is billed on every call, multi-turn sessions grow quadratically, and one changing line can defeat prompt caching.

Output costs four to five times more

Frontier APIs price output well above input. On gpt-4.1-mini, input costs $0.40 per million tokens and output $1.60, a 4x gap. On gpt-4.1 the ratio is also 4x, at $2.00 and $8.00. Claude Sonnet 4.5 charges $3.00 for input and $15.00 for output, a 5x gap, and Claude Opus charges $5.00 and $25.00, also 5x.

The gap reflects how GPUs run transformers. Reading the prompt (prefill) happens in parallel across all input tokens. Writing the reply (decode) goes one token at a time, and each step reloads model weights from GPU memory, so memory bandwidth limits speed and an output token occupies hardware longer.

In practice, a support triage endpoint that returns a 700-token explanation when a 35-token JSON label would do pays a steep tax on every request.

Side-by-side chart of the live 8-turn cache hit rate and the 25-turn coding agent quadratic cost model
Image: flaviocopes.com

Tokens are not words

About four characters per token works for plain English prose. Code, JSON and logs land closer to 2.2 to 2.8 characters per token because of braces, quotes, indentation and UUIDs. Italian, Spanish, French and German commonly need 20% to 40% more tokens than English for the same sentence, and Japanese, Korean, Arabic and Hindi can need two to three times as many.

Images add their own cost. On high-detail OpenAI vision calls, a screenshot costs an 85-token base plus 170 tokens per 512×512 tile. An agent that attaches a new full-resolution screenshot every turn adds 1,000 to 1,500 tokens per frame, and it keeps re-sending older ones unless the agent software drops them from history.

Terminal output of the live 8-turn gpt-4.1-mini prompt cache experiment and 25-turn agent cost model
Image: flaviocopes.com

Hidden input on every call

A typed request like “Fix the failing date parser test” is roughly 8 tokens, yet far more goes over the wire: an 800 to 3,000 token system prompt, each tool definition as JSON Schema, any retrieved files or search results, and the full earlier conversation. One well-documented tool schema can use 150 to 450 tokens. Connect an agent to three MCP servers exposing 40 tools and you add 8,000 to 12,000 tokens to every call.

Caching, reasoning and batches

OpenAI enables prefix caching by itself for prompts of 1,024 tokens or more and adds no write fee. Repeat calls sharing that prefix are 75% cheaper on gpt-4.1 and gpt-4.1-mini. Anthropic prices cache writes and reads apart. Writing with a 5-minute lifetime costs 1.25x the base input rate ($3.75 per million on Sonnet 4.5), a 1-hour lifetime costs 2x ($6.00), and every read is 0.10x ($0.30). The short write is repaid by one read, the long one by two.

Reasoning models bill for thinking you never see. If 3,200 internal tokens produce a 180-token answer, you pay for 3,380 output tokens. Leave high reasoning effort on across 1,000 classification jobs and a $2 batch can become $90. Setting a fixed effort level or thinking cap per endpoint prevents it.

OpenAI, Anthropic and Google all offer batch APIs that halve the price of input and output tokens if you accept a 24-hour completion window. They fit nightly evals, backfills and classifying old support threads.

Long context adds a price cliff. Past roughly 200,000 or 272,000 input tokens, many providers reprice the entire request, commonly at 2x for input and 1.5x for output. An agent session that creeps from 195K to 210K tokens suddenly pays double for input on each turn.

Why agent sessions grow quadratically

Because LLM endpoints keep no state, a coding agent resends the whole conversation every turn. Take a 6,000-token starting prefix that grows by 1,800 tokens per turn: by turn 25 each request carries 49,200 tokens. Over 25 turns that adds up to 690,000 input tokens and 11,250 output tokens. At Sonnet 4.5 rates, uncached, that costs $2.2388, of which output is under 8%.

With a stable prefix and 88% cache reuse, the same session costs $0.6136, a 72.6% cut. Adding compaction at turn 13, which replaces earlier logs with a 2,000-token summary, brings it to $0.4546, which is 79.7% below the uncached cost. Doubling the session to 50 turns lifts the uncached bill to $7.8525, or 3.51 times the 25-turn figure.

For ten developers running fifteen 25-turn sessions a day, the gap is $335 a day uncached against $68 with caching and compaction.

Budget controls to put in place

The practical advice is to route offline evals and archive backfills through batch APIs and to give every unattended script an explicit dollar cap, such as a –max-budget-usd flag or a budget guard wrapper, so a stuck agent halts at $1.00. A hard cap matters when outside users can trigger model calls, when an agent loop runs without supervision, or when one bad session on a frontier model could pass $5 to $10.

For a tiny internal script that costs about $3 a month on gpt-4.1-mini, a $20 monthly cap on a dedicated key is enough.

Source: flaviocopes.com

Written by

Saksham Bhargava

Saksham Bhargava runs Alteroid and has been writing about consumer technology for over five years, covering iPhone, Android, Windows, AI tools and gaming. With an MCA and six years of hands-on web development experience, he tests the features he writes about on his own devices and focuses on clear, practical guides that solve real problems. Away from the screen, he enjoys travelling to places most tourists skip.