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.
| Tactic | What it usually saves |
|---|---|
| Prompt caching | Often more than half of input spend |
| Route by task size | Routine steps at a tenth of the price or less |
| Context hygiene | Keeps late steps as cheap as early ones |
| Kill retry storms | A ceiling on the runaway night |
| Batch APIs | Half 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 budget | A 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.
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.
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.
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.
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.
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).
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.
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.
The same tactics, agent by agent
Spend limits and fixed budgets
What agents actually cost
- Agent Burn Index: how many tokens agents use
- What it costs to run an AI agent 24/7
- What AI coding agents cost per month
- The cheapest way to run Claude Code
- Codex CLI pricing: plans, API cost and limits
- The best subscription for Hermes Agent
- What your coding agents would cost at API prices
- LLM API cost calculator
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.