High severity beginner · Fix: 2-5 min

ValueError

deepseek.exceptions.ConfigurationError: base_url not set

What this error means
DeepSeek OpenAI SDK throws a configuration error when the required base_url environment variable or parameter is not set.

Stack trace

traceback
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
QUICK FIX
Set the DEEPSEEK_BASE_URL environment variable or pass base_url explicitly when instantiating the DeepSeek client.

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

1

The DEEPSEEK_BASE_URL environment variable is not set in the runtime environment.

✓ Fix

Set the DEEPSEEK_BASE_URL environment variable to the correct API endpoint URL before running your application.

2

The DeepSeek client is instantiated without passing the base_url parameter explicitly.

✓ Fix

Pass the base_url parameter explicitly when creating the DeepSeek client, e.g. DeepSeek(api_key=..., base_url=...).

3

Using an outdated DeepSeek SDK version that requires manual base_url configuration.

✓ Fix

Upgrade to the latest DeepSeek SDK version which supports automatic base_url detection or requires explicit setting.

Code: broken vs fixed

Broken - triggers the error
python
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)
Fixed - works correctly
python
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)
Added base_url parameter from environment variable to DeepSeek client initialization to satisfy SDK requirement and avoid ConfigurationError.

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.

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.