Configure DeepSeek API in Claude Code & Cline
Connect DeepSeek models to Claude Code CLI and VS Code Cline or Roo Code using DeepSeek's Anthropic- and OpenAI-compatible API endpoints.
On this page
Generate an API key from the DeepSeek Platform (starting with sk-) and confirm your account balance before connecting.
Claude Code (terminal CLI) configuration
Configure Claude Code to route requests through DeepSeek via environment variables.
Add these lines to your shell profile (~/.zshrc or ~/.bashrc):
# macOS / Linux
export ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic"
export ANTHROPIC_API_KEY="sk-your_deepseek_api_key"
export API_TIMEOUT_MS=600000
export ANTHROPIC_MODEL="deepseek-chat"
export ANTHROPIC_SMALL_FAST_MODEL="deepseek-chat"For Windows PowerShell sessions:
$env:ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic"
$env:ANTHROPIC_API_KEY="sk-your_deepseek_api_key"
$env:API_TIMEOUT_MS="600000"
$env:ANTHROPIC_MODEL="deepseek-chat"
$env:ANTHROPIC_SMALL_FAST_MODEL="deepseek-chat"~/.zshrc or ~/.bashrc, open a new terminal (or run source ~/.zshrc) before launching claude, and type /exit when you want to quit. Setting ANTHROPIC_SMALL_FAST_MODEL prevents background tasks from requesting unmapped Haiku model IDs, and API_TIMEOUT_MS=600000 avoids timeouts on long outputs. If your CLI version rejects non-Anthropic key prefixes in ANTHROPIC_API_KEY, use export ANTHROPIC_AUTH_TOKEN="sk-your_key" instead and inspect /status inside claude.VS Code extension setup (Cline / Roo Code)
- Install Cline or Roo Code from the VS Code Marketplace.
- Open the extension panel and click Settings ⚙️.
- Set API Provider to DeepSeek (or OpenAI Compatible).
- Paste your key into DeepSeek API Key.
- Choose deepseek-chat for daily coding or deepseek-reasoner for architecture planning.
- Base URL:
https://api.deepseek.comorhttps://api.deepseek.com/v1 - Model ID:
deepseek-chatordeepseek-reasoner
Claude Desktop boundary and local LiteLLM gateway
The official Claude Desktop app authenticates directly against claude.ai and extends local capabilities through MCP servers rather than custom chat Base URLs. If you use desktop or IDE clients that accept a custom gateway URL, you can bridge protocol differences locally with LiteLLM:
# Run a local LiteLLM gateway for clients that support custom Base URLs
pip install 'litellm[proxy]'
export DEEPSEEK_API_KEY="sk-your_deepseek_api_key"
litellm --model deepseek/deepseek-chat --port 8000Send a test prompt
Send a safe read-only message in your client:
Reply only with "DeepSeek connected successfully." Do not modify files.Common errors and solutions
401 Unauthorized / Authentication Error
Ensure the key begins with sk- with no surrounding whitespace. Do not use your web password.
402 Insufficient Balance
API usage is billed separately from web subscriptions. Top up your balance in the DeepSeek Platform.
Tool calling issues with deepseek-reasoner
Tool-calling behavior on deepseek-reasoner depends on client protocol handling (for example, omitting reasoning_content from follow-up request arrays). If an agent drops tool arguments or loops, switch the execution model to deepseek-chat.