الانتقال إلى المحتوى
أساسيات الـ AIمفاهيم الـ AI· 8 دقائق للقراءة

You Pay for the Whole Conversation Every Turn: How LLM Costs Add Up

Each request bills the full history again, so a chat's cost grows much faster than its messages. Measure it, then cache it.

ReadIn

مقال كل يوم يفرق معاك

21 نوفمبر 2026
  • كاتب موثّق
محتويات المقال

A team launches an internal assistant and budgets it from the average message: about 200 tokens in and 400 out. The first invoice is several times the budget. The questions weren't longer than expected; the sessions were. By the thirtieth turn of a conversation, every request carried the system prompt, the tool definitions and twenty-nine earlier exchanges, and each of those tokens was billed again.

The common misconception

"Each chat turn only costs the tokens of the new message I send." It's a natural assumption:

  • A chat UI shows one new message per turn, so that feels like the unit of work.
  • Pricing pages list a price per million tokens, which invites "message size × price".
  • The first turns of a session are cheap, so early tests confirm the estimate.
  • Chat products and SDK helpers manage history for you, and message threads (in beta) even let a request send only the new messages.

The half-truth: you do pay per token, and the new message is part of what you pay for. But the tokens you pay for on a turn are everything the model reads on that turn, and that's far more than what you typed.

What actually happens

Every turn re-reads the conversation

As the Understanding LLMs path showed, the Messages API is stateless: you send the full conversational history on every request. Message threads don't change the bill either; Anthropic's docs say they make requests smaller and faster to start, but threads "do not change pricing". The model reads the whole again, and you pay for reading it.

What's in each request's bill

On Claude Opus 5.5, Anthropic's pricing page lists $4 per million input and $20 per million output tokens. Input on a given turn includes:

  • The system prompt, every time.
  • Tool definitions, plus a tool-use system prompt the API adds when you send tools (286 tokens on Claude Opus 5.5 with automatic tool choice).
  • Every earlier user and assistant message, including tool results, which are often the bulkiest part.
  • Earlier thinking. Thinking is billed as output when it's generated, even when its text isn't returned to you, and on models that keep prior thinking in context, such as recent Opus models, it's billed as input on later turns too.

Output is the reply plus that turn's thinking, at five times the input price.

The arithmetic: linear per turn, quadratic per session

Because each request carries all earlier turns, the input of turn n grows in a straight line with n. Summed over a session, that's a quadratic curve. Take a chat with a 3,000-token system prompt and tools, 200-token questions and 400-token answers on Claude Opus 5.5. Turn 1 sends 3,200 tokens; turn 10 sends 8,600; turn 30 sends 20,600. A per-message estimate for 30 turns says $0.26. The model below says $1.67.

Python chat_cost.py
PRICE = {"in": 4.00, "write": 5.00, "read": 0.20, "out": 20.00}  # $/MTokdef chat_cost(turns, system=3_000, ask=200, answer=400, cached=False):    cost, cached_prefix = 0.0, 0    for turn in range(1, turns + 1):        sent = system + turn * ask + (turn - 1) * answer  # full history        if cached:  # earlier turns are cache reads, the new tail a write            cost += cached_prefix * PRICE["read"]            cost += (sent - cached_prefix) * PRICE["write"]            cached_prefix = sent        else:            cost += sent * PRICE["in"]        cost += answer * PRICE["out"]    return cost / 1_000_000print(f"uncached ${chat_cost(30):.2f}")  # uncached $1.67print(f"cached ${chat_cost(30, cached=True):.2f}")  # cached $0.41

Caching changes the price of the repeat, not its size

stores the processed prefix of a request (tools, then system, then messages) and reuses it when a later request starts with exactly the same content. With automatic caching, one top-level cache_control field moves the cache point to the end of each request as the chat grows, so every turn reads the earlier conversation from the cache and writes only the new part.

On Claude Opus 5.5, a cache read costs 0.05 times the base input price ($0.20 per million) and a 5-minute cache write costs 1.25 times ($5). That's the cached line in the model: $0.41 instead of $1.67. Notice what's left: $0.24 of it is output, which caching never touches.

The docs list the conditions. The default cache lives 5 minutes and every hit refreshes it at no extra cost; a 1-hour cache costs 2 times the base price to write. Prompts shorter than the model's minimum, 512 tokens on Claude Opus 5.5, aren't cached and no error is returned. And any change to the prefix invalidates what follows it: edit a tool definition and the whole cache is gone.

Read the real numbers from usage

Every response reports what you were billed for. With caching on, input_tokens counts only the tokens after the last cache breakpoint. Total input is cache_read_input_tokens + cache_creation_input_tokens + input_tokens. A meter that estimates from the new message misses almost all of it.

Python chat.py
def ask(text):    history.append({"role": "user", "content": text})    reply = client.messages.create(        model="claude-opus-5-5", max_tokens=16000,        system=SYSTEM, messages=history,    )    history.append({"role": "assistant", "content": reply.content})    new_tokens = len(text) // 4  # only the new message: the bill disagrees    meter.add_usd((new_tokens * 4.00 + reply.usage.output_tokens * 20.00) / 1e6)    return replyask("Why does the CSV export fail with E413?")
MythReality
A turn costs the new message plus the replyIt costs everything sent: system prompt, tools, all history, plus the reply
Cost grows with the number of messagesPer-turn input grows linearly, so session cost grows quadratically
Hidden thinking is freeIt's billed as output, and on keep-all models as input on later turns
Message threads mean you stop paying for historyThreads make requests smaller; they don't change pricing
Caching shrinks the contextIt makes repeated input cheaper; the model still reads all of it

How to apply it in your project

  1. Log usage per turnRecord all four usage fields with the conversation ID and turn number. Chart cost by turn, not just per day, and the long sessions show up.
  2. Turn on caching and keep the prefix stableAdd a top-level cache_control, put fixed content first and volatile content last, and check cache_read_input_tokens in your logs.
  3. Resend lessTrim tool results to the fields the model needs and summarize or drop old turns. The Building with LLMs path returns to this in its context engineering article.
  4. Budget sessions, not messagesSet a token or dollar ceiling per conversation and decide what happens when it's reached: summarize, start fresh or hand off.
  5. Move offline work to batchesFor jobs nobody waits on, the Batch API halves the price: $2 input and $10 output per million tokens on Claude Opus 5.5.

Key takeaways

  • Every request bills the full context again: system prompt, tool definitions, all earlier turns and their tool results.
  • Per-turn cost grows linearly, so a long session costs far more than a per-message estimate.
  • Thinking is billed as output, and on recent models earlier thinking is billed again as input.
  • Prompt caching makes the repeated prefix much cheaper, but it can't reduce output or what the model has to read.
  • Measure with the usage fields and count tokens before sending, then optimize what the numbers show.

📚 المصادر

  1. Using the Messages API: multiple conversational turns — Claude API Docs
  2. Pricing — Claude API Docs
  3. Prompt caching — Claude API Docs
  4. Token counting — Claude API Docs
  5. Thinking — Claude API Docs

التعليقات (0)