The invoice arrives, someone screenshots it into Slack, and the first instinct is procurement: negotiate a discount, swap in a cheaper model, put a hard cap on spend. Those moves are real, but they usually move the number by 10–20%. The other 80% is structural. It lives in how you assemble context, how often you re-send it, and how your agent behaves when a tool call fails. None of that appears on a rate card.

Input tokens dominate, and most of them are repeats

Open your logs and count, per request, input tokens against output tokens. In chat, RAG, and agent workloads the ratio is rarely below 8:1 and often above 20:1. A support assistant that sends a 4,000-token context — system prompt, tool schemas, retrieved chunks, six turns of history — and returns a 300-token answer is spending most of its money on the part of the request the model only reads.

Do the arithmetic on your own traffic: one million requests a month at 4,000 input tokens is 4 billion input tokens; the same million at 300 output tokens is 300 million. Price both at whatever your provider charges and the shape is obvious — input is 70–90% of the bill, and it is the part teams instrument least.

The rest is history. Multi-turn chat re-sends the entire transcript on every turn, so a 20-turn conversation pays for turn one twenty times. That is the pattern to attack first, and it is visible in fifteen minutes of log inspection.

Prompt caching is a prompt-layout decision, not a feature flag

Hosted providers now price cached input reads at a fraction of the base rate — roughly a tenth on some, half on others — with a small write premium. Run the break-even: with a 1.25x write and reads between 0.1x and 0.5x, you are ahead on the second call that reuses the prefix. If a prefix is reused three or four times inside the cache TTL, skipping it is a straightforward loss.

Caching is not a switch you flip. It is a property of ordering:

  • Stable content first: system prompt, tool definitions, policy text, few-shot exemplars.
  • Variable content last: the retrieved chunk, the user ID, the timestamp, the question.
  • No dynamic values above the cache breakpoint. A single formatted timestamp at the top of the system prompt invalidates everything below it.
  • Set the breakpoint explicitly where supported, and match the TTL to your reuse interval — a one-hour cache costs more to write and only pays off if reuse happens on the order of minutes.

Then measure hit rate as a first-class metric. A well-ordered prefix under dense traffic can reach 80–90% cache hit rates; a badly ordered one sits near zero while looking identical in code review.

The cheapest token is the one you never send, and the second cheapest is the one the provider already remembers.

Route on task difficulty, not on model prestige

Measure what fraction of your traffic actually needs the frontier model. In most production mixes it is a minority — classification, extraction, formatting, and short factual answers dominate. If a small model costs a tenth of a large one and handles 85% of calls, your blended cost is 0.85 + 1.5 versus 10, or roughly 75% cheaper at identical volume.

The gate is evaluation, not intuition. Build a labeled set per route, run both models, and require non-inferiority on the tasks you route away. Start the classifier with cheap heuristics before you reach for a model: does the request require a tool call, is the top retrieval score low, is the prompt unusually long, does it involve multi-step arithmetic. Log the routing decision alongside the request so a quality regression is debuggable rather than mysterious.

Agent loops write a second invoice

A tool-use agent that fails schema validation and re-prompts with the full 6,000-token context has just paid for the entire task again. Three retries and you are at 4x on a request that produced nothing. Guardrails that pay for themselves in a week:

  1. Cap steps per task and fail closed when the cap is hit.
  2. Set max_tokens and stop sequences on every call, including the ones inside loops.
  3. Cache tool results within a run so a repeated lookup is free.
  4. On a validation error, send the error and the offending fragment — not the whole trace — to the repair prompt.
  5. Enforce per-request and per-tenant budget ceilings, and alert on p99 tokens per task rather than p99 latency.

One retry storm can add more spend in an hour than a month of prompt tuning saves, which is why the guardrails belong in the same review as the agent logic.

The unit that matters is cost per successful task

Output tokens cost several times what input costs on most rate cards, and verbosity is contagious: step-by-step instructions leaking into production prompts, chain-of-thought appearing in the payload, three paragraphs for a yes/no question. Constrain with max_tokens, structured output, and a terse exemplar. Move everything asynchronous — backfills, nightly summarization, embedding refresh — to batch APIs, which typically price near half of interactive rates.

Then divide. Cost per resolved ticket, per merged PR, per document processed. Cost per successful task is the only figure that survives a model swap, because it captures the quality regression that cheaper tokens quietly hide. Put it on the same dashboard as latency and error rate, and gate prompt changes in CI on quality and cost together, the way you gate a build on tests.

Where this is heading: cost as an SLO

Per-token prices keep falling and consumption keeps rising faster, because cheaper inference expands the set of things worth doing. The teams that come out ahead will not be the ones with the best negotiated rate; they will be the ones that treat spend as an SLO with an owner, a budget, and an alert that pages before the invoice does. The next step is closed-loop: routers that retrain on eval feedback, semantic caches with measured false-hit rates, and remediation agents that roll back a prompt change when cost per task drifts 15% with no quality gain. That tooling exists. What most organizations still lack is the per-task cost metric to trigger it.