Skip to content
English

Claude Code Integration

Connect Claude Code to 1折AI: use ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN (environment variables or settings.json), with Windows syntax, model mapping, VS Code extension, and common errors.

Claude Code only needs two variables: ANTHROPIC_BASE_URL points to us, and ANTHROPIC_AUTH_TOKEN is filled with your API key (API key). No Anthropic account login is required.

If you already have Claude Code installed and an API key on hand, write the following two lines into ~/.claude/settings.json, then run claude:

~/.claude/settings.json
{
"env": {
"ANTHROPIC_BASE_URL": "https://1zheai.com",
"ANTHROPIC_AUTH_TOKEN": "sk-你的Key"
}
}

If the file already exists, merge these two items into the existing env without overwriting other configuration.

  1. Install Claude Code

    If already installed, you can skip this. The following commands come from Claude Code official installation docs :

    macOS / Linux
    curl -fsSL https://claude.ai/install.sh | bash

    When installing with npm, do not add sudo.

  2. Get an API key

    Create a new API key in the console ; it is recommended to dedicate one specifically for Claude Code on this machine. See Obtaining and Managing API Keys .

  3. Configure (choose one of three)

    Location of settings.json: on macOS / Linux it is ~/.claude/settings.json, on Windows it is %USERPROFILE%\.claude\settings.json.

    settings.json(推荐)
    {
    "env": {
    "ANTHROPIC_BASE_URL": "https://1zheai.com",
    "ANTHROPIC_AUTH_TOKEN": "sk-你的Key"
    }
    }

    Fill ANTHROPIC_BASE_URL with the root address; do not add /v1, Claude Code will append /v1/messages itself.

  4. Launch and confirm

    Run claude in the project directory, and after entering, type /status. Check two lines:

    • The base URL line shows https://1zheai.com
    • The credentials line shows the source is ANTHROPIC_AUTH_TOKEN

    Then ask a question, and go to call logs to see if there is a new record. If there is, it is connected.

    If you do not want to enter the interactive interface, you can also try once in non-interactive mode (tested on 2026-10-15, returned ok):

    bash
    claude -p "say ok" --model claude-sonnet-4-6

Claude Code has two variables that can hold the API key; the difference is as follows (official explanation ):

VariableHow SentBehavior
ANTHROPIC_AUTH_TOKENAuthorization: Bearer <值>Takes effect immediately once set, no confirmation prompt
ANTHROPIC_API_KEYx-api-key: <值>In interactive mode, the first time it will pop up asking whether to use this API key

We support both; ANTHROPIC_AUTH_TOKEN is recommended. Set only one of the two: if there is still an old official ANTHROPIC_API_KEY left in the system, delete it to avoid mixing and getting 401.

Two other rules that are easy to trip over:

  • When env in settings.json and a terminal export set the same variable, settings.json takes precedence. If changing the terminal variable did not take effect, check settings.json first.
  • Do not write the API key into the project’s .claude/settings.json; this file is usually committed to the repository. To differentiate per project, use the non-committed .claude/settings.local.json.

opus, sonnet, haiku, and fable in Claude Code are aliases; you can use environment variables to specify the concrete models they map to. The Haiku tier is also used by Claude Code to run some small background tasks.

VariablePurposeExample Value
ANTHROPIC_MODELModel used at startupclaude-sonnet-5-5
ANTHROPIC_DEFAULT_OPUS_MODELModel the opus alias points toclaude-opus-5-5
ANTHROPIC_DEFAULT_SONNET_MODELModel the sonnet alias points toclaude-sonnet-5-5
ANTHROPIC_DEFAULT_HAIKU_MODELModel for the haiku alias and background tasksclaude-haiku-5-5
ANTHROPIC_DEFAULT_FABLE_MODELModel the fable alias points toclaude-fable-5-1
~/.claude/settings.json(带模型映射)
{
"env": {
"ANTHROPIC_BASE_URL": "https://1zheai.com",
"ANTHROPIC_AUTH_TOKEN": "sk-你的Key",
"ANTHROPIC_MODEL": "claude-sonnet-5-5",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-5-5",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-5-5",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-5-5"
}
}

The model ID must be among the supported models . While running, you can also use /model claude-opus-5-5 to switch temporarily.

The Claude Code VS Code extension checks credentials before startup; the official recommendation is to write the variables in VS Code’s own user settings (Command Palette → Preferences: Open User Settings (JSON)):

VS Code settings.json
{
"claudeCode.environmentVariables": [
{ "name": "ANTHROPIC_BASE_URL", "value": "https://1zheai.com" },
{ "name": "ANTHROPIC_AUTH_TOKEN", "value": "sk-你的Key" }
]
}

When only written in ~/.claude/settings.json, the extension’s own login check may not read them.

VariablePurpose
API_TIMEOUT_MSRequest timeout, default 600000 (10 minutes); long tasks that easily time out can be increased
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1Turns off non-essential traffic such as auto-update, telemetry, and error reporting. Note that setting it to 0 or false also counts as enabled; to turn it off you must delete this variable
CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1Used when encountering 400 errors like “Extra inputs are not permitted”
CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1Lets the /model list fetch available models from /v1/models

CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 has been tested and works (Claude Code 2.1.296, 2026-10-15): after startup, [gatewayDiscovery] cached 14 models appears in the debug log, and the 14 models match the supported models .

Do not set DISABLE_PROMPT_CACHING; it will turn off caching and the bill will noticeably increase, see Prompt Caching .

Login screen appears on launch / prompt says Please run /login

Claude Code did not read the API key. Check the variable name spelling; if using environment variables, confirm you started in a newly opened terminal; if using settings.json, confirm the JSON format is correct (one extra comma will make the whole thing fail).

401 / Invalid API key

The API key was copied incompletely, or ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN both exist and one of them is an old value. Keep only one of the two. See more in error codes and troubleshooting .

404

ANTHROPIC_BASE_URL has an extra /v1 written. Change it to https://1zheai.com.

Opus selected, but logs show Haiku calls

This is Claude Code running small background tasks with the Haiku tier. To switch to another model, set ANTHROPIC_DEFAULT_HAIKU_MODEL.

How do I switch between my official account and 1折AI?

Delete (or comment out) the two variables above to return to official login. If you switch often, use CC Switch ; one click to switch.

Will using 1折AI affect my Anthropic account?

No association will be created. When connecting to 1折AI, Claude Code uses our API key and does not log in to your Anthropic account.