Skip to content

Accessing Third-Party / Domestic Models

Use domestic / third-party models like DeepSeek to drive Claude Code and cut down the bill

📚 Series Navigation: The previous article 04 · API Config explained how to use the official API Key to connect to Claude Code. This article changes the approach—swapping out the entire "brain" behind it, using domestic models like DeepSeek to save money.

⚠️ A preventive shot at the beginning of this article: Using third-party models to drive Claude Code is considered an "experimental gameplay". The official documentation only formally covers "LLM Gateways" and hosted Claude like Bedrock / Vertex, and does not endorse any non-Anthropic models. Whatever the official documentation explicitly states (environment variable meanings, default behaviors), I have marked the source; the DeepSeek part is mainly based on community solutions and actual testing, the API address and model names may change at any time, refer to the official DeepSeek for accuracy.

Brothers, let me say something that might get me scolded first: Most people don't need to tinker with third-party models at all.

A bunch of tutorials online hype "Claude Code connecting to DeepSeek" as a money-saving artifact, making it seem like you're a sucker if you don't connect. But honestly—if you have already bought a Claude subscription (Pro / Max), or your monthly API expense is just a few dozen bucks, the little money you save by tinkering around is not even enough to cover the time you spend debugging environment variables.

Then why write this article? Because there are two kinds of people who can really use it: one is heavy users whose API balance burns painfully, millions of tokens in and out every day, changing to a model ten times cheaper saves hundreds or thousands a month; the other is domestic users who can't connect to the official service and don't want to mess with proxies, a domestic direct connection interface like DeepSeek is actually the most worry-free.

If you are one of these two kinds of people—keep reading. If not, just skimming the principles is enough, don't rush to switch.

After reading this article, you will get:

  • A "Official API vs Third-Party Model" trade-off comparison table, to think clearly whether you should switch
  • A set of DeepSeek access configurations you can copy and run (given for Mac / Windows respectively)
  • Understand exactly what the 4 key environment variables are doing, universally applicable to changing any third-party model
  • A few common pitfalls: deprecated variables, /status verification, when not to use

01 First Understand: What Are You Actually Changing When You Change the Model

Conclusion first: Claude Code is the "shell", the model is the "brain", what third-party access does is swap the brain for someone else's.

The Claude Code you installed is essentially a client running in the terminal—it's responsible for reading your code, calling tools, managing context, and running that "Think → Act → Observe" agentic loop. But it doesn't think itself, every step requires sending the request to a large model and waiting for the model to reply. By default, this model is Anthropic's Claude.

Analogy: A car changing its engine. Claude Code is the car shell—the steering wheel, seats, dashboard remain unchanged, your operating habits don't need to change at all. The model is the engine. The original factory engine (Claude) has the fiercest power but expensive gas; if you want to save money, you can take it out and stuff in a domestic engine (DeepSeek). The car is still that car, the handling is about the same, it's just the power and fuel consumption that changed.

Then how exactly to "change the engine"? It doesn't rely on modifying code, but a few environment variables. The most core one of them is called ANTHROPIC_BASE_URL—it determines to which address Claude Code sends requests.

There is a point here that the official documentation specially emphasizes, but 90% of tutorials don't explain clearly:

ANTHROPIC_BASE_URL changes where requests are sent, not which model answers them. (Original text from official "Model Configuration")

What does it mean? ANTHROPIC_BASE_URL only changed "where to mail the letter", it's not responsible for "who replies to the letter". If you change the address to DeepSeek's interface, whether DeepSeek is willing to receive it and which model it uses to reply is determined by the interface address + the model name together. So just changing the URL is not enough, the model name must also follow suit—this is a high-incidence area for pitfalls later, remember this first.

Then why can DeepSeek be directly connected? Because DeepSeek provides an interface that is "compatible with the Anthropic protocol"—the address is https://api.deepseek.com/anthropic. Simply put, DeepSeek disguised itself to look like Anthropic, making Claude Code think it's still talking to the official, while actually DeepSeek is calculating behind it. Claude Code doesn't need to modify a single line of source code.

