In short
- You pay per token: input (what you send) and output (what the model writes), with a price per 1 million tokens.
- Every step of an agent loop sends the whole conversation again, so input tokens grow step by step.
- Example at Claude Sonnet 5.5 API prices: 1 chat answer is about 1 cent, a 20-step agent run about $1.40 (an illustration, not a measurement).
- Pay less with prompt caching, a smaller model for simple steps, and the Batch API for jobs that can wait.
You pay per token, in and out
A token is a small piece of text, often part of a word. AI APIs count tokens and charge a price per 1 million tokens (MTok). There are two prices: one for input tokens, the text you send, and one for output tokens, the text the model writes. Output is usually several times more expensive.
A plain chat is one round: your question goes in, an answer comes out, and you pay for both once.
Why the agent loop multiplies the bill
An agent works in a loop: plan, act with a tool, read the result, decide the next step. To decide, the model needs to see everything so far. So each step sends the whole conversation again: your task, earlier steps, tool results, file contents.
That means the input grows with every step, and you pay for it again each time. Twenty steps is not twenty small questions. It is twenty ever-longer questions.
A worked example
Prices: Claude Sonnet 5.5 costs $2 per 1M input tokens and $10 per 1M output tokens on the Claude API. The numbers below are an illustration, not a measurement of a real run.
- 1 chat answer: 2,000 tokens in ($0.004) + 500 tokens out ($0.005) = about 1 cent.
- A 20-step agent run: 600,000 tokens in ($1.20) + 20,000 tokens out ($0.20) = about $1.40.
- Most of the agent's cost is input: the same context read again and again.
Real API prices (per 1M tokens, input / output, checked Nov 23, 2026)
Prices change often and some depend on prompt length. Check the provider's pricing page before you plan a budget.
- Claude Sonnet 5.5: $2 / $10 (Anthropic)
- GPT-6.2 Sol: $2 / $10 (OpenAI, standard rate)
- Gemini 3.1 Pro Preview, prompts up to 200K tokens: $2 / $12 (Google)
- Claude Haiku 5.5, prompts up to 100K tokens: $0.10 / $0.50 (Anthropic)
3 ways to pay less
- Prompt caching: context that repeats (instructions, files) is stored and read back cheaply. On the Claude API a cache hit costs 0.1x the base input price on most models, and 0.05x on Claude Opus 5.5 and Sonnet 5.5. Writing to the cache costs a bit more than normal input.
- A smaller model for simple steps: Claude Haiku 5.5 costs a fraction of a large model, so use it where it is good enough.
- Batch API: for jobs that can wait, the Claude API gives 50% off both input and output tokens.
Tip for Claude Code users
Type /usage to see your current session's token usage. In a long session, use /compact to summarize the history, or /clear to start fresh when you switch to unrelated work. Stale context costs tokens on every message.
On a Pro, Max or Ultra plan, usage is part of your subscription, so the session cost figure is mainly useful for API users.
Test yourself
5 quick questions. Pick an answer to check it.
Sources
- Claude API docs: Pricing (model prices, prompt caching, Batch API)
- OpenAI API: Pricing
- Google Gemini API: Pricing
- Claude Code docs: Manage costs effectively (/usage, /compact, /clear)
Checked November 23, 2026.