Agent cost playbook

Cut your AI agent's API bill

Agents resend their context on every step, call tools in parallel and retry when they are throttled, so their API bills grow much faster than chat. Here are seven tactics, ordered by typical savings, each with the case where it won't help.

TacticWhat it usually saves
Prompt cachingOften more than half of input spend
Route by task sizeRoutine steps at a tenth of the price or less
Context hygieneKeeps late steps as cheap as early ones
Kill retry stormsA ceiling on the runaway night
Batch APIsHalf price on OpenAI and Anthropic batches
Cheap open‑weight models$0.15 to $0.30 per million input tokens, against $2 to $5
A fixed monthly budgetA bill you set in advance

Prompt caching

Cache the stable parts of every request: system prompt, tool definitions, large documents and conversation history. On Anthropic, cache reads bill at 10% of the input price and don't count toward input-token rate limits.

Works when
Agents resend nearly identical context on every step, so most of each request can come from cache.
Doesn't help when
Tasks are short one-shots with no repeated context, or the provider prices cache reads poorly.

Route by task size

Send routine steps (file triage, summaries, tool routing, subagent chatter) to a cheap model and keep the frontier model for the steps that need judgment.

Works when
Most agent steps are mechanical, and the cheap tier lists at a tenth of frontier prices or less.
Doesn't help when
Routing misfires and cheap-model mistakes turn into expensive retries. Start conservative, measure, then widen.

Context hygiene: compact and reset

Compact long sessions and start fresh for each task. Every tool result you append rides along on every later call, and so do CLAUDE.md, AGENTS.md and MCP tool definitions.

Works when
Cost per step grows with session length, so regular compaction keeps the late steps of a long session close to the price of the first ones.
Doesn't help when
Pruning gets so aggressive that the agent forgets and redoes work, which costs more than the tokens saved.

Kill retry storms

Use exponential backoff with jitter, honor retry‑after headers, cap attempts and alert on failure loops. A 429 storm bills you for attempts while accomplishing nothing.

Works when
Runaway retry loops are a common cause of surprise overnight bills, and a retry budget puts a ceiling on them.
Doesn't help when
The agent already runs cleanly. The everyday bill stays the same.

Batch APIs for non-interactive work

Move evaluation runs, backfills and bulk processing to provider batch endpoints. OpenAI and Anthropic bill batch requests at half the normal rate, and batches don't compete with your live rate limits.

Works when
Any workload that can wait minutes to hours for results.
Doesn't help when
The work is interactive, like a live agent loop.

Cheap open-weight models where quality tolerates it

DeepSeek V4.1 Flash, GLM 5.3 Flash and MiniMax M3 list at $0.15 to $0.30 per million input tokens, against $2 for Claude Sonnet 5 and $5 for Claude Opus 5 (maker list prices, October 2026).

Works when
High-volume, low-stakes steps, subagents, and anything you would hand to a junior developer.
Doesn't help when
The step needs long-horizon planning or hard debugging, where frontier models still pull ahead. Measure on your own tasks.

A fixed monthly budget for always-on agents

Past a few hours of daily agent runtime, stop optimizing per-token spend and cap it with a flat monthly price.

Works when
Always-on agents, heavy daily coding use, and anywhere you have caught yourself rationing the agent to protect the bill.
Doesn't help when
Use is light or bursty. Cheap per-token models win there, as the cheapest-API math shows.

Where Standard Compute fits

Standard Compute gives your agents one API key on a monthly plan: from $19 a month with a fixed monthly compute budget ($20 on Starter), and a router that sends each request to an efficient model.

Agent API costs: common questions

Why is my AI agent's API bill so high?

Agents multiply costs in three ways chat doesn't: they resend growing context on every step, they make many calls per task (planning, executing, verifying, retrying), and failures trigger retries that bill without producing anything. A single overnight loop can make hundreds of frontier-model calls.

What single change cuts agent API costs the most?

Usually prompt caching, because agents resend nearly identical context on every call. Cache-hit rates above 70% are common and can more than halve input costs. Second is routing routine steps to cheaper models. For always-on agents, flat-rate pricing caps the bill entirely.

How do I stop an agent from burning money overnight?

Hard caps: a retry budget with exponential backoff, a per-session spend or step limit, and provider-side spend limits where offered. Then cap the downside: most overnight burns are 429 retry storms, and on a flat-rate endpoint with a fixed monthly budget a runaway loop can stop your agent but can't add to your bill.