💡 One-sentence summary: Changing the model = changing a few environment variables to swap out the "engine", the car shell (Claude Code) doesn't move; ANTHROPIC_BASE_URL manages "where to mail", the model name manages "who answers", both must be configured right.


02 Should You Switch? Look at This Table First

Before taking action, calm down for five minutes. Third-party models are not a free lunch; they save money, but will also lose some things.

Taking a real project to compare for two weeks: the same set of code, the same work, using official Sonnet the first week, switching to DeepSeek the second week. The table below is the truest feeling from actual use, not copied from a parameter sheet.

DimensionOfficial Claude (Anthropic API)Third-Party / Domestic Model (e.g., DeepSeek)
PriceExpensive, Opus especially burns money✅ Cheap, often an order of magnitude cheaper
Domestic Direct ConnectMost need proxies✅ DeepSeek etc. direct connect, zero barrier
Coding Ability✅ Currently top tier, steady on complex refactoringEnough, occasionally fumbles on complex tasks
Tool Calling / Agent Ability✅ Native is steadiest, multi-step tasks don't drop the ball⚠️ Depends on model, compatible API occasionally has edge behaviors
Config CostJust fill a KeyNeeds a set of env vars, easy to hit pitfalls
Official Support✅ First-class citizen❌ Experimental, no one to catch if things break

See it clearly? Cheap and domestic direct connection are the two trump cards of third parties; the price is the coding ceiling, Agent stability, and "no one to catch you."

The real conclusion after two weeks of comparison: For daily CRUD, writing tests, filling in docs, and explaining code, DeepSeek is completely sufficient, feeling not much different from Sonnet, but the money spent is less than a fraction. But once encountering tasks like "understanding the call relationship of five or six files, cross-module large refactoring," DeepSeek missed crucial dependencies twice, whereas Claude got it right the first time with the same prompt.

So a more practical usage is to mix them: give rough work to cheap models, switch back to Claude for hard work—how exactly to layer this, Section 05 gives a configuration you can copy directly.

One sentence to judge whether you should switch:

  • Should switch: Heavy users with API bills in the hundreds or thousands a month; domestic users who find connecting to the official service tedious and don't want to mess with proxies; people who just want to practice and don't care about that bit of model gap.
  • Don't tinker: Those who already bought a Claude subscription (subscription is a fixed cost, changing to API actually costs extra, next article 06 will detail); those whose main force does complex architecture and difficult debugging (saving that bit of money is not worth trading result quality for).

Still Hesitating? Let the Network Speak First

In the "Should you switch" list above, "whether connecting to official domestically is tedious" is the hardest item to judge yourself—you think turning on the proxy makes it stable, but after running two steps Claude Code suddenly 502s or 400s, is it glitching or has your network been risk-controlled? Guessing is useless, run a test first:

ipcheck is a little network diagnostic tool I wrote before, one command tests IP / DNS / proxy / risk control, directly telling you if the current network can cleanly connect to the official API.

  • If it tests out a sea of red / yellow (DNS pollution, proxy recognized, risk control hit) → Don't hesitate, go third-party, saving N times of metaphysical troubleshooting later
  • If it tests out a sea of green → Honestly use official, don't tinker with a set of environment variables just to save that bit of money

💡 One-sentence summary: Third-party models trade "money saving + domestic direct connect" for "coding ceiling + official support"; heavy users and domestic direct connect party should switch, subscription party and hardcore refactoring party don't join the fun.


03 Hands-on: Connect DeepSeek into Claude Code

Okay, assuming you have confirmed to switch. This section gives a set of configurations you can copy and run.

Below uses DeepSeek as an example (most worry-free domestically). Connecting other third-party models (Kimi, Zhipu, various aggregate relays...) the routine is exactly the same, just replace ANTHROPIC_BASE_URL and model names with the corresponding platform's—these two are subject to their respective official documentation.

Prerequisite: Get a DeepSeek API Key

