Skip to content
GenAI Figure

Technology UpdateAI & LLMs

Server-side conversation state: message threads in the Claude API

Message threads let the Claude API keep a conversation for a few minutes, so each agent turn sends only the new messages. How create, continue and replay work, what you must still keep yourself, and a runnable size comparison.

By Sritharan K (opens in a new tab)

Published Updated 9 min read

ConceptualThis article explains a concept. It reports no measured results.

Cover card for the article Server-side conversation state: message threads in the Claude API

The Messages API is stateless. An agent that has run forty tool calls sends the system prompt, every tool schema and all eighty earlier messages again on turn forty-one, and the API validates and tokenizes all of it again before the model starts. The request grows with every turn, and so does the work before the first token.

Message threads, in beta since 2 November 2026, change that. You send the full conversation once. After that, each request carries only the new messages and the id of the previous response, and the API rebuilds the conversation on its side. In the ten-turn example below, the request body stays at about 3 kB per turn after the first, except for one replay, instead of growing to 33 kB.

Read the figure from top to bottom: one request without a thread, the four requests of a thread that expires once, and the request size per turn from the example.

Without a thread, turn 10 resends system, tools and 18 earlier messages. With a thread: create, continue, a continue that gets 404 thread_not_found after six idle minutes, then a replay. Bars over ten turns: up to 33 kB without a thread, about 3 kB with one, a 24 kB replay at turn 7.
Request payloads without and with a message thread. The sizes come from the synthetic agent loop in the example, measured in bytes of JSON; they are not token counts or latency measurements.

What message threads are#

A message thread keeps a conversation on Anthropic's servers for a short time. It is a parameter on the ordinary Messages API, thread, plus the beta header message-threads-2026-08-12. The response is the usual message.

Facts from the documentation and the release notes, as of 28 November 2026:

  • Status: beta, announced in the release notes of 2 November 2026.
  • Models: all models.
  • Platforms: the Claude API, Claude Platform on AWS, Claude Models on Google Cloud (Anthropic managed) and Claude in Microsoft Foundry.
  • Lifetime: a thread expires 5 minutes after its last request. Each response the API stores restarts those 5 minutes. The API deletes the thread no more than 1 hour after its last use.
  • Price: threads do not change pricing or rate limits.
  • Data handling: not eligible for zero data retention (ZDR) and not HIPAA eligible. The thread is held in memory, encrypted under a server-managed key, and never written to durable storage.

The documentation names the benefit as smaller requests and a time to first token that stays lower and steadier as the conversation grows. That is the vendor's claim; I have not measured it.

How a thread works#

There are three moves:

  1. Create. Send the first request as you do today, with system, tools and messages, and add "thread": {"type": "create"}. The API stores the conversation, including the reply, under the response id.
  2. Continue. Send only the messages since the previous response, with "thread": {"type": "continue", "previous_message_id": "<id>"}. Leave system and tools out; sending either one, even as null, returns a 400 error.
  3. Replay. A thread is best effort. When the API cannot continue it, a continue request returns 404 with error.details.error_code set to thread_not_found. Check that code before you replay, because a request for a model that does not exist also returns 404. You send the full conversation again in a new create request and continue from the new response id.

The rules that catch people:

  • Fixed fields. model, tool_choice, thinking, output_config, the top-level cache_control, the set of beta headers and a few others go on every request of the thread, with the same value as on the create request. A different value returns 400 thread_fingerprint_mismatch. To change one, start a new thread.
  • Append only. Each response id can be continued once. To edit or branch an earlier message, or to compact the history into a summary, start a new thread.
  • Streaming. The response id arrives in message_start, but continue only after message_stop. If a stream drops, send the same continue request again, and replay if that returns thread_already_continued or thread_continue_in_flight.
  • Caching is separate. A thread does not cache your prompt. Add a top-level cache_control on every request if you want each turn cached.

The API rebuilds the full conversation before it calls the model. In my reading, a thread therefore saves upload, validation and tokenization, not input tokens: the model still reads the whole conversation, and prompt caching is what lowers that cost.

Where it helps, and where it does not#

Useful:

  • Long agent loops. The documentation names them as the case where threads help most. Tool calls and tool results follow each other within seconds, well inside the 5 minutes, and each turn adds a small delta to a large history.
  • Large tool sets and long system prompts. They are sent once per thread instead of once per turn.
  • Clients on slow links. In my reading, a request that stays near the size of one turn uploads faster than one that grows with the history.

Not useful, or with care:

  • Short exchanges. A two-turn call gains almost nothing, and the create request is slightly larger than the plain one.
  • Human-paced chat. If a user often pauses for more than 5 minutes, many turns become replays and you are back to sending everything.
  • Regulated data. Threads are not ZDR eligible, so keep ZDR workloads off them. Organizations with HIPAA readiness enabled cannot use them at all.
  • Message Batches, token counting and on-demand compaction. These do not support threads. Count tokens on the full conversation instead.

Example: request sizes over ten turns#

The script below builds the request bodies of a ten-turn agent loop in both modes and prints their size. It sends nothing and needs no API key. The model replies are stubs: one tool call per turn, then a tool result of about 2.4 kB from the client. At turn 7 it pretends the thread expired and replays. The system prompt, eight tool schemas and the tool results are synthetic text, chosen only to make the growth visible.

I ran it with Python 3.12.14 and the standard library only.

thread_payloads.pypython
"""Request bodies of a ten-turn agent loop, without and with a message thread.

Builds the JSON bodies only. Nothing is sent, so no API key is needed.
"""
import json

