Guides
Messages and Generation Parameters
Organize multi-turn messages and understand common parameters such as temperature, max_tokens, and stream.
Chat Completions represents a conversation as a chronological messages array. Each message has a role and content; longer histories usually consume more input tokens.
Message roles
| Role | Purpose | Example |
|---|---|---|
system | Set the assistant's identity, tone, boundaries, and output rules. | “You are a product classifier that returns only JSON.” |
user | End-user questions, tasks, or supplied information. | “Classify this review as positive or negative.” |
assistant | Previous model replies for conversation continuity. | Save and resend the previous model message. |
tool | Results returned after the application executes an external tool. | A JSON string returned by a weather API. |
Multi-turn conversation
{
"model": "deepseek-chat",
"messages": [
{
"role": "system",
"content": "You are a technical support assistant. Provide actionable steps."
},
{
"role": "user",
"content": "My request returns 401. What should I check?"
},
{
"role": "assistant",
"content": "First check the Authorization header and whether the API key is valid."
},
{
"role": "user",
"content": "What format should the header use?"
}
]
}The API does not automatically remember previous requests. Your application stores relevant messages and resends them when multi-turn context is needed.
Common generation parameters
| Parameter | Type | Purpose | Recommendation |
|---|---|---|---|
model | string | Select the target model. | Use the exact catalog identifier. |
messages | array | Provide the task and conversation context. | Keep only relevant information. |
temperature | number | Adjust output randomness. | Use lower values for factual extraction and higher values when appropriate for creative tasks. |
max_tokens | integer | Limit output tokens. | Leave enough room for the answer while controlling cost and latency. |
stream | boolean | Enable incremental output. | Recommended for interactive products; handle disconnections. |
tools | array | Describe external tools available to the model. | Expose only tools needed for the current task. |
Context management
- Keep system instructions short and specific; avoid repeating the same rule in multiple places.
- Summarize older messages in long conversations, retaining recent interactions and key facts.
- For RAG, inject only relevant passages and clearly mark source boundaries.
- Reserve output tokens: input plus expected output must fit the model's context window.
- Do not assume every model supports identical parameters or roles.