The premise is you have installed Claude Code (if not, go back to see 02 · Installation and Usage). Then:

  1. Open DeepSeek Open Platform, register / log in
  2. Create an API Key, copy it out and save it (looks like sk-xxxxxxxx)

🔑 API Key equals your account's wallet key. Don't commit it to Git repositories, don't send it in groups, don't write it into code. Below we use environment variables to manage it, naturally staying out of code.

Step One: Configure Environment Variables

Environment variables are "a set of switches and addresses written for the system to see", Claude Code reads them upon launch to decide where to send and what model to use.

Analogy: Filling out an express shipping label. ANTHROPIC_BASE_URL is the recipient address, ANTHROPIC_AUTH_TOKEN is your ID (identity verified before mailing), and the string ANTHROPIC_*_MODEL behind is "specifying which courier to deliver". If the label is filled out correctly, the package (your request) can arrive at the correct place and be handled by the correct person.

Mac / Linux

Open terminal, execute line by line (replace <Your DeepSeek API Key> with the real Key):

bash
export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
export ANTHROPIC_AUTH_TOKEN=<Your DeepSeek API Key>
export ANTHROPIC_MODEL=deepseek-chat
export ANTHROPIC_DEFAULT_OPUS_MODEL=deepseek-chat
export ANTHROPIC_DEFAULT_SONNET_MODEL=deepseek-chat
export ANTHROPIC_DEFAULT_HAIKU_MODEL=deepseek-chat

Windows (PowerShell)

powershell
$env:ANTHROPIC_BASE_URL="https://api.deepseek.com/anthropic"
$env:ANTHROPIC_AUTH_TOKEN="<Your DeepSeek API Key>"
$env:ANTHROPIC_MODEL="deepseek-chat"
$env:ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek-chat"
$env:ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek-chat"
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL="deepseek-chat"

⚠️ About Model Names: The deepseek-chat written above is an example placeholder. DeepSeek's specific model names (and which capability tier they correspond to) are subject to DeepSeek Official Documentation, names may change when the platform upgrades, don't hardcode it blindly. The model name is the "courier ID filled on the label", if filled wrong the system won't recognize it and will error on startup.

Sequence diagram of a request from Claude Code rewritten via env vars sent to DeepSeek and returning along original path

The whole link the image above wants to express: Your instruction → Claude Code packages it into a request → BASE_URL changes the recipient address to DeepSeek → AUTH_TOKEN verifies identity → DeepSeek model calculates → Result returns to terminal along the original path. In the middle, Claude Code this "shell" hasn't changed throughout the process.

The export / $env: above are only valid in the current terminal window, close the window and they're gone—this is the first big pitfall for beginners: "I clearly configured it, why doesn't it work when I reopen the terminal?"

To take effect permanently:

  • Mac (zsh, default): Append those lines of export to the end of ~/.zshrc, then execute source ~/.zshrc
  • Linux (bash): Append to the end of ~/.bashrc, execute source ~/.bashrc
  • Windows: Add user variables in "System Properties → Environment Variables", or write into PowerShell's $PROFILE

💡 One-sentence summary: Connecting DeepSeek = get Key + configure a set of environment variables (address + ID + model name); temporary export becomes invalid when window is closed, to use long-term write it into ~/.zshrc.


04 Verification: Did It Actually Connect

Don't rush to use it after configuring, verify first. If you start working without verifying, it's very likely you write for a long time only to find the request is actually still going official, not switched over at all—wasting time for nothing.

Verification is just one command. Enter any project directory, launch Claude Code, type /status:

bash
cd /path/to/your-project
claude

After entering, type in the dialogue box:

/status

If connected, you will see a few lines like this in the output (pay attention to Base URL and Model):

Base URL: https://api.deepseek.com/anthropic
Model: deepseek-chat

Seeing the Base URL change to DeepSeek's address means the "engine" has really been swapped. /status simultaneously displays your account information and current model, which is the fastest means to troubleshoot this type of problem—the official documentation also specifically calls it out to "verify your proxy and gateway configuration has been applied correctly."

