Follow Discord
Sweep 20 Nov 2026 · 19:55Z Build v2.1.330 547 read Stable v2.1.323 Latest v2.1.330 Next v2.1.330 Feeds RSS JSON llms.txt llms-full.txt Unofficial
One change · api

message-threads changedbuild-with-claude/message-threads

Nearest release: v2.1.324, published 2 hours after this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.

Recorded here
Lines+42added
Lines−42removed
From line 37 where the diff opens
First seen 2 Nov 2026 this site's first read of the page
Recorded edits9to this page, all time

## Use a thread with the SDK ## Use a thread with an SDK

The whole hunk

from line 37, old and new numbered
/
lines
from line 37
3737 
3838With a message thread, requests are smaller, and time to first token stays lower and steadier as the conversation grows. Threads help most in long agent loops. Without a thread, every turn uploads the whole conversation again, and the API validates and tokenizes all of it again. With a thread, most of that work covers only the new turn.
3939 
40A message thread keeps a conversation on the server for a short time. You send the full conversation once, with your system prompt and tools. On each later turn, you send only the new messages and the `id` of the previous response. The API rebuilds the conversation before it calls the model. You add one parameter, `thread`, to a [Messages API](https://platform.claude.com/docs/en/api/messages) request. The response is the usual message.
40A message thread keeps a conversation on the server for a short time. You send the full conversation, your system prompt, and your tools once. On each later turn, you send the new messages and the `id` of the previous response instead of the full conversation. The API rebuilds the conversation before it calls the model. You add the [`thread`](https://platform.claude.com/docs/en/api/beta/messages/create#create.thread) parameter and a beta header to a Messages API request. The response is the usual message.
4141 
4242<Note>
4343 Message threads are different from [session threads](https://platform.claude.com/docs/en/managed-agents/session-threads) in Claude Managed Agents.
from line 45
4545 
4646## How message threads work
4747 
48* **Create.** Send your first request as you do today, with the full conversation, `system`, and `tools`, and add `"thread": {"type": "create"}`. The API stores the conversation, including Claude’s reply, under the response `id`.
49* **Continue.** Send only the messages since the previous response, and add `"thread": {"type": "continue", "previous_message_id": "<previous id>"}`. Leave `system` and `tools` out of the request. The thread keeps the values from the create request. Use each new response `id` for the next turn.
50* **Replay.** A thread is best-effort. It expires 5 minutes after its last request, and the API deletes it no more than 1 hour after its last use. Each response that the API stores restarts the 5 minutes. If the API can no longer continue the thread, a continue request returns a 404 error. Send the full conversation again in a new create request, and continue from that response’s `id`. The SDK thread helper does this replay for you (see [How the SDK helper behaves](https://platform.claude.com/docs/en/build-with-claude/message-threads#sdk-helper-handles)). After a response from a fallback model, see [Use fallbacks with a thread](https://platform.claude.com/docs/en/build-with-claude/message-threads#fallbacks).
48* **Create.** Send your first request as you do today, with the full conversation, `system`, and `tools`. Add `"thread": {"type": "create"}` to the request. The API stores the conversation, including Claude’s reply, under the response `id`.
49* **Continue.** Send only the messages since the previous response and add `"thread": {"type": "continue", "previous_message_id": "<previous id>"}`. Leave `system` and `tools` out of the request. The thread keeps the values from the create request. Use each new response `id` for the next turn.
50* **Replay.** A thread is best-effort. It expires 5 minutes after its last request, and the API deletes it no more than 1 hour after its last use. Each response that the API stores restarts the 5 minutes. If the API can no longer continue the thread, a continue request returns a 404 error. Send the full conversation again in a new create request and continue from the new response `id`. The SDK thread helper does this replay for you (see [How the SDK helper behaves](https://platform.claude.com/docs/en/build-with-claude/message-threads#sdk-helper-handles)). After a response from a fallback model, see [Use fallbacks with a thread](https://platform.claude.com/docs/en/build-with-claude/message-threads#fallbacks).
5151 
52Your application stays the source of truth for the conversation. Keep your own copy of every message, and build the [replay path](https://platform.claude.com/docs/en/build-with-claude/message-threads#recover) from the start. No response, to a create or a continue request, says whether the API stored that turn. You find out on the next continue request. The SDK thread helper keeps this copy in memory while the helper object exists, and saves it nowhere else. If the conversation has to outlive your process, keep your own copy.
52Your application stays the source of truth for the conversation. Keep your own copy of every message and build the [replay path](https://platform.claude.com/docs/en/build-with-claude/message-threads#recover) from the start. No response to a create or a continue request says whether the API stored that turn. You find out on the next continue request. The SDK thread helper keeps this copy in memory while the helper object exists, and it saves the copy nowhere else. If the conversation has to outlive your process, keep your own copy.
5353 
54## Use a thread with an SDK
54## Use a thread with the SDK
5555 
56The SDK has a thread helper that builds the thread requests for you. Create it with the same fields as a Messages request, then send it one turn at a time. The helper keeps the full conversation in memory.
56The SDK has a thread helper that builds each request for you. Create the helper with the same fields as a Messages request. Then send one turn at a time. The helper keeps the full conversation in memory.
5757 
5858This example has two turns. The helper creates a thread on the first turn and continues it on the second, and it adds the beta header for you. The top-level `cache_control` is optional. It asks for prompt caching on each turn (see [Prompt caching on a thread](https://platform.claude.com/docs/en/build-with-claude/message-threads#prompt-caching)). Without it, each later turn still sends only the new messages, but nothing is cached unless you add cache breakpoints yourself.
5959 
from line 217
217217 $thread = $client->beta->messages->thread(
218218 maxTokens: 1024,
219219 model: Model::CLAUDE_OPUS_5_5,
220 cacheControl: new BetaCacheControlEphemeral,
220 cacheControl: new BetaCacheControlEphemeral(),
221221 system: 'You are a support agent for Acme. Keep replies short.',
222222 );
223223 
from line 239
239239 
240240 # Create the helper. This call sends no request.
241241 thread = client.beta.messages.thread(
242 model: :"claude-opus-5-5",
242 model: Anthropic::Model::CLAUDE_OPUS_5_5,
243243 max_tokens: 1024,
244244 cache_control: {type: "ephemeral"},
245245 system_: "You are a support agent for Acme. Keep replies short."
from line 259
259259 
260260## Send the `thread` field yourself
261261 
262To build thread requests yourself, for example with cURL, the CLI, or an SDK’s usual `create` method, add the `thread` field to each request.
262Add the `thread` field to each request yourself. You can do this with cURL, with the CLI, or with an ordinary SDK request.
263263 
264264Send the `message-threads-2026-08-12` beta header on every request of a thread.
265265 
266This example creates a thread on the first turn and continues it on the second. The top-level `cache_control` asks for prompt caching on each turn. It takes effect once the conversation is longer than the [minimum cacheable length](https://platform.claude.com/docs/en/build-with-claude/prompt-caching).
266This example creates a thread on the first turn and continues it on the second. The top-level `cache_control` asks for prompt caching on each turn. Nothing is cached until the full conversation, together with `system` and `tools`, reaches the [minimum cacheable length](https://platform.claude.com/docs/en/build-with-claude/prompt-caching#cache-limitations).
267267 
268268<CodeGroup>
269269 ```bash cURL
from line 526
526526 $first = $client->beta->messages->create(
527527 model: Model::CLAUDE_OPUS_5_5,
528528 maxTokens: 1024,
529 cacheControl: new BetaCacheControlEphemeral,
529 cacheControl: new BetaCacheControlEphemeral(),
530530 system: 'You are a support agent for Acme. Keep replies short.',
531531 messages: [
532532 ['role' => 'user', 'content' => 'Hi! I have a question about an order.'],
from line 540
540540 $second = $client->beta->messages->create(
541541 model: Model::CLAUDE_OPUS_5_5,
542542 maxTokens: 1024,
543 cacheControl: new BetaCacheControlEphemeral,
543 cacheControl: new BetaCacheControlEphemeral(),
544544 messages: [
545545 ['role' => 'user', 'content' => 'How long does standard shipping usually take?'],
546546 ],
from line 560
560560 
561561 # Turn 1: send the full conversation and create a thread
562562 first = client.beta.messages.create(
563 model: :"claude-opus-5-5",
563 model: Anthropic::Model::CLAUDE_OPUS_5_5,
564564 max_tokens: 1024,
565565 cache_control: {type: "ephemeral"},
566566 system_: "You are a support agent for Acme. Keep replies short.",
from line 572
572572 # Turn 2: send only the new message and the id of the turn 1 response.
573573 # Leave out system_ and tools: the thread keeps them.
574574 second = client.beta.messages.create(
575 model: :"claude-opus-5-5",
575 model: Anthropic::Model::CLAUDE_OPUS_5_5,
576576 max_tokens: 1024,
577577 cache_control: {type: "ephemeral"},
578578 messages: [{role: "user", content: "How long does standard shipping usually take?"}],
from line 609
609609 
610610Send only the new messages on a continue request. The API doesn’t check them against the messages it already has. A message you send again can appear twice in the conversation, or the request can return an error. For example, a continue request that starts with the previous response returns an error.
611611 
612The new messages usually start with a `user` message: your next user turn, or the `tool_result` blocks that answer a `tool_use` in the previous response. If a response stops with [`stop_reason: "pause_turn"`](https://platform.claude.com/docs/en/build-with-claude/handling-stop-reasons#pause-turn), resume it with a continue request from that response’s `id` and an empty `messages` list (`"messages": []`). If that request returns a 404 error, replay the full conversation, including the paused response, in a new create request. Don’t send a new `user` message while the turn is paused: the API rejects it. With the SDK thread helper, call `send()` (go, csharp: `Send()`; ruby: `send_message()`) with no messages: the helper sends this request and replays on a 404 error.
612The new messages usually start with a `user` message: your next user turn or the `tool_result` blocks that answer a `tool_use` in the previous response. If a response stops with [`stop_reason: "pause_turn"`](https://platform.claude.com/docs/en/build-with-claude/handling-stop-reasons#pause-turn), resume it with a continue request from that response’s `id` and an empty `messages` list (`"messages": []`). If that request returns a 404 error, replay the full conversation, including the paused response, in a new create request. Don’t send a new `user` message while the turn is paused: the API rejects it. With the SDK thread helper, call `send()` (go, csharp: `Send()`; ruby: `send_message()`) with no messages: the helper sends this request and replays on a 404 error.
613613 
614614A thread is append-only, and each response `id` can be continued once. Always continue from the latest response `id` of the thread. To edit or branch an earlier message, start a new thread with a create request. To replace earlier turns with a summary, see [Compact a conversation](https://platform.claude.com/docs/en/build-with-claude/message-threads#compaction).
615615 
from line 617
617617 
618618A thread does not cache your prompt for you. [Prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) works as it does without a thread: you choose where the cache breakpoints go.
619619 
620To cache each turn, send a top-level `cache_control` on every request of the thread, as in the earlier example. The API applies it to the last block of each request’s `messages` that can be cached. Each turn then reads the earlier conversation from the cache and writes the new turn to it. The top-level `cache_control` is a fixed field: send the same value on every request.
620To cache each turn, send a top-level `cache_control` on every request of the thread as in the earlier example. The API applies it to the last block of each request’s `messages` that can be cached. Each turn then reads the earlier conversation from the cache and writes the new turn to it. The top-level `cache_control` is a fixed field: send the same value on every request.
621621 
622622You can also place `cache_control` breakpoints on blocks yourself:
623623 
from line 624
624624* Breakpoints that you send on the create request keep working on every later turn if they are on `tools`, on `system`, or on a message block before the last one. A breakpoint on the last block of a request’s `messages` writes the cache on that request. To cache each new turn, send a breakpoint on every request. A request without a breakpoint might still read part of the conversation from the cache.
625625* You can’t move or remove a breakpoint after you send it, because a continue request can’t send an earlier message again.
626626* A request with `thread` can carry at most 4 `cache_control` breakpoints. The top-level `cache_control` counts as one. Breakpoints on the `system` and `tools` of the create request count again on every continue request. Breakpoints on earlier stored messages do not count. One breakpoint too many returns a 400 error with the code `thread_unsupported_request`.
627* If you place breakpoints on message blocks yourself, remove them from earlier messages when you replay the conversation in a new create request, and keep one on the last block, so the request stays within the limit of 4.
627* If you place breakpoints on message blocks yourself, remove them from earlier messages and keep one on the last block when you replay the conversation in a new create request. The request then stays within the limit of 4.
628628 
629629## Streaming
630630 
from line 632
632632 
633633If the stream of a continue request drops before `message_stop`, send the same continue request again. If that request returns a `thread_already_continued` or `thread_continue_in_flight` error, replay the full conversation in a new create request.
634634 
635Your connection might have dropped while the server was still generating the response, or after the server saved it. That is why the API can reject the retry. Replaying your exact copy is safe.
635Your connection might have dropped while the server was still generating the response or after the server saved it. That is why the API can reject the retry. Replaying your exact copy is safe.
636636 
637637The SDK thread helper doesn’t retry the continue request after a dropped stream. See [How the SDK helper behaves](https://platform.claude.com/docs/en/build-with-claude/message-threads#sdk-helper-handles).
638638 
from line 648
648648* The request comes from a different user or service account from the one that created the thread. A thread created with a [workspace key (legacy)](https://platform.claude.com/docs/en/manage-claude/authentication#key-types) stays with that key, so use the same key for the whole thread.
649649* The new messages add something that the stored conversation can’t take. For example, the first image in a conversation that had none can return this error.
650650 
651To recover, send the full conversation from your own copy in a new create request, with `system` and `tools`. The SDK thread helper sends this create request once by itself, and leaves out the `cache_control` breakpoints of earlier turns when it does. If earlier messages in your copy carry `cache_control` breakpoints, remove them first (see [Prompt caching on a thread](https://platform.claude.com/docs/en/build-with-claude/message-threads#prompt-caching)). Then continue from the new response `id`. If a fallback model wrote the previous response, see [Use fallbacks with a thread](https://platform.claude.com/docs/en/build-with-claude/message-threads#fallbacks). To rule out the ownership causes, use the same API key and workspace for every request of a thread. On Claude Platform on AWS, sign every request of a thread with credentials for the IAM role or IAM user that created it.
651To recover, send the full conversation from your own copy in a new create request with `system` and `tools`. The SDK thread helper sends this create request once by itself and leaves out the `cache_control` breakpoints of earlier turns when it does. If earlier messages in your copy carry `cache_control` breakpoints, remove them first (see [Prompt caching on a thread](https://platform.claude.com/docs/en/build-with-claude/message-threads#prompt-caching)). Then continue from the new response `id`. If a fallback model wrote the previous response, see [Use fallbacks with a thread](https://platform.claude.com/docs/en/build-with-claude/message-threads#fallbacks). To rule out the ownership causes, use the same API key and workspace for every request of a thread. On Claude Platform on AWS, sign every request of a thread with credentials for the IAM role or IAM user that created the thread.
652652 
653653A request for a model that does not exist also returns a 404 error, so check `error.details.error_code` before you replay.
654654 
655If a continue request still returns a 404 error right after you replay, the API might be unable to store that conversation, for example a very large one. Send it without `thread`. The SDK thread helper does this when you create it with `unsupported_request_behavior` (typescript, java, php: `unsupportedRequestBehavior`; go, csharp: `UnsupportedRequestBehavior`) set to `continue_unthreaded` (ruby: `:continue_unthreaded`; java: `CONTINUE_UNTHREADED`; csharp: `ContinueUnthreaded`; go: `BetaMessageThreadUnsupportedRequestBehaviorContinueUnthreaded`). Otherwise it replays on every turn.
655If a continue request still returns a 404 error right after you replay, the API might be unable to store that conversation (for example, a very large one). Send it without `thread`. The SDK thread helper does this when you create it with `unsupported_request_behavior` (typescript, java, php: `unsupportedRequestBehavior`; go, csharp: `UnsupportedRequestBehavior`) set to `continue_unthreaded` (ruby: `:continue_unthreaded`; java: `CONTINUE_UNTHREADED`; csharp: `ContinueUnthreaded`; go: `BetaMessageThreadUnsupportedRequestBehaviorContinueUnthreaded`). Otherwise, the helper replays on every turn.
656656 
657657### After a refusal
658658 
from line 660
660660 
661661### Use fallbacks with a thread
662662 
663[Server-side fallback](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#server-side-fallback) is available with threads on the Claude API. Decide when you create the thread: send `fallbacks` on every request of the thread, or on none. The value of `fallbacks` can change between requests. A continue request that adds or drops `fallbacks` returns a 400 error with the code `thread_fingerprint_mismatch`.
663[Server-side fallback](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#server-side-fallback) is available with threads on the Claude API. Decide when you create the thread: send `fallbacks` on every request of the thread or on none. The value of `fallbacks` can change between requests. A continue request that adds or drops `fallbacks` returns a 400 error with the code `thread_fingerprint_mismatch`.
664664 
665665A thread keeps one model, so the API doesn’t store a turn that a fallback model wrote. You get the response as usual, but you can’t continue from its `id`. After each response, follow these steps:
666666 
from line 675
675675 
6766764. Go back to step 1 with the response to that request. When it has no `fallback_message` entry, continue the new thread from its `id`.
677677 
678[Sticky routing](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#sticky-routing) starts after a request falls back (a create request, or a request without `thread`). For about an hour, it might send later create requests for the same conversation that include `fallbacks` straight to the fallback model, without trying the model you requested. The API stores none of those turns, and each answered one restarts the hour. A continue request never starts this routing and never uses it. Sticky routing doesn’t apply if your organization or workspace uses zero data retention or customer-managed encryption keys.
678[Sticky routing](https://platform.claude.com/docs/en/build-with-claude/refusals-and-fallback#sticky-routing) starts after a request falls back (a create request or a request without `thread`). For about an hour, it might send later create requests for the same conversation that include `fallbacks` straight to the fallback model without trying the model you requested. The API stores none of those turns, and each answered one restarts the hour. A continue request never starts this routing and never uses it. Sticky routing doesn’t apply if your organization or workspace uses zero data retention or customer-managed encryption keys.
679679 
680680## Compact a conversation
681681 
682A thread is append-only, so you can’t replace its earlier turns with a summary. To compact a conversation, start a new thread from the summary. Write the summary in your code, and send it as an ordinary message in a new create request, with `system` and `tools`. [Compaction on demand](https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand) is not available with threads (see [Features that threads don’t support](https://platform.claude.com/docs/en/build-with-claude/message-threads#unsupported)).
682A thread is append-only, so you can’t replace its earlier turns with a summary. To compact a conversation, start a new thread from the summary. Write the summary in your code and send it as an ordinary message in a new create request with `system` and `tools`. [Compaction on demand](https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand) is not available with threads (see [Features that threads don’t support](https://platform.claude.com/docs/en/build-with-claude/message-threads#unsupported)).
683683 
684684## How the SDK helper behaves
685685 
from line 689
689689* Creates a thread on the first turn and continues it after that, sending only the new messages and leaving out `system` and `tools`.
690690* Replays the full conversation once in a new create request when a continue request returns `thread_not_found`, `thread_already_continued`, or `thread_continue_in_flight`.
691691* Resumes a `pause_turn` response when you call `send()` (go, csharp: `Send()`; ruby: `send_message()`) with no messages.
692* Starts a new thread after a refusal. You get the `stop_reason: "refusal"` response as usual, but the helper doesn’t keep that turn: it takes back the messages you gave to that call. Messages that you added with `thread.append(...)` (csharp, go: `thread.Append(...)`; php: `$thread->append(...)`), or gave when you created the helper, stay staged. Your next turn sends them with the conversation from before the refused turn, in a new create request. Send a rephrased message, or, if a staged message led to the refusal, start a new thread from the params without it.
692* Starts a new thread after a refusal. You get the `stop_reason: "refusal"` response as usual, but the helper doesn’t keep that turn: it takes back the messages you gave to that call. Messages that you added with `thread.append(...)` (csharp, go: `thread.Append(...)`; php: `$thread->append(...)`) or gave when you created the helper stay staged. Your next turn sends them in a new create request with the conversation from before the refused turn. Send a rephrased message or, if a staged message led to the refusal, start a new thread from the params without that message.
693693* Sends a new create request after a response from a fallback model. When a response has a `fallback_message` entry in `usage.iterations`, the helper keeps the response and sends the full conversation in a new create request on the next turn. It doesn’t wait for a 404 error. That request keeps the `model` and `fallbacks` that you set.
694* Leaves out the `cache_control` breakpoints of earlier turns whenever it sends them again, for example in a replay or in the first turn of a fork. Your newest messages, `system`, `tools`, and the top-level `cache_control` go out as you gave them.
694* Leaves out the `cache_control` breakpoints of earlier turns whenever it sends those turns again (for example, in a replay or in the first turn of a fork). Your newest messages, `system`, `tools`, and the top-level `cache_control` go out as you gave them.
695695 
696696What you handle yourself:
697697 
698* **Fallbacks.** While the API keeps answering from a fallback model, the helper sends the full conversation in a new create request on every turn, because the API stores none of those turns. It goes back to continue requests after a response from the model that you requested. To move the conversation to the fallback model instead, start a new thread from the params with that `model` and without `fallbacks`, as in [Use fallbacks with a thread](https://platform.claude.com/docs/en/build-with-claude/message-threads#fallbacks).
698* **Fallbacks.** While the API keeps answering from a fallback model, the helper sends the full conversation in a new create request on every turn because the API stores none of those turns. The helper goes back to continue requests after a response from the model that you requested. To move the conversation to the fallback model instead, start a new thread from the params with that `model` and without `fallbacks` as in [Use fallbacks with a thread](https://platform.claude.com/docs/en/build-with-claude/message-threads#fallbacks).
699699* **Dropped streams.** If a stream ends partway through a response, the helper keeps the finished blocks and any text that arrived, and the next turn sends the full conversation in a new create request. The helper doesn’t retry by itself: to re-send the interrupted turn instead, call `send()` (go, csharp: `Send()`; ruby: `send_message()`) with no messages. If the kept part ends in tool calls, answer them in your next message. If you stop reading a stream after it shows `stop_reason: "refusal"`, the helper treats that turn as a refusal.
700700* **Other errors.** `thread_fingerprint_mismatch` and `thread_unsupported_request` errors reach your code. To carry on without `thread` after a `thread_unsupported_request` error, create the helper with `unsupported_request_behavior` (typescript, java, php: `unsupportedRequestBehavior`; go, csharp: `UnsupportedRequestBehavior`) set to `continue_unthreaded` (ruby: `:continue_unthreaded`; java: `CONTINUE_UNTHREADED`; csharp: `ContinueUnthreaded`; go: `BetaMessageThreadUnsupportedRequestBehaviorContinueUnthreaded`). With that setting, the helper also stops using `thread` when the first continue request after a replay returns `thread_not_found` again. The API might be unable to store that conversation. Without that setting, the helper replays on every turn. A tool runner that creates its own thread uses that setting by default.
701701 
702The SDK’s beta tool runner also uses a thread by default, which you can turn off when you create the runner.
702The SDK’s beta tool runner also uses a thread by default. You can turn off this default when you create the runner.
703703 
704704### Other helper methods
705705 
from line 712
712712| Add messages without sending | `thread.append(...)` (csharp, go: `thread.Append(...)`; php: `$thread->append(...)`) |
713713| Change fields for later turns | `thread.update(...)` (csharp: `thread.Update(p => p with { ... })`; go: `thread.Params.MaxTokens = ...`; java: `thread.update(b -> ...)`; php: `$thread->update([...])`) |
714714| Copy the thread | `thread.fork()` (csharp, go: `thread.Fork()`; php: `$thread->fork()`; ruby: `thread.fork`) |
715| Fields and conversation, to start a new thread | `thread.params` (csharp, go: `thread.Params`; java: `thread.params()`; php: `$thread->params()`) |
715| Fields and conversation to start a new thread | `thread.params` (csharp, go: `thread.Params`; java: `thread.params()`; php: `$thread->params()`) |
716716| Tool runner on this thread | `thread.tool_runner()` (typescript, java: `thread.toolRunner()`; csharp: `thread.ToolRunner(tools)`; go: `thread.NewToolRunner(tools)`; php: `$thread->toolRunner()`; ruby: `thread.tool_runner`) |
717717| Tool runner without a thread | `tool_runner(..., thread=False)` (typescript: `toolRunner({ ..., thread: false })`; csharp: `ToolRunner(parameters, tools, thread: false)`; go: `BetaToolRunnerParams{DisableThread: true}`; java: `ToolRunnerCreateParams.builder().thread(false)`; php: `toolRunner(..., thread: false)`; ruby: `tool_runner(..., thread: false)`) |
718718 
from line 727
727727 
728728In C#, the request goes out when you start to read the stream.
729729 
730In C#, Go, Java, and PHP, after a refusal `thread.LastMessage` (go: `thread.LastMessage()`; java: `thread.lastMessage()`; php: `$thread->lastMessage()`) still returns the previous turn’s response, or nothing on a first turn. Read the refusal from the stream’s events.
730In C#, Go, Java, and PHP, after a refusal, `thread.LastMessage` (go: `thread.LastMessage()`; java: `thread.lastMessage()`; php: `$thread->lastMessage()`) still returns the previous turn’s response or nothing on a first turn. Read the refusal from the stream’s events.
731731 
732732**Changing fields.** An update sends nothing and applies to every later turn. Once a thread has a response, the helper refuses a turn that changes `system` or `tools`, and the API rejects a change to any other fixed field (see [What to send on each request](https://platform.claude.com/docs/en/build-with-claude/message-threads#what-to-send)). To change one of these fields, start a new thread from the params, or fork the thread and update the fork before its first turn.
733733 
734**Forking.** A fork copies the conversation, the fields, and the request options, and sends nothing. Its first turn sends the full conversation in a new create request, and the two threads are independent after that. A fork always starts from the whole conversation, not from an earlier response.
734**Forking.** A fork copies the conversation, the fields, and the request options, and it sends nothing. Its first turn sends the full conversation in a new create request, and the two threads are independent after that. A fork always starts from the whole conversation, not from an earlier response.
735735 
736**Params.** The params hold the helper’s fields and the full conversation. Pass them to the method that creates a helper to start a new thread, for example with a different `system` (see [What to send on each request](https://platform.claude.com/docs/en/build-with-claude/message-threads#what-to-send)), or with `messages` cut back to drop later turns. A thread that you start from the params sends every message as you gave it, `cache_control` breakpoints included, so keep within the limit of 4 (see [Prompt caching on a thread](https://platform.claude.com/docs/en/build-with-claude/message-threads#prompt-caching)). Except in Ruby, the params leave out the request options, so pass those again.
736**Params.** The params hold the helper’s fields and the full conversation. Pass them to the method that creates a helper to start a new thread. For example, start one with a different `system` (see [What to send on each request](https://platform.claude.com/docs/en/build-with-claude/message-threads#what-to-send)) or with `messages` cut back to drop later turns. A thread that you start from the params sends every message as you gave it, `cache_control` breakpoints included, so keep within the limit of 4 (see [Prompt caching on a thread](https://platform.claude.com/docs/en/build-with-claude/message-threads#prompt-caching)). Except in Ruby, the params leave out the request options, so pass those again.
737737 
738738**Structured output.** Give the output format when you create the helper. A later turn can’t change it. How you get the parsed result depends on the SDK:
739739 
from line 751
751751| Status | `error_code` | Meaning | What to do |
752752| ------ | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------- |
753753| 404 | `thread_not_found` | The API can’t continue the thread. | Send the full conversation in a new create request. |
754| 400 | `thread_fingerprint_mismatch` | A fixed field differs from the value stored with the thread. The error message names the fields. | Keep the fixed fields the same, or start a new thread to change one. |
754| 400 | `thread_fingerprint_mismatch` | A fixed field differs from the value stored with the thread. The error message names the fields. | Keep the fixed fields the same or start a new thread to change one. |
755755| 400 | `thread_already_continued` | Each response `id` can be continued once. | Continue from the latest response `id` of the thread. If your client never received that response, replay. |
756756| 400 | `thread_continue_in_flight` | Another continue request from this response `id` is still running. This is usually your own earlier attempt. | Let it finish and continue from its response `id`, or replay. |
757| 400 | `thread_unsupported_request` | The request uses a feature or an organization setting that threads don’t support. `error.details.unsupported` names it when present. | Remove that feature from the request, or send the full conversation without `thread`. |
757| 400 | `thread_unsupported_request` | The request uses a feature or an organization setting that threads don’t support. `error.details.unsupported` names it when present. | Remove that feature from the request or send the full conversation without `thread`. |
758758 
759Some 400 errors for thread requests carry no `error_code`, for example a continue request without `previous_message_id`, or one that includes `system` or `tools`.
759Some requests with `thread` return a 400 error with no `error_code`. For example, a continue request returns this error if it has no `previous_message_id` or if it includes `system` or `tools`.
760760 
761761The following example shows an error body:
762762 
from line 781
781781 
782782* [Message Batches](https://platform.claude.com/docs/en/build-with-claude/batch-processing). A request item that includes `thread` ends with an `invalid_request_error` in the batch results.
783783* [Token counting](https://platform.claude.com/docs/en/build-with-claude/token-counting). A token counting request that includes `thread` returns a 400 error. Count the full conversation instead, with `system` and `tools`.
784* [Compaction](https://platform.claude.com/docs/en/build-with-claude/compaction). [Compaction on demand](https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand) is not available with threads. A request that includes `thread` returns a 400 error if it sets the `compaction` parameter, or if it sends a `compaction` block with the `compact-2026-09-04` beta header. See [Compact a conversation](https://platform.claude.com/docs/en/build-with-claude/message-threads#compaction).
785* [Context editing](https://platform.claude.com/docs/en/build-with-claude/context-editing), except `clear_thinking_20251015` with `keep: "all"`.
784* [Compaction](https://platform.claude.com/docs/en/build-with-claude/compaction). [Compaction on demand](https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand) is not available with threads. A request that includes `thread` returns a 400 error if it sets the `compaction` parameter or if it sends a `compaction` block with the `compact-2026-09-04` beta header. See [Compact a conversation](https://platform.claude.com/docs/en/build-with-claude/message-threads#compaction).
785* [Context editing](https://platform.claude.com/docs/en/build-with-claude/context-editing) except `clear_thinking_20251015` with `keep: "all"`.
786786* Organizations that have [HIPAA readiness](https://platform.claude.com/docs/en/manage-claude/api-and-data-retention#hipaa-readiness) enabled.
787787* Organizations that have [Inference hooks](https://platform.claude.com/docs/en/manage-claude/inference-hooks) turned on.
788788 
Feedback