What one agent step costs
Take a step with 100,000 tokens of context on Claude Sonnet 5.5. Input costs $2.40 per 1M tokens, cache reads $0.12 and cache writes $3.
Output costs the same in all three cases, so it’s left out of the table. Two rules follow from this:
- With a working cache, a step is about 13 times cheaper. So the first thing to do is make sure caching actually works.
- One cache invalidation costs as much as 17 regular steps. So don’t break the cache mid-task unless you have to.
1. Make sure caching works
Claude Code handles caching on its own when used through RuAPI: it uses the native Anthropic format and sets the cache markers, and RuAPI passes them through unchanged. To check, run/usage: in the Session block, the Prompt cache (main) line shows what share of input came from the cache and how many misses there were (requires version 2.1.251 or later).
Cline caches Claude only with the Anthropic provider and the base URL https://www.ruapi.ai. RuAPI’s OpenAI-compatible endpoint supports Claude caching too, but only when the client puts cache_control markers in the request — and Cline doesn’t add them in OpenAI Compatible mode (per Cline’s source code as of Oct 16, 2026). So in that mode every step is billed at the full input price, as in the second row of the table. Setting up the Anthropic provider is covered in the Cline guide.
DeepSeek and GPT cache automatically, whatever tool you use.
You can see the same in the RuAPI console: Usage Logs → entry details → the “Cache Tokens” line. If repeated steps don’t show it, the cache isn’t being hit. More in Prompt caching.
2. Don’t break the cache mid-task
The cache is tied to the beginning of the request: if anything at the start changes, everything after it is processed and written again. According to the Claude Code documentation, the cache is invalidated by:- Switching models. Each model has its own cache, so after
/modelthe next request re-reads the entire history uncached. - Changing the effort level — on most models.
- Connecting or disconnecting an MCP server mid-session.
/compact: the history is replaced with a summary, and its cache is built from scratch.- A break longer than 5 minutes. That’s how long the cache lives when you use an API key; every request extends it by another 5 minutes.
- Updating Claude Code: a new version usually changes the system prompt.
/rewind. Editing CLAUDE.md mid-session doesn’t break the cache either, but the change only takes effect after /clear, /compact or a restart.
In practice:
- Pick the model and effort level at the start of a session. Switch models between tasks, ideally together with
/clear. - Finished a task? Run
/clearbefore you take a break. Otherwise the first request after the break writes the whole long context to the cache again. - In Cline, switching between Plan and Act with different models is also a model switch: the first request in the new mode goes out uncached. That’s why it pays to put a cheaper model on Act. With the same 100,000-token context, a cache miss on
deepseek-flashcosts about $0.017 — almost 18 times less than on Sonnet.
3. Match the model to the job
Prices per 1M tokens from the pricing page as of Oct 16, 2026:- Claude Haiku 5.5 is 20 times cheaper than Sonnet 5.5 on input and output and 10 times cheaper on cache reads, as long as the whole request, cache included, stays within 100,000 tokens. Beyond that, the entire request is billed at the higher tier (that’s how Anthropic itself prices it), and the gap shrinks to 4 times on input and output and 2 times on cache reads. In a long task, an agent’s context quickly grows past 100,000 tokens, so Haiku pays off most on short tasks and in helper agents.
- DeepSeek Flash is 14 times cheaper than Sonnet 5.5 on input, 10 times cheaper on cache reads and about 8 times cheaper on output. It accepts images too. What that adds up to over a full day of work is shown in DeepSeek vs Claude.
- Claude Opus 5.5 is for the hardest tasks: its input and output cost twice as much as Sonnet’s.
- Switch models with
/model— preferably between tasks, see section 2. - In a subagent’s configuration you can set
model: haiku, and whatever you delegate to it, such as searching the code or running tests, will run on Haiku. For thehaikualias to point toclaude-haiku-5-5, yoursettings.jsonneeds the line"ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-5-5"— it’s already in the Claude Code guide. - The model’s reasoning is billed as output. For simple tasks, lower the level with
/effort— at the start of the session, so you don’t break the cache. - You can also run Claude Code entirely on DeepSeek — see Claude Code on DeepSeek V4 Pro.
- Turn on Use different models for Plan and Act: plan with a strong model, make the edits with a cheaper one. Suggested pairings are in the Cline guide.
4. Keep the context short
Every token in the context is paid for on every step — even if at the cache price. In Claude Code/clearbetween unrelated tasks. Old context doesn’t help the new task, yet you pay for it on every step./clearitself costs nothing. If you’ll need the session again, name it with/renamefirst; you can get back to it with/resume./compactbetween stages of work, not in the middle of one. It’s a large request in its own right: the model re-reads the whole history to summarize it. While the cache is still warm, that’s cheap; after a break, the same command re-reads everything uncached. You can tell it what to keep:/compact keep the code changes and test output./rewindinstead of “no, not like that”. If the agent went down the wrong path, roll back to the step before the mistake. The history is cut back to a beginning that is already cached, and the failed branch is no longer paid for on every step.- Turn off MCP servers you don’t need with
/mcp. WhenANTHROPIC_BASE_URLpoints somewhere other than Anthropic — RuAPI included — Claude Code by default sends the definitions of every tool from every MCP server with each request. Where a CLI tool exists (gh,aws,gcloud), it’s cheaper than an MCP server./contextshows what takes up the context. - Keep CLAUDE.md under 200 lines. It loads into every session. Move detailed instructions for specific workflows, such as code review or migrations, into skills: those load only when needed.
- Specific tasks. “Improve the code” makes the agent read half the project; “add input validation to the login function in auth.ts” — a couple of files.
- Long output through hooks. A hook can trim test output down to the failing checks, so the agent reads a hundred tokens instead of tens of thousands. There’s an example hook in the Claude Code documentation.
- New topic, new task.
/newtaskstarts a new task and carries over only what matters: the plan, progress so far, relevant files and next steps. /smol(or/compact) condenses the current task’s history into a short summary.- Point to files explicitly with
@, so the agent doesn’t search the whole project for them.
5. Keep spending under control
- Usage Logs in the RuAPI console show the model, tokens, cached tokens and the amount charged for every request.
- A separate key with a limit. Create a dedicated key for the agent and set a limit on it under API Keys: the agent can’t spend more than that.
- The amount in
/usageis only an estimate. Claude Code calculates it itself at Anthropic’s list prices, not RuAPI’s. The exact charges are in Usage Logs.
In short
- Claude in Cline — only through the Anthropic provider; in Claude Code, check caching in
/usage. - Pick the model and effort level at the start of a session; change them between tasks.
- New task —
/clearin Claude Code,/newtaskin Cline. - Hand routine work to Haiku 5.5 or DeepSeek Flash; keep Sonnet and Opus for tasks that really need them.
- Turn off MCP servers you don’t use; keep CLAUDE.md short.
FAQ
Why is the first request after a break so expensive?
Why is the first request after a break so expensive?
With an API key, the cache lives for 5 minutes after the last request. After a break, the whole context is written to the cache again — at the cache write price, 1.25 times the regular input price — and then caching works as usual. If the task is finished, run
/clear before the break: the new session starts with a short context.The amount in /usage doesn't match what RuAPI charged
The amount in /usage doesn't match what RuAPI charged
Claude Code calculates the cost itself at Anthropic’s list prices and doesn’t know RuAPI’s prices. Go by Usage Logs in the console: those are the amounts actually charged to your balance.
My balance is draining faster than expected. What should I check first?
My balance is draining faster than expected. What should I check first?
Whether the cache is hit: Usage Logs → entry details → “Cache Tokens”. If repeated steps don’t show this line, Claude is most likely connected through the OpenAI-compatible format without cache markers — in Cline, pick the Anthropic provider. The step-by-step check is in Prompt caching.
Can I use Claude Code without Claude?
Can I use Claude Code without Claude?
Yes: you can switch Claude Code to DeepSeek while keeping your RuAPI key and base URL — see Claude Code on DeepSeek V4 Pro. Keep in mind that
deepseek-v4-pro doesn’t accept images: for screenshots, switch to deepseek-flash.Next steps
Prompt caching
How caching works for Claude, GPT and DeepSeek, and how to check for hits.
DeepSeek vs Claude
The same day of work at different models’ prices.
Claude Code
Connecting Claude Code to RuAPI.
Cline
Claude through Anthropic, DeepSeek and GPT through OpenAI Compatible.