If it still displays the official address, or directly reports an error, troubleshoot these high-frequency reasons item by item:

PhenomenonHighly Probable ReasonHow to Fix
Base URL is still officialEnv vars didn't take effect (maybe opened new terminal)Re-source, or confirm written into config file
Errors model does not exist on startupModel name typo / platform renamed itCheck DeepSeek official docs for latest model name
401 / Authentication failedAPI Key wrong or expiredRegenerate Key, check if extra space was copied
Prompts to log into claude.aiClient still wants to go official loginSee explanation below

A separate word on the last item: Under some third-party access scenarios, Claude Code may still pop up official login prompts upon startup. The common solution is to modify ~/.claude.json, add a line "hasCompletedOnboarding": true to skip the onboarding. This belongs to an experimental bypass, not the standard practice recorded in the official documentation, behavior may change in new versions—don't touch it if you can help it, try only if truly stuck.

💡 One-sentence summary: A glance at Base URL in /status tells you if it's connected; if it doesn't connect don't guess blindly, go through the troubleshooting table item by item.


05 Advanced: Layered Model Usage, Save Money Without Dropping the Ball

This section is the most valuable trick, and also the concrete landing of "mix and use" mentioned in section 02.

Remember that bunch of ANTHROPIC_*_MODEL variables in Section 01? They are not filled repeatedly at random—internally, Claude Code divides tasks into three tiers, and you can assign different models to each tier.

VariableOfficial MeaningWhat work fits here
ANTHROPIC_DEFAULT_OPUS_MODELModel resolved by opus aliasMost complex: architecture design, hard debugging
ANTHROPIC_DEFAULT_SONNET_MODELModel resolved by sonnet aliasDaily: writing features, modifying code
ANTHROPIC_DEFAULT_HAIKU_MODELModel for haiku alias / bg features (like auto titles)Lightweight: quick Q&A, bg chores
CLAUDE_CODE_SUBAGENT_MODELModel used by all subagents / agent teamsSub-tasks, recommend giving cheap and fast

All meanings above come from the official "Model Configuration" documentation. This mechanism is not exclusive to DeepSeek, it is native to Claude Code—when connecting a third party, you are just pointing these aliases to third-party models.

Analogy: Restaurant scheduling. The head chef (strongest model) has high wages, only let him cook signature hard dishes; home-style stir-fries are handed to ordinary chefs (mid-tier models); things like serving tea, pouring water, washing veggies (bg chores, subtasks) just dispatch apprentices (cheap fast models). Using the head chef for the whole shop? The dishes are delicious, but you can't afford the payroll.

So the truly playful configuration is not "filling one model for everything", but layering—suppose a certain platform has both "strong reasoning type" and "fast and cheap type" models simultaneously:

bash
# Complex tasks use strong one
export ANTHROPIC_DEFAULT_OPUS_MODEL=<Strong Reasoning Model Name>
export ANTHROPIC_DEFAULT_SONNET_MODEL=<Strong Reasoning Model Name>
# Lightweight tasks and subagents use cheap fast one, saving money
export ANTHROPIC_DEFAULT_HAIKU_MODEL=<Fast & Cheap Model Name>
export CLAUDE_CODE_SUBAGENT_MODEL=<Fast & Cheap Model Name>

The advantage of configuring this way: when you switch to the "heavy tier" with /model opus in Claude Code, it runs the strong model; usually it defaults to running the cheap one; high-frequency background calls like subagents automatically go to the cheapest one—the bill goes down immediately.

There is also a variable CLAUDE_CODE_EFFORT_LEVEL controlling "thinking depth", officially supporting low / medium / high / xhigh / max / auto (auto means reverting to model default tier; exactly which tiers are available depends on the model). If you want the model to think a bit longer and have steadier results, you can turn it up; if you want to save tokens and need speed, turn it down.

A handy setup: Fill cheap model for default tiers + effort to medium for daily runs, when encountering tough bones, manually cut to heavy tier with /model + temporarily pull effort to high. Built this way, the API bill per month gets cut to about a third of original, daily feel is almost no difference.

