4.7 KiB
Claude Code with DeepSeek API
This guide shows how to run Claude Code through DeepSeek's Anthropic-compatible API while capturing the traffic with claude-tap.
DeepSeek's official Claude Code guide points Claude Code at https://api.deepseek.com/anthropic and uses deepseek-v4-pro[1m] for the main Claude Code model. When you capture the session with claude-tap, keep that same Claude Code environment. claude-tap reads the DeepSeek upstream from ANTHROPIC_BASE_URL, then launches Claude Code against the local proxy.
Simplified Chinese version: Claude Code 搭配 DeepSeek API.
Environment
Use ANTHROPIC_AUTH_TOKEN for Claude Code and leave ANTHROPIC_API_KEY unset to avoid Claude Code's API-key conflict prompt.
export ANTHROPIC_AUTH_TOKEN="<your DeepSeek API key>"
unset ANTHROPIC_API_KEY
export ANTHROPIC_MODEL="deepseek-v4-pro[1m]"
export ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek-v4-pro[1m]"
export ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek-v4-pro[1m]"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="deepseek-v4-flash"
export CLAUDE_CODE_SUBAGENT_MODEL="deepseek-v4-flash"
export CLAUDE_CODE_EFFORT_LEVEL=max
export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
claude-tap uses the current ANTHROPIC_BASE_URL as the real upstream target before it overwrites the launched Claude Code process with the local proxy URL. Use --tap-target only when you want to override that detected upstream.
Capture With claude-tap
Run claude-tap normally:
claude-tap -- --permission-mode bypassPermissions
For a one-off non-interactive smoke test:
claude-tap \
-- \
--permission-mode bypassPermissions \
-p 'Use Bash to run pwd, then reply with DEEPSEEK_CLAUDE_TAP_OK.'
When the process exits, open the generated viewer:
open .traces/*/trace_*.html
TLS and Local Proxies
If the upstream request fails with SSLCertVerificationError while direct curl calls succeed, the Python process may be using a CA bundle that does not trust your local outbound proxy. Run claude-tap with the system bundle or the CA bundle used by your proxy:
# macOS/Homebrew examples often use /etc/ssl/cert.pem.
SSL_CERT_FILE=/etc/ssl/cert.pem claude-tap
On Debian/Ubuntu, the system CA bundle is usually /etc/ssl/certs/ca-certificates.crt.
Compatibility Notes
Claude Code 2.1.128 and 2.1.131 can send metadata.user_id as a JSON string. DeepSeek's Anthropic-compatible endpoint rejects that value because it only accepts letters, digits, underscores, and hyphens. claude-tap normalizes invalid metadata.user_id values only when the upstream target is https://api.deepseek.com/anthropic; default Anthropic traffic is left unchanged.
DeepSeek may return 404 for Claude Code's /v1/models?limit=1000 preflight. Claude Code continues as long as /v1/messages succeeds. In the validation run below, CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 was set to reduce unrelated startup traffic.
claude-tap redacts common authentication headers such as Authorization and x-api-key, but it does not globally scrub prompts, request bodies, or tool output. Do not put secrets in prompts, script output, or files that the agent may read into the trace.
Verified Run
Validated on 2026-05-06 with:
- Direct DeepSeek Anthropic API call returning HTTP
200 - Claude Code
2.1.131 deepseek-v4-pro[1m]for main Claude Code turnsdeepseek-v4-flashfor Claude Code title/auxiliary turnsANTHROPIC_BASE_URL=https://api.deepseek.com/anthropicclaude-tapCLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
The serial tmux run produced:
- 3 user rounds
- 11
/v1/messagesrequests - 6 unique
Bashtool_useblocks, two per requested round - 6 matching
tool_resultblocks - A generated HTML viewer from the real trace under
.traces/ - Viewer screenshots captured after multiple Playwright mouse-wheel scroll events
Overview:
Scrolled detail pane:
Scrolled sidebar/navigation:
Final response after additional mouse-wheel scrolling:



