Using Claude Code with Chinese LLMs via Anthropic-Compatible Endpoints

    This guide shows how to configure Claude Code to use Chinese LLM providers through Anthropic-compatible endpoints. It covers prerequisites, installation, environment variables, `settings.json` configuration, and API key protection.

    1. Scope and Prerequisites

    This article uses Claude Code as an example. It is a command-line coding assistant that can read project files, execute commands, and generate code changes. Other tools follow a similar approach, but configuration key names and file paths differ. Check the official documentation for the specific tool before applying this setup.

    To make Claude Code use Chinese LLMs, the provider must offer an endpoint compatible with the Anthropic Messages API protocol. A common approach is for the provider to publish a dedicated URL, for example a path ending in /anthropic.

    If the provider only offers an OpenAI-compatible API, you need to deploy an additional protocol conversion layer. This layer adds an extra network hop and another set of keys to manage. When choosing one, confirm that it supports streaming output and tool calling, because Claude Code relies on tool calling to read and write files and execute commands. The deployment method for a conversion layer is not covered here, but the same testing principles apply.

    Endpoint addresses, model names, and prices change with providers. Before use, refer to the provider’s and Claude Code’s official documentation.

    2. Environment Preparation

    Before starting, confirm the following conditions.

    Check Requirement Command (macOS / Linux) Command (Windows PowerShell)
    Node.js Version 18 or later node -v node -v
    npm Installed with Node.js npm -v npm -v
    Package source connectivity Can access the official npm registry or a corporate mirror curl -I https://registry.npmjs.org curl.exe -I https://registry.npmjs.org
    System permissions Can write to the npm global directory See Section 3 See Section 3

    For corporate networks that require a proxy, set proxy variables in the terminal. PowerShell example:

    1. $env:HTTPS_PROXY = "http://proxy.example.com:8080"
    2. npm config set registry https://mirror.example.com/npm/

    Proxy and mirror addresses are provided by the corporate network administrator. On macOS and Linux, set the proxy with export HTTPS_PROXY=...; the mirror command is the same.

    3. Installation Steps

    Run the steps in order and verify each result.

    1. Global installation: run npm install -g @anthropic-ai/claude-code.
    2. Verify the version: run claude --version. The terminal should output a version number, for example 2.x.x (Claude Code).
    3. If an EACCES permission error appears, do not use sudo directly. Recommended options are to manage Node.js with nvm (nvm-windows on Windows), or switch the npm global directory to a user directory. Installing global packages as an administrator expands the risk surface and makes cleanup harder when problems occur.

    After installation succeeds, do not run claude and enter the default login flow yet. Complete the model access configuration in the following sections first.

    4. Understanding Access Parameters

    Claude Code uses environment variables to determine where requests are sent, which model is used, and which credentials are used for authentication. The three most common variables are listed below.

    Variable Purpose Value Source
    ANTHROPIC_BASE_URL Address to which requests are sent The Anthropic-compatible endpoint in the provider’s documentation
    ANTHROPIC_AUTH_TOKEN Authentication credential, sent as Bearer API Key created in the provider console
    ANTHROPIC_MODEL Default model identifier Name in the provider’s model list, usually case-sensitive

    A few points to note:

    • Different versions support different variables. Some versions also read ANTHROPIC_API_KEY, which is sent with the x-api-key request header. Set only the variable that matches the provider’s authentication requirement. Setting both may cause conflicts.
    • Some versions also support variables such as ANTHROPIC_SMALL_FAST_MODEL for background small-model tasks. Newer versions may use other variable names. Refer to the official documentation for the installed version.
    • In most cases, ANTHROPIC_BASE_URL does not need to include /v1/messages; Claude Code appends the path itself. Whether /v1 is required depends on the example request URL in the provider’s documentation.

    Confirm three things in the provider console: whether the endpoint is a dedicated address compatible with the Anthropic protocol, whether the API Key is enabled, and whether the target model can be called under the current account.

    5. Writing Configuration and Protecting Keys

    Claude Code reads the user-level configuration file settings.json. Variables in the env field take effect during the session.

    Operating System Configuration File Path
    macOS / Linux ~/.claude/settings.json
    Windows %USERPROFILE%\.claude\settings.json, for example C:\Users\<username>\.claude\settings.json

    If the directory or file does not exist, create it manually. Example content is shown below; replace the angle-bracket placeholders with real values:

    1. {
    2. "env": {
    3. "ANTHROPIC_BASE_URL": "<Anthropic-compatible endpoint provided by the provider>",
    4. "ANTHROPIC_AUTH_TOKEN": "<your API Key>",
    5. "ANTHROPIC_MODEL": "<model name published by the provider>"
    6. }
    7. }

    After writing the file, validate the JSON syntax. Extra commas, curly quotation marks, and missing braces can invalidate the configuration.

    • macOS / Linux: python3 -m json.tool ~/.claude/settings.json
    • Windows PowerShell: Get-Content $env:USERPROFILE\.claude\settings.json | ConvertFrom-Json

    If the command returns without errors and outputs content, the syntax is valid. If python3 -m json.tool reports an error, it provides line numbers to help locate the issue.

    This file stores the API Key in plaintext. Handle it as follows.

    • Restrict file permissions. On macOS / Linux, run chmod 600 ~/.claude/settings.json to allow only the current user to read and write the file. On Windows, use icacls to remove inheritance and grant permissions to the current user; consult the official Windows documentation for the exact syntax.