Introduction
How does an AI chatbot remember what you said earlier in a conversation?
For example, imagine asking a chatbot a question and then referring to something you mentioned earlier.
My name is John.
Nice to meet you, John!
What is my name?
Your name is John.
The chatbot can answer because it has access to the previous conversation.
However, an LLM does not automatically remember previous API requests. Your application must maintain conversation history and provide it with new requests.
Let's explore how to manage conversation state using OpenAI and Claude APIs.
What is conversation state management?
Conversation state management means keeping track of previous interactions so the AI can understand the conversation and provide relevant answers.
A conversation can contain:
- User messages
- Assistant responses
- Tool calls and their results
Your application is responsible for maintaining this history between API requests.
There are different ways to manage this history. Let's look at four approaches supported by OpenAI and Claude including latest beta feature of Claude Thread.
Approach 1: Manual conversation history
This is the simplest and most flexible approach. Your application stores previous user and assistant messages in a list. Whenever the user sends a new message, you send the previous messages along with it. This gives the LLM the context it needs to continue the conversation.
messages = [
{"role": "user", "content": "My name is John."}
]
response = client.responses.create(
model="gpt-5.5",
input=messages
)
messages.append({
"role": "assistant",
"content": response.output_text
})
messages.append({
"role": "user",
"content": "What is my name?"
})
response = client.responses.create(
model="gpt-5.5",
input=messages
)
print(response.output_text)Both OpenAI and Claude support manual conversation history.
The main difference is that your application is responsible for storing and sending the messages. You can keep them in memory, a database or another storage system.
✓When to use it
Use this approach when you want full control over conversation history, storage and message management.
Approach 2: OpenAI Conversations API
What if you don't want to manually send the previous messages with every request? OpenAI provides the Conversations API for this purpose.
You create a conversation and receive a unique conversation ID. You then use that ID when sending new messages. OpenAI maintains the conversation history associated with that ID.
First, create a conversation:
conversation = client.conversations.create()Send the first message:
response = client.responses.create(
model="gpt-5.5",
conversation=conversation.id,
input="My name is John."
)Continue the conversation:
response = client.responses.create(
model="gpt-5.5",
conversation=conversation.id,
input="What is my name?"
)
print(response.output_text)Notice that we don't pass the previous messages again. We simply use the same conversation ID.
Conversations can persist across sessions, devices and jobs, making this useful for chat applications where users return to previous conversations.
✓When to use it
Use this approach when building OpenAI chatbots that need persistent conversations across sessions.
Approach 3: Using previous_response_id
Another option in OpenAI is previous_response_id.
Instead of creating a separate conversation object, you connect a new response to the previous response using its ID.
This creates a chain of responses that allows the conversation to continue.
response1 = client.responses.create(
model="gpt-5.5",
input="My name is John."
)
response2 = client.responses.create(
model="gpt-5.5",
previous_response_id=response1.id,
input="What is my name?"
)
print(response2.output_text)Here, the second request references the first response through previous_response_id.
You don't need to manually maintain and send the complete message list.
Unlike the Conversations API, this approach does not require creating a separate conversation object.
✓When to use it
Use this approach when you want a simple way to continue conversations by linking one response to another.
Approach 4: Claude Message Threads (Beta) – A Newer, Improved Approach
Anthropic now offers Message Threads, a beta feature that provides temporary server-side conversation continuity.
Instead of uploading the complete conversation history on every request, you send the full conversation when creating a thread. For subsequent requests, you send only the new messages and the ID of the previous response similar to OpenAI Conversation API.
How Message Threads work
Let's look at a Python example.
Create a thread with the first message:
first = client.beta.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[
{"role": "user", "content": "My name is John."}
],
thread={"type": "create"},
betas=["message-threads-2026-08-12"],
)Continue the conversation:
second = client.beta.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[
{"role": "user", "content": "What is my name?"}
],
thread={
"type": "continue",
"previous_message_id": first.id
},
betas=["message-threads-2026-08-12"],
)
print(second.content[0].text)The previous_message_id connects the new request to the previous response. For the next turn, use the latest response ID.
Important things to know about Message Threads
- Temporary storage: A thread expires five minutes after its last request. Anthropic deletes it no more than one hour after its last use.
- System prompts and tools: Send the system prompt and tools when creating the thread. They are retained by the thread, so don't send them again when continuing it.
- Beta feature: Message Threads require the
message-threads-2026-08-12beta header. - Fallback: If a thread expires or cannot be continued, create a new thread using the full conversation history.
Message Threads are particularly useful for long-running agents, coding assistants and workflows with many tool calls. They reduce the amount of conversation data your application needs to upload on each turn, which can improve time to first token.
✓When to use it
Use Message Threads for active conversations where reducing repeated data uploads and improving response latency are important. Keep your own conversation history for persistence and recovery.
Comparing the approaches
Let's compare the different approaches based on how conversation history is managed.
| Feature | Manual history | previous_response_id | Conversations API | Claude Message Threads |
|---|---|---|---|---|
| Provider | OpenAI / Claude | OpenAI | OpenAI | Claude |
| History management | Your application | OpenAI response chain | OpenAI | Anthropic thread |
| Persistence | Your storage | Subject to response retention | Persistent | Temporary (5-minute inactivity expiry) |
| Main benefit | Full control | Easy response chaining | Smaller requests and lower latency | Smaller requests and lower latency |
Official documentation
Want to build practical AI applications?
Auragile's AI Engineering course teaches developers by building real-world projects, from LLM-powered applications to more advanced AI systems.
