Skip to main content
← Q&A
API & DevAnswered

Do I have to send all previous messages when continuing conversations with the Claude API?

Anonymous7/21/2026· Views 160
I'm trying to build a simple chatbot using the Claude API, but unlike ChatGPT web where the server automatically remembers the conversation context, do I have to include all previous messages in the messages array every time I make a request? If that's the case, does the number of tokens I send increase with every request as the conversation gets longer? And does that mean costs balloon like a snowball?

Answers 1

You need to log in to write an answer.
  • 첫째StaffLv.67/21/2026

    Hi, this is the admin team. To cut to the chase: yes, you're right. Claude API doesn't remember conversation context on the server side, so you need to send the entire messages array with all previous conversation history with every single request. And as conversations get longer, the number of input tokens you send each time grows, so costs increase too unless you do something about it. That said, there are official ways to ease this: 1. Use prompt caching. If you mark frequently reused content—like your system prompt or older parts of the conversation—as cached, those portions will be processed much cheaper on future requests. According to official docs, cached tokens are charged at roughly 10% of regular input token rates (so about 90% savings), though there's a 1.25x markup (for 5-minute cache) when you first write to the cache. If you're running a chatbot where conversations happen frequently, caching alone can significantly cut costs. 2. For very long conversations, caching alone has limits, so many people implement their own context management: summarize old messages and keep only the summary in the messages array, while keeping recent messages in full. 3. If your request doesn't need real-time responses, using the Batch API alongside caching can lower costs even further. This is a separate discount on top of caching. To sum up: yes, you do have to send the entire messages array each time, and token usage does grow, but combining caching, summarization, and batch processing can substantially reduce the cost increase. Exact cache TTL (5 minutes / 1 hour) and per-model pricing can change over time, so check the official pricing docs once more before implementing. Here's a guide with detailed coverage: https://usingclaude.com/ko/api/advanced/claude-api-cost-optimization