API Features & Capabilities

Multi-Turn Conversations: Managing the Messages Array

The API has no memory of your last request. Every "conversation" is a list you rebuild and resend — which makes history management your job, and your bill.

Claude 3P 101 · Updated July 2026 · Unofficial guide

The single most important fact about the Messages API is that it is stateless. Claude does not remember your previous request on any platform — not on Bedrock, not on Vertex AI, not on Foundry or Claude Platform on AWS. What looks like a conversation is really your application maintaining an array of turns and sending the whole thing back, grown by two entries, on every call.

How the array models a conversation

The messages array alternates roles: a user turn, then an assistant turn, then user again. Your loop is simple in outline: send the array, receive a response, append that response as an assistant turn, append the user's next input as a user turn, and send the whole array again. Each entry's content can be a plain string or a list of typed blocks — text, images, documents, tool calls and results — so the same structure carries chat, vision, and agentic tool loops alike.

Two shapes deserve care. First, when Claude requests tools, the tool results go back inside a user turn — and if multiple tools were called at once, all results belong in a single user message. Second, if the assistant turn contained thinking blocks, pass them back exactly as received: modifying, reordering, or filtering thinking blocks in the latest assistant message returns a 400 error, because they are verified cryptographically by signature.

What appending really costs

Because you resend everything, every past turn is billed as input tokens on every new request. Everything in the request counts toward the context window too: system prompt, all messages including tool results and documents, tool definitions, and the output being generated. A 50-turn support conversation is not paying for one exchange — it is paying for 50 turns of history on turn 51. This is why prompt caching matters so much for conversational apps: with a cache breakpoint moving forward along the conversation, the unchanged prefix is re-read at roughly a tenth of the input price instead of full price. On most models cache reads do not even count against your input-tokens-per-minute rate limit.

Rule of thumb: append-only histories cache beautifully; edited histories don't. Caching is a strict prefix match, so trimming or rewriting anything mid-array invalidates every cached byte after the edit point. If you must prune, prune deliberately — or let the server do it.

Where history management goes wrong

Overflowing the window. If the input alone exceeds the model's context window, the API returns a 400 "prompt is too long" error. On Claude 4.5 and later models, input plus max_tokens overflowing is tolerated — generation simply stops with stop_reason: "model_context_window_exceeded" — but your code needs to handle that stop reason rather than assume a complete answer.

Hand-rolled trimming. Ad-hoc "drop the oldest messages" logic tends to orphan tool results from their tool calls and destroy cache prefixes. Prefer the server-side options: context editing clears old tool results before the prompt reaches the model while your client keeps its full history, and compaction (beta) summarizes older content into a compaction block once the conversation nears a token threshold.

Assuming prefill still works. An old trick — ending the array with a partial assistant turn for Claude to continue — is no longer supported on current-generation models such as Fable 5, Opus 4.8, and Sonnet 4.6+; it returns a 400. Use structured outputs or explicit instructions instead.

Switching models mid-conversation. The array is portable, but strip thinking blocks from prior assistant turns when you switch: other models ignore them silently while still billing them as input. Note also that which models keep or strip prior thinking differs by generation, so re-test conversation flows when migrating.

Platform notes

Multi-turn conversation handling is core Messages API behavior, available on all four third-party platforms. Batch processing supports multi-turn payloads as well, so the same arrays you build interactively can be replayed in bulk where the Message Batches API is available (see the batch article for which platforms that covers).

Where to go next

Read the Messages API anatomy for the field-level view, then prompt cache mechanics to make long conversations affordable. The feature matrix shows which context-management features are live on your platform.

Sources