Multi-turn dialogue
DeepSeek publishes a guide explaining how to implement multi-turn conversations using its stateless /chat/completions API by manually concatenating conversation history in each request.
This guide will introduce how to use the DeepSeek /chat/completions API for multi-turn conversations. The DeepSeek /chat/completions API is a "stateless" API, meaning the server does not record the context of user requests. Users need to concatenate all previous conversation history and pass it to the conversation API with each request. The following code demonstrates in Python how to concatenate context to implement multi-turn conversations. from openai import OpenAI client = OpenAI(api_key="", base_url="https://api.deepseek.com") Round 1 messages = [{"role": "user", "content": "What's the highest mountain in the world?"}] response = client.chat.completions.create( model="deepseek-v4-pro", messages=messages ) messages.append(response.choices[0].message) print(f"Messages Round 1: {messages}") Round 2 messages.append({"role": "user", "content": "What is the second?"}) response = client.chat.completions.create( model="deepseek-v4-pro", messages=messages ) messages.append(response.choices[0].message) print(f"Messages Round 2: {messages}") In the first round of requests, the messages passed to the API are: [ {"role": "user", "content": "What's the highest mountain in the world?"} ]…
- api-docs.deepseek.comMulti-turn dialogueprimary