ValueError
deepseek.exceptions.ConfigurationError: base_url not set
Stack trace
deepseek.exceptions.ConfigurationError: base_url not set
File "/usr/local/lib/python3.9/site-packages/deepseek/sdk.py", line 45, in __init__
raise ConfigurationError("base_url not set")
File "/app/main.py", line 12, in <module>
client = DeepSeek(api_key=os.environ['DEESEEK_API_KEY']) # triggers error
Why it happens
The DeepSeek SDK requires a base_url parameter or environment variable to know which API endpoint to call. If this is missing, the SDK cannot initialize properly and raises a ConfigurationError. This usually happens when environment variables are not set or the client is instantiated without specifying base_url.
Detection
Check for ConfigurationError exceptions during DeepSeek client initialization and verify that the base_url environment variable or parameter is set before making API calls.
Causes & fixes
The DEEPSEEK_BASE_URL environment variable is not set in the runtime environment.
Set the DEEPSEEK_BASE_URL environment variable to the correct API endpoint URL before running your application.
The DeepSeek client is instantiated without passing the base_url parameter explicitly.
Pass the base_url parameter explicitly when creating the DeepSeek client, e.g. DeepSeek(api_key=..., base_url=...).
Using an outdated DeepSeek SDK version that requires manual base_url configuration.
Upgrade to the latest DeepSeek SDK version which supports automatic base_url detection or requires explicit setting.
Code: broken vs fixed
from deepseek import DeepSeek
import os
client = DeepSeek(api_key=os.environ['DEESEEK_API_KEY']) # triggers base_url not set error
response = client.chat.completions.create(model="gpt-4o", messages=[{"role": "user", "content": "Hello"}])
print(response) from deepseek import DeepSeek
import os
# Fix: Set base_url explicitly or ensure environment variable is set
client = DeepSeek(api_key=os.environ['DEESEEK_API_KEY'], base_url=os.environ['DEEPSEEK_BASE_URL']) # base_url set from env
response = client.chat.completions.create(model="gpt-4o", messages=[{"role": "user", "content": "Hello"}])
print(response) Workaround
Wrap DeepSeek client initialization in try/except ConfigurationError and prompt users or logs to set the base_url environment variable before retrying.
Prevention
Always set DEEPSEEK_BASE_URL environment variable in your deployment environment or pass base_url explicitly in code to ensure SDK initializes correctly.