Claude API Memory Persistence: How Conversations Work
Does the Claude API Remember Conversations?
No. The Claude API is stateless — every request is independent, and Anthropic's servers do not retain or recall anything from a previous call. If you want Claude to "remember" earlier parts of a conversation, you have to resend that history yourself with every request. There is no session ID, no server-side memory, and no automatic linking between calls, even if they come from the same user a few seconds apart.
This surprises a lot of developers coming from chat products like claude.ai, where memory feels automatic. In the API, that illusion of memory is actually just the client (claude.ai's frontend) reconstructing the full message history and sending it back on every turn. Understanding this is the key to building anything with multi-turn context, whether it's a chatbot, an agent, or a support tool.
How Conversation State Actually Works
Claude's messages endpoint takes a messages array. Each entry has a role (user or assistant) and content. To continue a conversation, you append the new user message to the array and resend the entire history — including Claude's previous replies — on every call.
{
"model": "claude-sonnet-4-5",
"max_tokens": 1024,
"messages": [
{ "role": "user", "content": "My name is Priya and I work in fintech." },
{ "role": "assistant", "content": "Nice to meet you, Priya! What are you working on in fintech?" },
{ "role": "user", "content": "What's my name again?" }
]
}
Claude will correctly answer "Priya" here — not because it remembers, but because the full exchange is right there in the request payload. Remove the earlier turns and it has no idea who "Priya" is. This is the entire mechanism behind "memory persistence" in the Claude API: you own the state, not Anthropic.
Where to Store Conversation History
Since the API itself holds nothing, persistence is an application-layer concern. Common approaches, roughly in order of complexity:
- In-memory array — fine for a quick script or demo, lost on restart. Not viable for anything production.
- Database table — a
messagestable keyed byconversation_id, storingrole,content, and a timestamp. This is the standard approach for most chat apps. - Redis or similar cache — good for short-lived sessions where you want fast reads/writes and don't need long-term durability.
- Vector store for long-term recall — once conversations get long, you often don't want to resend everything (cost and context-window limits). Instead you store embeddings of past turns and retrieve only the relevant ones for the current query, injecting them as context.
A minimal persistence loop looks like this:
async function sendMessage(conversationId, userText) {
const history = await db.getMessages(conversationId); // load prior turns
const messages = [...history, { role: "user", content: userText }];
const response = await fetch("https://api.subtoapi.app/v1/messages", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "claude-sonnet-4-5",
max_tokens: 1024,
messages
})
});
const data = await response.json();
const assistantText = data.content[0].text;
await db.saveMessage(conversationId, "user", userText);
await db.saveMessage(conversationId, "assistant", assistantText);
return assistantText;
}
This pattern — load, append, call, save — is the backbone of every Claude-based chat product, regardless of framework.
Managing Context Window Limits
Resending the full history works until it doesn't. Claude's context window is large, but long-running conversations (support threads, coding sessions, long-form assistants) will eventually hit limits or get expensive, since you pay for input tokens on every turn, including the history you resend.
Practical strategies:
- Truncate old turns once you're near the limit, keeping only the most recent N exchanges.
- Summarize older context with a cheaper model call, then replace a block of old turns with a compact summary message.
- Retrieve selectively using embeddings, so only relevant past turns get re-injected rather than the entire transcript.
- Separate system context from chat history — put stable instructions (persona, rules, formatting) in the
systemparameter instead of repeating them in every user turn.
None of these require special API features — they're just history-management logic you write around the stateless messages call. See /docs/messages for the full request schema.
Streaming and Tool Use Don't Change This
If you're using streaming responses or tool calling, the statelessness rule still applies. A streamed reply is just delivered incrementally — you still need to capture the full assembled text and store it as the assistant's turn once the stream completes. With tool use, intermediate tool calls and results also belong in the message history if you want Claude to reference them later in the same conversation. Details on both are in /docs/streaming and /docs/tools.
Where SubToAPI Fits
SubToAPI doesn't add server-side memory to Claude either — no proxy can change how the underlying model works — but it does make building persistent conversations easier to operate day to day. You get a standard HTTPS endpoint with an application API key (sub_live_...), request logs with token usage per call so you can see exactly how much your stored history is costing you, and streaming support that works the same way as above. If you're running a team building chat features on Claude, shared billing and per-seat access (from the Solo plan at €9 up through Team and Scale) means you're not passing around a single shared key for something that needs an audit trail. Check /pricing or start with /signup and /docs/quickstart.
Questions
Does Claude have a "memory" feature like ChatGPT's persistent memory? Not in the API. Claude.ai's consumer product may offer memory-like features in its own UI, but the API itself is fully stateless — you must manage and resend conversation history yourself.
How much conversation history should I send with each request? As much as needed for coherent replies, bounded by your context window and budget. Most apps truncate or summarize once a conversation exceeds a few dozen turns to control token costs.
Can I use a database instead of resending full chat history every time? You still need to resend the relevant text in the API call — Claude can't query your database directly — but you use the database to decide which messages to include, via truncation, summarization, or retrieval.