💡 One-sentence summary: Don't fill one model for all tiers—rough work to cheap, hard work to strong, subagents go cheapest, after layering you can have both savings and quality.


06 Two Pitfalls Beginners Must Hit

Finally, pull out two pitfalls beginners universally fall into, and specifically talk about them.

Pitfall One: Copied Variables Already Deprecated by Official

Online (including in some tutorial "reference configuration" tables) you will see a variable ANTHROPIC_SMALL_FAST_MODEL, used to specify that "fast small model".

This variable has already been marked "deprecated" by the official, the rightful owner is ANTHROPIC_DEFAULT_HAIKU_MODEL. When many people configured for the first time they copied ANTHROPIC_SMALL_FAST_MODEL following old tutorials; although it could still run at the time, they were always unsure—flipping through the official "Environment Variables" documentation will reveal it has been replaced.

Conclusion: New configurations should uniformly use ANTHROPIC_DEFAULT_HAIKU_MODEL, when seeing ANTHROPIC_SMALL_FAST_MODEL in old tutorials replace it directly, don't keep it.

Pitfall Two: Can't Tell Apart AUTH_TOKEN and API_KEY

When connecting a third-party model, which variable is used for authentication? These two look similar but behave completely differently—look directly at the official statement:

VariableOfficial BehaviorWhich to use for Third-Party
ANTHROPIC_AUTH_TOKENSent as Authorization header, value auto-prefixed with Bearer Use this for DeepSeek etc. third-party
ANTHROPIC_API_KEYSent as X-Api-Key header; in non-interactive mode (-p) forced to use if existsUse when going through official Anthropic API

Why is ANTHROPIC_AUTH_TOKEN recommended for third parties? Because compatible interfaces like DeepSeek go through the standard Authorization: Bearer <key> set, which exactly matches. This is also why community solutions and actual testing all use ANTHROPIC_AUTH_TOKEN.

There is also an associated small pitfall to keep in mind: the official documentation explicitly states, when ANTHROPIC_BASE_URL points to a "non-first-party host" (that is, non-official address), MCP tool discovery will be turned off by default. Simply put—after connecting a third party, some advanced features relying on the official might behave differently or even be unusable. This echoes the phrase in section 02 "experimental, no one to catch you". You probably won't use it in daily programming, but if you heavily rely on MCP, keep this in mind.

💡 One-sentence summary: Look for ANTHROPIC_AUTH_TOKEN for authentication, ANTHROPIC_DEFAULT_HAIKU_MODEL for small model; directly replace deprecated variables from old tutorials, after connecting third-party some advanced features will shrink.


07 Summary

This article accomplished one thing: Swapping Claude Code's "brain" from official Claude to a cheaper third-party model.

Stringing the key points:

LinkKey Action
Think ClearlyOnly heavy users / domestic direct connect party worth switching, subscription party don't tinker
ConnectConfigure ANTHROPIC_BASE_URL + ANTHROPIC_AUTH_TOKEN + model name
Verify/status see if Base URL changed
Save ThoroughlyLayer models, rough work cheap, hard work strong, subagent cheapest
Avoid PitsDon't use deprecated ANTHROPIC_SMALL_FAST_MODEL; auth uses AUTH_TOKEN

You should now be able to: independently connect DeepSeek (or any third-party model compatible with Anthropic protocol) into Claude Code, verify connection, and configure hierarchically by task to drive down the bill.

Emphasizing that counter-intuitive phrase again: This is a money-saving method, not a required course. Whether it's worth tinkering depends on whether you are really feeling pain for the API bill—for most light users, honestly using the official is perfectly fine.


Next article 06 · Coding Plan: Subscriptions and Billing—Since this article kept talking about "saving money", let's calculate the bill to the end: Between Claude's subscription plans (Pro / Max) and pay-as-you-go API, which one is actually worth it? Leaving you a question to think about first: If you heavily use Claude Code every day, should you buy a subscription, or is connecting a third-party API cheaper? After reading the next article, you'll have the answer.