How much an AI agent costs: a step-by-step model spend calculation

Agent cost is set by the number of steps, context growth, cache and the model. A formula, three examples with arithmetic and a calculator you can plug your own numbers into.

8 min · · агенты · экономия

"AI agent price" is a question with no single answer, because cost is determined not by the model itself but by how it is used in a loop. An agent calls the model on every step and each time sends the accumulated context, so the bill grows faster than it seems. Below is a formula from which you can calculate the spend of any agent, three examples at Zukko prices as of October 18, 2026 and a small Python calculator. The current list of models and prices: GET https://api.zukko.pro/v1/models or the Models page in the dashboard.

What the cost consists of

For one request to a model:

cost = fresh input × input price + cache read × read price + cache write × write price + output × output price

Prices are per 1M tokens, so tokens are divided by 1,000,000. For an agent this request repeats on every step while the context grows. Notation:

  • N: number of steps;
  • C0: starting context (system instruction, tool descriptions, the task);
  • Δ: how many tokens are added to the context per step (tool result plus the model's reply);
  • O: output tokens per step.

The context at step k equals C0 + (k − 1) × Δ. If there is no cache, the total input for the whole task is:

input = N × C0 + Δ × N × (N − 1) / 2

The second term depends quadratically on the number of steps. So doubling the steps more than doubles the input.

Assumptions for the examples

For all examples below: C0 = 8,000 tokens, Δ = 1,500 tokens, O = 500 tokens per step, N = 20 steps (unless stated otherwise). These are illustrative numbers: in your agent they will differ, and you can measure them from the usage field of the responses.

Input per task: 20 × 8,000 + 1,500 × 20 × 19 / 2 = 160,000 + 285,000 = 445,000 tokens. Output: 20 × 500 = 10,000 tokens.

Example 1: a cheap model without cache

deepseek-v4.1-flash: input $0.013, output $0.038 per 1M tokens (for DeepSeek the cache read price equals the input price, so the cache changes nothing).

  • Input: 445,000 × 0.013 / 1,000,000 = $0.005785.
  • Output: 10,000 × 0.038 / 1,000,000 = $0.00038.
  • Total: $0.006165, about 0.6 cents per task.

For comparison glm-5.3-flash (0.04 / 0.04, 128K context): 445,000 × 0.04 / 1,000,000 + 10,000 × 0.04 / 1,000,000 = 0.0178 + 0.0004 = $0.0182.

Example 2: Claude Sonnet 5.5 with and without cache

claude-sonnet-5-5: input $0.4, output $2, cache read $0.05, cache write $0.5.

Without cache (for example, Claude is called in the OpenAI format, where all input is billed at the input price):

  • Input: 445,000 × 0.4 / 1,000,000 = $0.178.
  • Output: 10,000 × 2 / 1,000,000 = $0.02.
  • Total: $0.198.

With cache (Anthropic format, /v1/messages). The model works like this: on step 1 the starting context C0 is written to the cache, on each following step the whole previous context is read from the cache and the new part Δ is written. Then:

  • write: 8,000 + 19 × 1,500 = 36,500 tokens;
  • read: 19 × 8,000 + 1,500 × (0 + 1 + ... + 18) = 152,000 + 1,500 × 171 = 408,500 tokens;
  • check: 36,500 + 408,500 = 445,000, which is all of the input.

Cost:

  • write: 36,500 × 0.5 / 1,000,000 = $0.01825;
  • read: 408,500 × 0.05 / 1,000,000 = $0.020425;
  • output: $0.02;
  • total: $0.058675, about $0.059.

The difference between $0.198 and $0.059 is explained entirely by the format and the cache. This is the ideal case where the cache hits on every step; in practice there are misses (a model switch, an edit at the start of the prompt, a pause longer than the cache lifetime), so the real result lies between these numbers.

For comparison, GPT. gpt-6.1-sol (input 0.27, output 1.32, cache read 0.013): a cache write is not billed separately for GPT, so new tokens go at the input price. Fresh input: the new parts of the context, the same 36,500 tokens, at the input price: 36,500 × 0.27 / 1,000,000 = 0.009855. Read: 408,500 × 0.013 / 1,000,000 = 0.0053105. Output: 10,000 × 1.32 / 1,000,000 = 0.0132. Total: 0.009855 + 0.0053105 + 0.0132 = $0.0283655, about $0.028. We assume the cache hits on all steps; for GPT the cache read is visible in both formats.

Example 3: a long session on Opus 5.5

A complex task: N = 60 steps, C0 = 15,000, Δ = 2,000, O = 800 tokens per step. Model claude-opus-5-5: input $0.8, output $4, cache read $0.08, write $1.

Total input: 60 × 15,000 + 2,000 × 60 × 59 / 2 = 900,000 + 3,540,000 = 4,440,000 tokens. Output: 60 × 800 = 48,000 tokens.

Without cache:

  • input: 4,440,000 × 0.8 / 1,000,000 = $3.552;
  • output: 48,000 × 4 / 1,000,000 = $0.192;
  • total: $3.744.

With cache (Anthropic format):

  • write: 15,000 + 59 × 2,000 = 133,000 tokens, 133,000 × 1 / 1,000,000 = $0.133;
  • read: 4,440,000 − 133,000 = 4,307,000 tokens, 4,307,000 × 0.08 / 1,000,000 = $0.34456;
  • output: $0.192;
  • total: $0.66956, about $0.67.

What the examples show

  1. Steps matter more than the model. With the same C0 and Δ, doubling steps from 20 to 40 raises the input from 445,000 to 40 × 8,000 + 1,500 × 40 × 39 / 2 = 320,000 + 1,170,000 = 1,490,000 tokens. On claude-sonnet-5-5 without cache that is $0.636 instead of $0.198 (1,490,000 × 0.4 / 1,000,000 + 20,000 × 2 / 1,000,000).
  2. Cache matters for Claude and GPT. For long sessions with a repeated prefix a cache read is cheaper than input, and for Claude the request format affects spend more than many settings. In the OpenAI format Claude gets no cache.
  3. Cheap models change the scale. The task in example 1 costs a fraction of a cent. But a weak model may need more steps or fail to solve the task, so count the cost of a solved task, not the cost of a step.
  4. Reasoning is output too. If the model spends tokens on reasoning, they are billed as output; increase the O parameter.

The calculator

The function takes prices from the table and computes spend with and without cache:

bash
def agent_cost(n, c0, delta, out, p_in, p_out, p_cache_read=None, p_cache_write=None):
    """Prices in $ per 1M tokens. Context at step k = c0 + (k-1)*delta."""
    total_in = n * c0 + delta * n * (n - 1) // 2
    out_cost = n * out * p_out / 1_000_000
    if p_cache_read is None:                      # no cache: all input at the input price
        return total_in * p_in / 1_000_000 + out_cost
    written = c0 + (n - 1) * delta                # new parts, written to the cache
    read = total_in - written                     # the rest is read from the cache
    return (read * p_cache_read + written * p_cache_write) / 1_000_000 + out_cost

print(agent_cost(20, 8000, 1500, 500, 0.4, 2))             # no cache: 0.198
print(agent_cost(20, 8000, 1500, 500, 0.4, 2, 0.05, 0.5))  # with cache: ~0.0587

Replace the numbers with your own. Take real C0, Δ and O from the usage of several actual runs of your agent, and the prices from GET /v1/models. If you want to estimate a request size in advance, the token counting endpoint POST /v1/messages/count_tokens is useful. Note that this function computes the ideal case with a cache hit on every step, so for an upper-bound estimate use the "no cache" variant.

"AI agent free"

Many price queries are really about free access. Honestly: Zukko has no free tier, payment is per token from a balance starting at $1. Free tiers of third-party services and agents exist, but their terms and limits change and we do not know them, so check current terms on the service's site. With cheap models the cost of small tasks is measured in fractions of a cent (example 1), though that is not free either. You can top up via SBP (the payment page adds 8.5% on top), cryptocurrency or a MasterCard card.

How to keep spend in check

  • A step ceiling in the agent itself (in the examples above it equals N).
  • A separate key with a daily limit in $ and a list of allowed models: key limits documentation.
  • A cheap model for routine, an expensive one for hard steps: the idea is covered in Model cascade for LLMs.
  • Context compaction and a clean session per task.
  • Verification on real runs: watch spend on the Usage page of the dashboard.

A step-by-step breakdown of a Claude Code session with cache is in How much a Claude Code agent costs. You create a key for the agent in the Zukko dashboard.

FAQ

How much does one agent step cost?

It depends on the context size at that step. A step at the start of a session is cheap, at the end expensive: the context grows. So average over the task, as in the examples.

Why does spend grow non-linearly?

Because on every step the whole accumulated context is sent to the model. The total input contains a term proportional to the square of the number of steps.

How do I tell that the cache works?

For Claude in the Anthropic format look at the cache_read_input_tokens and cache_creation_input_tokens fields in usage. For GPT, prompt_tokens_details.cached_tokens. If the read is zero on long sessions, the request prefix changes between steps.

Which model should I take for an agent?

Compare by price, context and intelligence index and test on your own tasks: a solved task matters more than a cheap step. Index from the table: claude-opus-5-5 58, gpt-6.1-sol 52, claude-sonnet-5-5 48, deepseek-v4.1-flash 39.

zukko

Pay 25×
less

for Claude Code & ChatGPT

One fetch_* key and base URL api.zukko.pro — for Cursor, Claude Code, Codex, and any SDK.

Get API keyDocumentation

api.zukko.pro · fetch_*

AI agent cost: a step-by-step calculation · Zukko