Multi-turn Conversation
Endpoints
Multi-turn Conversation
Maintain conversation context across multiple messages by passing full history with every request.
POST
Multi-turn Conversation
Overview
The Claude API is stateless — Claude has no memory between requests. Every request starts fresh. To maintain context across a conversation, your application must pass the full conversation history with every request. This is not a limitation, it is a deliberate design decision that gives developers complete control over what context Claude sees at any point in the conversation.How Context Works
Every message in the conversation is passed as an object in themessages array. Claude reads the entire array on every request and responds based on the full history you provide.
“Your name is Chisaneme and you are a technical writer.”Claude knew the answer because you passed the full history. Without it, Claude would have no context.
The Alternating Role Pattern
Messages must strictly alternate betweenuser and assistant roles:
user → assistant → user → assistant → user
The array must always:
- Start with a
usermessage - Alternate between
userandassistantroles throughout
Token Accumulation
Every message in the history consumes input tokens. As a conversation grows, input tokens increase with every request:
Input tokens are billed on every request — a long conversation history means higher costs on every subsequent turn.
Context Window Limit
The total conversation history including all messages and the system prompt, must fit within the model’s context window:
200,000 tokens is approximately 150,000 words. For most applications this limit is rarely reached — but document-heavy or very long conversations can approach it.
If the limit is exceeded the API returns:
Who Manages History
Your application manages conversation history — not the API. A typical implementation looks like this:- User sends a message
- Your app appends it to the history array as a user turn
- Your app sends the full history to the API
- Claude responds
- Your app appends Claude’s response to the history as an assistant turn
- Repeat from step 1
Further Reading
Messages
Deep dive into the messages array structure
Tokens
How token accumulation affects cost in long conversations
System Prompt
Add a system prompt to shape behavior across all turns
Tool Use
Maintain context across tool use cycles
Authorizations
Headers
Example:
"2023-06-01"
Body
application/json
Response
Successful response
Example:
"msg_01XFDUDYJgAACzvnptvVoYEL"
Example:
"message"
Example:
"assistant"
Example:
"claude-sonnet-4-6"
Available options:
end_turn, max_tokens, stop_sequence, tool_use Example:
"end_turn"