DeepSeek-R1 Prompting & Reasoning API Guide
DeepSeek-R1 generates an explicit chain of thought before answering. Review Zero-shot prompting rules, hosted vs local parameter boundaries, and multi-turn API handling.
On this page
1. Core reasoning mechanism
DeepSeek-R1 generates an internal chain of thought before providing answers. In API responses, the reasoning trajectory is returned in the dedicated reasoning_content field, while final conclusions are delivered in standard content.
2. Official prompting principles
Zero-shot prompt preference
Directly describe the target question. Avoid rigid few-shot examples or strict formatting templates that hinder autonomous problem exploration.
Avoid step-by-step instructions
Do not append "think step by step." DeepSeek-R1 is reinforcement-learning trained to self-verify and refine steps autonomously.
3. Hosted API vs local weight parameters
- Hosted API (
deepseek-reasoner): Onapi.deepseek.com, sampling parameters such astemperature,top_p,presence_penalty, andfrequency_penaltyare ignored by the server (passing them does not raise an error, but they have no effect). - Self-hosted weights (Ollama / vLLM / SGLang): When serving open-weight
DeepSeek-R1orDeepSeek-R1-Distillmodels locally, the DeepSeek-R1 model card recommends setting Temperature in the0.5 ~ 0.7range (default0.6) to avoid repetitive loops or incoherent jumps. - Size
max_tokensfor CoT + answer: Ensuremax_tokensleaves headroom for both reasoning steps and final output (for example8192or higher on long proofs) so the response does not stop mid-thought.
4. Streaming reasoning_content (Python example)
Stream both reasoning steps and final conclusions separately:
from openai import OpenAI
client = OpenAI(
api_key="sk-your_deepseek_api_key",
base_url="https://api.deepseek.com"
)
response = client.chat.completions.create(
model="deepseek-reasoner",
messages=[{"role": "user", "content": "Which number is larger: 9.11 or 9.8? Provide a proof."}],
stream=True
)
reasoning_content = ""
answer_content = ""
for chunk in response:
delta = chunk.choices[0].delta
# Print reasoning steps
if hasattr(delta, "reasoning_content") and delta.reasoning_content:
reasoning_chunk = delta.reasoning_content
reasoning_content += reasoning_chunk
print(reasoning_chunk, end="", flush=True)
# Print final answer
elif delta.content:
if not answer_content:
print("\n\n=== Final Answer ===\n")
answer_chunk = delta.content
answer_content += answer_chunk
print(answer_chunk, end="", flush=True)5. Common pitfalls to avoid
Echoing reasoning_content in multi-turn API requests (HTTP 400)
When building multi-turn chat history, append only the assistant's final content to messages. Sending prior reasoning_content fields back to api.deepseek.com returns a 400 validation error.
Overcomplicating the System Prompt
Heavy persona constraints interfere with reasoning exploration. On local R1 weights, omit the system message and place all task constraints directly in the user prompt.
Truncated outputs with empty content
The chain-of-thought phase consumed the entire max_tokens budget before reaching the final answer. Increase max_tokens so both phases fit.