Skip to content
Main Site News Console

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:

StrategyApproachUse Case
Sliding windowKeep only the most recent N turns + systemCustomer support, casual chat
Summary compressionCompress old history into a summary with a cheaper modelLong-session assistants
Retrieval augmentationStore history in a vector database and retrieve relevant fragments as neededKnowledge-based applications

Notes

  • The system message 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 model value.