Using Domestic LLM APIs with AI Coding Assistants: Claude Code Setup, Base URL Configuration, and Anthropic-Compatible Endpoints

    AI coding assistants are only as capable as the model API behind them. This article explains how to keep your assistant and point it at a China-based LLM API, such as ERNIE on Baidu AI Cloud Qianfan, DeepSeek, Qwen on Alibaba Cloud, or GLM from Zhipu AI. It covers installing Claude Code with npm (Node.js 18+ and registry setup), getting API credentials, configuring the Base URL, API key, and model, connecting an Anthropic-compatible client such as Claude Code to a non-Anthropic endpoint, verifying connectivity with curl, troubleshooting common errors, managing API keys, costs, and rate limits, and choosing a model.

    1. Two Hurdles: Calling a China-Based LLM API and Installing an AI Coding Assistant

    AI coding assistants are now part of everyday development. However, questions like “How do I connect a China-based LLM API?”, “How do I install and configure an AI coding assistant in China?”, and “How do I point a CLI assistant at a domestic model?” still stop many beginners and small teams. The obstacles usually aren’t the operations themselves. They fall into two areas:

    • Network access: Many official install scripts are hosted on domains outside China. Direct connections from China often time out, get reset, or fail partway through a download. When you install through a package manager instead, the default registry may also be slow or fail.
    • Paid access: Many services based outside China require a subscription. Even the lowest tier can be a significant monthly cost, and payment often requires a credit card issued outside China. For individuals and small teams, this is a real cost and payment barrier.

    This article has two goals: get the tools running on a network in China, and replace the backend model with a China-based LLM API. These APIs can be reached directly from within China and are billed per usage.

    2. The Approach: Keep the Tool, Swap Only the Backend Model

    It helps to separate two layers:

    • The client: the AI coding assistant you type commands into, read code with, and ask for suggestions.
    • The model API: the backend the client calls, which provides the actual intelligence.

    By default, the client sends requests to a service based outside China. That creates both the network problem and the subscription cost.

    The approach is straightforward. Keep using the client as usual, and point its requests from the service outside China to a China-based LLM API instead. This solves three problems at once:

    • Direct network access
    • A usable payment method
    • Pay-as-you-go billing

    Your workflow stays essentially the same, and you pay based on actual usage.

    One important caveat: not every tool supports a custom Base URL. Before choosing a tool, check that it offers something like “custom API endpoint / Base URL / OpenAI-compatible API / Anthropic-compatible API.” Without that, you can’t make the switch.

    About the examples in this article: the examples use the CLI tool Claude Code (npm package @anthropic-ai/claude-code) with Baidu AI Cloud Qianfan. For other tools and providers, apply the same steps with the corresponding package name, endpoint, and model name.

    The path has four steps:

    1. Set up the local runtime (Node.js 18+) and check your npm registry.
    2. Install the client from a mirror (Claude Code in the examples).
    3. Get China-based LLM API credentials (configure a sub-account and budget alerts first).
    4. Switch the endpoint and verify connectivity with curl.

    3. Step 1: Install Node.js 18+ and Check Your npm Registry

    Most CLI assistants run on Node.js, which must be version 18 or higher. Older versions cause errors during installation or at runtime. In China, you can download installers faster from the npmmirror mirror:

    • Go to https://npmmirror.com/mirrors/node/ and choose the latest version labeled LTS (Long-Term Support).
    • Download the .msi installer on Windows, the .pkg installer on macOS, or the .tar.xz archive on Linux, and follow the installer’s instructions.

    Then run these commands one after another to verify the installation:

    1. $ node -v # Expect v18.x.x or higher
    2. $ npm -v # npm ships with Node.js; any version number printed means it works
    3. $ npm config get registry # Show the current npm registry
    4. https://registry.npmjs.org/ # Usually the default official registry; you can switch to a mirror in the next step

    If your Node.js version is too old, install a newer one from the same page. If you already use nvm, run nvm install 20 && nvm use 20.

    4. Step 2: Install the AI Coding Assistant from a Mirror (Claude Code Example)

    In China, the default npm registry is often slow or unreliable. Switch to npmmirror first, then install:

    1. # Switch the npm registry to a mirror
    2. $ npm config set registry https://registry.npmmirror.com/
    3. $ npm config get registry # Should print https://registry.npmmirror.com/
    4. # Install Claude Code globally (swap in the package name for other tools)
    5. $ npm install -g @anthropic-ai/claude-code
    6. # Verify the installation
    7. $ claude --version
    8. 1.0.x (Claude Code)

    If a version number is printed, the client is ready. At this point it still points to the service outside China by default. You’ll switch that in Step 4.

    Switching registries and rolling back:

    1. # Use the official registry for this install only, without changing the global config
    2. $ npm install -g @anthropic-ai/claude-code --registry=https://registry.npmjs.org/
    3. # Fully roll back to the official registry
    4. $ npm config delete registry # Restore the default
    5. # Or set it explicitly
    6. $ npm config set registry https://registry.npmjs.org/

    If your company’s internal network sets the registry centrally through the NPM_CONFIG_REGISTRY environment variable in CI, that value overrides the global config. You’ll need to ask your administrator to change it. To see where a setting comes from, run npm config get registry --location=project.

    Offline installation: on a machine with internet access, run npm pack @anthropic-ai/claude-code to create a .tgz package. Copy it to the target machine and run npm install -g ./anthropic-ai-claude-code-x.y.z.tgz. If the package is already cached on the machine, you can add --prefer-offline (prefer the cache) or --offline (use the cache only).

    Other tool examples (swap in the package name and commands from each tool’s documentation):

    • Clients with an OpenAI-compatible API: the VS Code extensions Cline and Continue, and the Python CLI tool Aider (pip install aider-install). Their settings are usually called Base URL or OpenAI API Base.
    • Clients with an Anthropic-compatible API: Claude Code.

    5. Step 3: Get China-Based LLM API Credentials

    This step decides which provider’s models you use. The example is Baidu AI Cloud Qianfan, which offers an API that follows the OpenAI calling conventions (referred to below as OpenAI-compatible). DeepSeek, Alibaba Cloud Model Studio (Bailian, which serves Qwen), and others offer similar APIs with roughly the same workflow.

    Plan your account and permissions first (before creating any key):

    1. Register and verify your identity: Chinese cloud services generally require real-name verification. Check what the provider accepts for individual and business accounts.
    2. Use a sub-account / RAM user: don’t use the main account for day-to-day integration. It has too broad permissions, and a leak would affect the entire cloud account.
    3. Grant least privilege: give the sub-account only the permissions to call the models you need. Don’t enable unrelated permissions for storage, billing, or other services.
    4. Create a separate key per tool: give each tool or project its own key so you can disable it individually and trace its usage.
    5. Set budget and usage alerts: in the billing center, set a spending cap and threshold notifications to limit the damage if a key leaks.

    Then activate the service and create credentials:

    1. Enable the model service you need: some models must be enabled separately.
    2. Add a payment method or top up your balance: Chinese platforms generally support domestic payment methods and bill by usage, so there’s no high monthly fee to get started.
    3. Create an API key.

    In the Qianfan console, the exact menus may change, so check the current console. After logging in, go to Qianfan ModelBuilder → Application Access / API Key Management and create and view your API key. v2 API keys usually start with bce-v3/, and you place them after Authorization: Bearer when calling the API.

    The Base URL and model name are usually listed in the API documentation or on the “Online Inference / Service List” page:

    • Base URL (where requests are sent): the Qianfan OpenAI-compatible example is https://qianfan.baidubce.com/v2.
    • model name (which model answers): the example is ernie-4.5-8k-preview.

    These addresses and model names are examples only. Before integrating, use the values that are actually available to your account in the console documentation.

    DeepSeek, Alibaba Cloud Model Studio (Bailian), and Zhipu AI also publish OpenAI-compatible endpoints:

    Provider Base URL (OpenAI-compatible, example) Example model
    Baidu AI Cloud Qianfan https://qianfan.baidubce.com/v2 ernie-4.5-8k-preview
    DeepSeek https://api.deepseek.com deepseek-chat
    Alibaba Cloud Model Studio (Bailian / Qwen) https://dashscope.aliyuncs.com/compatible-mode/v1 qwen-plus
    Zhipu AI https://open.bigmodel.cn/api/paas/v4 glm-4.5

    A note on protocols: every address in the table is OpenAI-compatible. If your client only supports the Anthropic-compatible protocol (such as Claude Code), you can’t use these addresses directly. Check whether the provider offers an Anthropic-compatible endpoint, or set up protocol conversion. See Step 4 for details.

    6. Step 4: Switch the Endpoint and Verify Connectivity

    Each tool is configured differently. There are two common approaches:

    • Graphical settings: some assistants and extensions have a settings UI. Look for “custom Base URL / OpenAI-compatible / Anthropic-compatible” in the documentation, and fill in the three fields below.
    • Config file or environment variables: for example, Claude Code can use the environment variables ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN, and ANTHROPIC_MODEL, or the file ~/.claude/settings.json.

    Either way, the core is the same three values: the API base URL (Base URL), the API key, and the model identifier (model).

    Scenario A: the client supports the OpenAI-compatible API (works directly with Qianfan, DeepSeek, and others)

    1. {
    2. "api_base_url": "https://qianfan.baidubce.com/v2",
    3. "api_key": "<your API key>",
    4. "model": "ernie-4.5-8k-preview"
    5. }

    Field names depend on the tool you choose. For example, Aider uses the OPENAI_API_BASE and OPENAI_API_KEY environment variables.

    Scenario B: the client only supports the Anthropic-compatible API (such as Claude Code)

    Claude Code communicates using the Anthropic Messages protocol and sends requests to /v1/messages under the Base URL. You can’t put an OpenAI-compatible address in directly. Your options are:

    1. Use the provider’s Anthropic-compatible endpoint first: according to DeepSeek’s public documentation, DeepSeek offers an endpoint in the form https://api.deepseek.com/anthropic, the same form as Moonshot AI’s https://api.moonshot.cn/anthropic. Check the latest documentation before integrating. Enter a model identifier the endpoint supports (such as deepseek-chat), not a claude-* name.
    2. Run your own gateway for protocol conversion: use an open-source gateway such as one-api or new-api to convert the Anthropic protocol to the OpenAI protocol, and point the client’s Base URL at the gateway.
    3. Switch clients: use one of the OpenAI-compatible tools from Scenario A.

    Here’s an example with the DeepSeek Anthropic-compatible endpoint (macOS / Linux terminal):

    1. $ export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
    2. $ export ANTHROPIC_AUTH_TOKEN=<your API key>
    3. $ export ANTHROPIC_MODEL=deepseek-chat
    4. $ claude # Start Claude Code

    To make the settings permanent, add them to ~/.claude/settings.json:

    1. {
    2. "env": {
    3. "ANTHROPIC_BASE_URL": "https://api.deepseek.com/anthropic",
    4. "ANTHROPIC_AUTH_TOKEN": "<your API key>",
    5. "ANTHROPIC_MODEL": "deepseek-chat"
    6. }
    7. }

    Key points:

    • With third-party endpoints, you usually use ANTHROPIC_AUTH_TOKEN, not ANTHROPIC_API_KEY, which is for an official Anthropic account.
    • If you’ve already logged in with an official account, run /logout first to avoid credential conflicts.
    • Some tools also need a separate small/fast model setting (such as ANTHROPIC_SMALL_FAST_MODEL). Without it, you may get a “model not found” error. Check the tool’s documentation.

    Verification 1: test connectivity with curl (using the Qianfan OpenAI-compatible API as an example)

    1. $ curl -sS -w "\nHTTP %{http_code}\n" https://qianfan.baidubce.com/v2/chat/completions \
    2. -H "Authorization: Bearer <your API key>" \
    3. -H "Content-Type: application/json" \
    4. -d '{"model":"ernie-4.5-8k-preview","messages":[{"role":"user","content":"Reply with just: hello"}]}'
    • Success (HTTP 200):
    1. {
    2. "id": "as-xxxxxxxx",
    3. "object": "chat.completion",
    4. "model": "ernie-4.5-8k-preview",
    5. "choices": [
    6. {
    7. "index": 0,
    8. "message": { "role": "assistant", "content": "你好" },
    9. "finish_reason": "stop"
    10. }
    11. ],
    12. "usage": { "prompt_tokens": 9, "completion_tokens": 2, "total_tokens": 11 }
    13. }

    The call passed if choices[0].message.content is a non-empty reply, usage shows what the request consumed, and the corresponding record appears on the console’s usage dashboard.

    • Failure (HTTP 401):
    1. { "error": { "code": "invalid_api_key", "message": "Invalid API key" } }

    Verification 2: send a test prompt from the assistant

    • Claude Code: after starting it, enter /status and confirm that the Base URL and model match what you configured. Then send “Reply with just: hello.” If you get a reply from the domestic model, it’s working. If you get a connection error or a 401, go back and check your configuration.
    • GUI tools: check that the model selector shows your custom model, then send a simple question in the chat to confirm you get a response.

    7. Common Errors and Troubleshooting

    Error / Symptom Likely Cause Where to Check / Command Fix
    401 Unauthorized Wrong, incomplete, or inactive key HTTP status code from curl; key page in the console Copy the full key again (Qianfan v2 keys include the bce-v3/ prefix) and confirm it’s enabled
    403 Forbidden No real-name verification, model service not enabled, or sub-account lacks permission Service activation page and sub-account policies in the console Enable the service; grant the sub-account permission to call the model
    404 model not found Misspelled model name, or the account has no access to it “Service List / Online Inference” in the console Use the model value given in the console
    404 Not Found Base URL includes /chat/completions Path rules in the tool’s documentation Enter only the base address, not the full path
    429 Too Many Requests Rate limit hit, too many concurrent requests, or insufficient balance Rate-limit quotas and usage dashboard in the console Slow down and retry with exponential backoff; top up or request a higher quota
    Connection timeout / reset Wrong address, or a proxy or network blocking the request curl -v <Base URL>; `env \ grep -i proxy` Check the address; disable unnecessary proxies; retry on another network
    Context length exceeded Input too long, so it’s rejected or truncated Token counts in the error message Split the input, summarize it, or include fewer files
    Starts but reports connection errors Environment variables not applied or overridden by a config file macOS/Linux: `env \ grep ANTHROPIC; Windows PowerShell:dir env:ANTHROPIC_*;claude /status` Set the variables again, then restart the terminal and the tool

    8. API Key Security, Costs, and Rate Limits

    • Key security: treat an API key like an account credential. Don’t hard-code it into source code, share it in screenshots, or put it in a URL, where it can easily end up in logs. Manage it through environment variables or a local config file, and add that file to .gitignore:
    1. # Local credentials and config — never commit these
    2. .env
    3. .env.*
    4. .claude/settings.local.json
    • If a key leaks: if you suspect a leak, disable or delete the key in the console immediately and create a replacement. Also check the usage dashboard for unusual calls.
    • Costs and rate limits: pay-as-you-go billing has a low barrier to entry, but high-frequency calls still add up. Check usage and spending regularly and set budget alerts. If you hit a 429, retry with exponential backoff (for example, 1s, 2s, 4s, and so on, with a maximum number of attempts).
    • Matching capabilities: models differ in context length, code understanding, and response style. After switching, try your common commands again to see how the new model performs.
    • Version management: before upgrading Node.js or the client, read the release notes so an automatic upgrade doesn’t introduce problems.
    • Network and compliance: make sure your usage meets the provider’s compliance requirements. When handling sensitive code or data, prefer a service with a clear data compliance policy.

    9. How to Choose a Model

    All of these providers use the same API conventions, so you can compare a few domestic models before deciding:

    Task Type Context Needs Cost Sensitivity How to Test
    Inline completion, short code Small is fine; prioritize latency High Time each model on your usual set of files and compare response speed and cost
    Cross-file understanding, refactoring Needs a large context window Medium Have the model summarize how a multi-file project fits together, and see what it misses
    Complex reasoning, hard bugs Medium; prioritize capability Low Give it a real bug you’ve already fixed and see if it can locate and fix it
    Team use by multiple people Accounted for per project Medium-high Estimate per-person daily usage × price per token, and choose a tier with the quota in mind

    The takeaway: run A/B comparisons with your own real code snippets, not just published benchmarks. Use low-cost models for high-frequency completion and save higher-cost models for complex tasks, so you balance quality and cost.

    After these four steps, your AI coding assistant runs reliably on a network in China, with a pay-as-you-go, easier-to-pay China-based model behind it. The experience depends on the capabilities of the model you choose, and the cost changes with actual usage. The tool stays the same; only the model behind it changes.