Multi-turn Conversations
Chat Completions is a stateless API: the model does not remember the previous request. The principle of multi-turn conversations is — send the full history of messages with every request.
Basic Usage
messages = [ {"role": "system", "content": "You are a concise Chinese assistant."}, {"role": "user", "content": "What is a vector database?"},]r1 = client.chat.completions.create(model="gpt-5.5", messages=messages)messages.append({"role": "assistant", "content": r1.choices[0].message.content})
messages.append({"role": "user", "content": "What is the difference between it and Elasticsearch?"})r2 = client.chat.completions.create(model="gpt-5.5", messages=messages)In the second round, the model can understand what “it” refers to, because the complete history is in messages.
Context Management
The longer the history, the more input tokens are used, the higher the cost, and the more likely it is to exceed the model context limit. Common strategies:
| Strategy | Approach | Use Case |
|---|---|---|
| Sliding window | Keep only the most recent N turns + system | Customer support, casual chat |
| Summary compression | Compress old history into a summary with a cheaper model | Long-session assistants |
| Retrieval augmentation | Store history in a vector database and retrieve relevant fragments as needed | Knowledge-based applications |
Notes
- The
systemmessage is recommended to always be kept as the first message, and use cached billing to reduce repeated costs; - When truncating history, delete it in “turns” (paired user + assistant messages), and do not cut it off halfway;
- When switching between models cross-model (for example, GPT to Claude), the history format does not need to change; simply change the
modelvalue.