High severity beginner · Fix: 2-5 min

ValueError

deepseek.errors.ValueError

What this error means
DeepSeek raises a ValueError when both temperature and top_p parameters are set simultaneously, as they conflict in sampling configuration.

Stack trace

traceback
Traceback (most recent call last):
  File "app.py", line 42, in <module>
    response = client.chat.completions.create(model="deepseek-chat-1", messages=messages, temperature=0.7, top_p=0.9)
  File "/usr/local/lib/python3.9/site-packages/deepseek/client.py", line 120, in create
    raise ValueError("Cannot set both temperature and top_p parameters together.")
ValueError: Cannot set both temperature and top_p parameters together.
QUICK FIX
Remove either temperature or top_p from your DeepSeek client call to resolve the parameter conflict immediately.

Why it happens

DeepSeek's sampling configuration requires either temperature or top_p to control randomness, but not both simultaneously. Setting both causes an internal conflict in the sampling algorithm, triggering this error.

Detection

Check your API call parameters before sending requests; log or assert that only one of temperature or top_p is set to avoid this conflict error.

Causes & fixes

1

Both temperature and top_p parameters are set in the DeepSeek chat completion call.

✓ Fix

Remove one of the parameters so only temperature or top_p is specified, never both.

2

Using a wrapper or helper function that sets default temperature and top_p simultaneously.

✓ Fix

Review and update helper functions or config to ensure only one sampling parameter is passed to DeepSeek client.

3

Misunderstanding of DeepSeek API sampling parameters leading to simultaneous use.

✓ Fix

Consult DeepSeek documentation to understand that temperature and top_p are mutually exclusive and choose the appropriate one.

Code: broken vs fixed

Broken - triggers the error
python
from openai import OpenAI
import os

client = OpenAI(api_key=os.environ["DEEPSEEK_API_KEY"], base_url="https://api.deepseek.com")
messages = [{"role": "user", "content": "Hello"}]

# This line causes the ValueError due to both parameters set
response = client.chat.completions.create(model="deepseek-chat-1", messages=messages, temperature=0.7, top_p=0.9)
print(response)
Fixed - works correctly
python
from openai import OpenAI
import os

client = OpenAI(api_key=os.environ["DEEPSEEK_API_KEY"], base_url="https://api.deepseek.com")
messages = [{"role": "user", "content": "Hello"}]

# Fixed: Removed top_p parameter to avoid conflict
response = client.chat.completions.create(model="deepseek-chat-1", messages=messages, temperature=0.7)
print(response)
Removed the top_p parameter so only temperature is set, resolving the conflict and allowing the request to succeed.

Workaround

If you cannot change the call immediately, wrap the client call in try/except catching ValueError and retry the call with only one sampling parameter set.

Prevention

Design your configuration and wrapper functions to enforce mutually exclusive setting of temperature and top_p before calling DeepSeek APIs to prevent this error.

Python 3.9+ · deepseek >=3.0.0 · tested on 3.2.1
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.