MODEL = "claude-opus-5-5"
SYSTEM = "You are an order support agent. Follow the refund policy. " * 40
TOOLS = [{"name": f"tool_{i}", "description": "Look up order data. " * 10,
          "input_schema": {"type": "object",
                           "properties": {"order_id": {"type": "string"}}}}
         for i in range(8)]
TOOL_RESULT = json.dumps([{"order": f"A-{n}", "status": "shipped"} for n in range(60)])


def size(body):
    return len(json.dumps(body).encode())


def reply(turn):
    """Stands in for the model: an id and one tool call per turn."""
    return {"id": f"msg_{turn:02d}", "role": "assistant", "content": [
        {"type": "tool_use", "id": f"toolu_{turn:02d}", "name": "tool_0",
         "input": {"order_id": f"A-{turn}"}}]}


def new_messages(turn):
    """What the client adds before a turn: the question, then tool results."""
    if turn == 1:
        return [{"role": "user", "content": "Why was my refund for A-1042 refused?"}]
    return [{"role": "user", "content": [{"type": "tool_result",
             "tool_use_id": f"toolu_{turn - 1:02d}", "content": TOOL_RESULT}]}]


def create(messages):
    return {"model": MODEL, "max_tokens": 1024, "system": SYSTEM, "tools": TOOLS,
            "messages": messages, "thread": {"type": "create"}}


def continue_(new, previous_id):
    return {"model": MODEL, "max_tokens": 1024, "messages": new,
            "thread": {"type": "continue", "previous_message_id": previous_id}}


history, previous_id = [], None  # the client keeps its own full copy
totals = [0, 0]
print("turn  stateless  threaded  thread request")
for turn in range(1, 11):
    new = new_messages(turn)
    history += new
    stateless = {"model": MODEL, "max_tokens": 1024, "system": SYSTEM,
                 "tools": TOOLS, "messages": history}
    if previous_id is None:
        body, kind = create(history), "create"
    elif turn == 7:  # pretend the thread expired: 404 thread_not_found
        body, kind = create(history), "replay (create)"
    else:
        body, kind = continue_(new, previous_id), "continue"
    print(f"{turn:>4}  {size(stateless):>9,}  {size(body):>8,}  {kind}")
    totals[0] += size(stateless)
    totals[1] += size(body)
    answer = reply(turn)
    history.append({"role": "assistant", "content": answer["content"]})
    previous_id = answer["id"]
print(f"total {totals[0]:>9,}  {totals[1]:>8,}  bytes")

The output, from a run on 28 November 2026:

text
turn  stateless  threaded  thread request
   1      5,061     5,091  create
   2      8,153     3,095  continue
   3     11,245     3,095  continue
   4     14,337     3,095  continue
   5     17,429     3,095  continue
   6     20,521     3,095  continue
   7     23,613    23,643  replay (create)
   8     26,705     3,095  continue
   9     29,797     3,095  continue
  10     32,889     3,095  continue
total   189,750    53,494  bytes

Three things to notice:

  • The create request costs a little more. The thread field adds 30 bytes on turn 1.
  • A replay costs a full turn. At turn 7 the body is as large as the stateless one. In a real client it also follows a failed continue request; that request is rejected before the model runs and uses no tokens.
  • The client still keeps everything. history holds the full conversation in both modes. Without it there is nothing to replay.

On the wire, a continue request with a follow-up question looks like this. A plain user message is only valid after a reply that ended in text; after a tool call, the new message carries the tool_result blocks. The headers and fields follow the official documentation; I did not send it, because it needs an API key:

bash
curl -sS --fail-with-body https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2026-10-21" \
  -H "anthropic-beta: message-threads-2026-08-12" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-opus-5-5",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "And the refund for A-1043?"}],
    "thread": {"type": "continue", "previous_message_id": "'"$previous_id"'"}
  }'

The SDKs also have a thread helper that creates, continues and replays on thread_not_found for you, and the beta tool runner uses a thread by default.

Pros, cons and limits#

AspectDetails
ProsRequests stay near the size of one turn. System and tools are sent once per thread. No new endpoint: one field and one beta header on the Messages API. No price change.
ConsBeta. Expires after 5 idle minutes, so you must build and test the replay path. Fixed fields lock model, thinking and tool choice for the life of the thread.
LimitsNo API to list, read or delete a thread. Not available with Message Batches, token counting, on-demand compaction, most context editing, HIPAA readiness or inference hooks. At most 4 cache_control breakpoints per request.
State and dataYour application stays the source of truth: no response says whether the turn was stored. Not ZDR eligible. Files are held by reference, so keep them available while the thread is in use.
Lock-inThe thread parameter is specific to this API. Code that keeps its own history, as it must anyway, can drop the field and fall back to stateless requests.

When to use it#

Use it for agent loops with many fast turns, large tool sets or long system prompts, where request size and time to first token grow with the history. Keep your own copy of the conversation, write the replay path first, and turn on prompt caching alongside it, because a thread does not cache the prompt and does not change pricing.

Skip it for short calls, for conversations with long human pauses, and for any workload that needs ZDR.

Next step: read the message threads documentation (opens in a new tab), in particular the table of fields to send on each request and the error codes, then add the thread field behind a flag and compare request size and time to first token on your own agent traces.

References

  1. Message threads (opens in a new tab). Anthropic.
  2. Claude Platform release notes (2 November 2026) (opens in a new tab). Anthropic, 2026-11-02.
  3. Prompt caching (opens in a new tab). Anthropic.