← Back to API Guides

Multi-round Conversation

Build multi-turn conversations by including previous messages in the messages array.

How It Works

The DeepSeek API is stateless — each request is independent. To maintain conversation context, include the full conversation history in the messages array with appropriate roles (system, user, assistant).

Example

Send the entire conversation history to maintain context across turns.
{
  "model": "deepseek-v4-pro",
  "messages": [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "What is the capital of France?"},
    {"role": "assistant", "content": "The capital of France is Paris."},
    {"role": "user", "content": "What about Germany?"}
  ]
}

Best Practices

• Keep conversation history concise to reduce token usage. • Use system messages to set behavior and context. • Consider summarizing long histories to stay within context limits. • Use context caching for repeated prefixes to reduce costs.