Use DeepSeek in Claude Code: V4 Flash / Pro Setup Guide
Run DeepSeek V4 Flash and Pro in Claude Code through APIMaster. Set the gateway and API key, switch models, verify file-reading tools and fix configuration errors.
Can Claude Code use DeepSeek? Our tests with Claude Code 2.1.239 successfully used deepseek-v4-flash and deepseek-v4-pro through APIMaster's Messages endpoint. Set ANTHROPIC_BASE_URL to https://apimaster.ai, provide an APIMaster key and select the model explicitly. This configuration runs DeepSeek, even though the client is named Claude Code.
Last tested: 2026-09-07, Claude Code 2.1.239, Linux. Both models returned the expected text and completed a file-reading tool round trip. All runs exited with code 0. The CLI printed
unrecognized_model, but the tested requests succeeded. These checks do not establish support for every Claude Code feature, long sessions or future releases. Windows / macOS setup commands are included; the recorded test ran on Linux.
1. Prepare the CLI and API key
Follow the environment guide and Claude Code setup guide for installation. Check your version:
claude --version
Get an APIMaster API key with access to the selected DeepSeek model and sufficient quota. Use the session settings below for this tutorial; there is no need to overwrite your normal settings.json.
2. Set the gateway and key
Open a new terminal to keep these settings separate from your usual CLI session.
macOS / Linux:
export ANTHROPIC_BASE_URL='https://apimaster.ai'
export ANTHROPIC_API_KEY='YOUR_APIMASTER_API_KEY'
unset ANTHROPIC_AUTH_TOKEN
Windows PowerShell:
$env:ANTHROPIC_BASE_URL = 'https://apimaster.ai'
$env:ANTHROPIC_API_KEY = 'YOUR_APIMASTER_API_KEY'
Remove-Item Env:ANTHROPIC_AUTH_TOKEN -ErrorAction SilentlyContinue
Use the site origin here, without /v1: Claude Code appends /v1/messages. The API key must come from APIMaster. These commands affect this terminal and its child processes, not your saved login files. Do not put a real key in a shared settings file or repository.
3. Send a minimal test request
claude --bare --setting-sources "" --no-session-persistence --model deepseek-v4-flash --tools "" --output-format json -p "Reply with exactly: DEEPSEEK_TEST_OK"
Expected: is_error is false, result is DEEPSEEK_TEST_OK, and the process exits with code 0. Change --model to deepseek-v4-pro and run again.
The tested version's --bare mode uses explicit API-key authentication and skips normal background integrations. --setting-sources "" excludes saved setting sources, while --tools "" disables tools for this one text test. These are deliberate diagnostic settings, not requirements to disable tools during normal use. Older CLI versions may not accept all of these flags.
4. Verify file-reading tools
Create probe.txt in the current directory with this content:
TOOL_PROBE_739182
Run:
claude --bare --setting-sources "" --no-session-persistence --model deepseek-v4-flash --tools Read --allowedTools Read --output-format json -p "Use the Read tool to read probe.txt in the current directory. Reply with only the exact content. Do not guess."
Expected: the CLI reads the file and returns TOOL_PROBE_739182. Repeat with deepseek-v4-pro. This checks that the model can request a tool, receive its result and then answer. Only the Read tool is enabled for this test.
For ordinary interactive work with the same terminal settings:
claude --bare --setting-sources "" --model deepseek-v4-flash
To start with Pro:
claude --bare --setting-sources "" --model deepseek-v4-pro
The interactive commands omit --tools "", so the default tools are available. Review permission prompts as usual. --bare skips conveniences such as hooks and automatic project instructions; enable your normal settings deliberately after the minimal setup works, and check that they do not override the gateway or model. Close this terminal when finished to leave this session's environment behind.
Troubleshooting
| Symptom | What to check |
|---|---|
unrecognized_model |
Observed for both DeepSeek IDs in 2.1.239. It did not prevent our requests from completing. Check the final result rather than treating the warning alone as failure. |
| 401 or an unexpected login prompt | Confirm ANTHROPIC_API_KEY is set, remove a conflicting ANTHROPIC_AUTH_TOKEN in this terminal and retry bare mode. |
| 404 | ANTHROPIC_BASE_URL should be https://apimaster.ai, not the full /v1/messages endpoint or a base ending in /v1. |
Unknown --bare option |
Check your version against the tested 2.1.239. Use the general installation guide to update if appropriate. |
Cannot read probe.txt |
Run from the file's directory. For the tool test, enable Read rather than using --tools "". |
| A different model is selected | Pass the full model ID with --model and check saved settings or model alias overrides before enabling them. |
| Rate limit, insufficient quota or upstream error | Read the error body, check quota and model permissions, and record the timestamp for support. |
Frequently asked questions
Is this the same as using a Claude model?
No. Claude Code is the client here; the selected model is DeepSeek. Features that depend on a particular Claude model are not automatically covered by this setup.
Why is the base URL different from the Python SDK example?
The Python OpenAI SDK uses https://apimaster.ai/v1 and appends /chat/completions. Claude Code uses https://apimaster.ai and appends /v1/messages. Use each client's documented base format.
Can I use a DeepSeek official key with this gateway?
This tutorial requires an APIMaster-issued key. Keys are specific to the provider that issues them; changing only the endpoint does not transfer credentials or quota.
Was actual tool use tested, or only a text reply?
Both were tested for both models. The tool test read a local file and returned its contents. It does not establish that all tools, background agents or long coding tasks are supported.