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.
Shortest Path
Section titled “Shortest Path”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:
{ "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.
Full Steps
Section titled “Full Steps”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 | bashWindows PowerShell irm https://claude.ai/install.ps1 | iexHomebrew brew install --cask claude-codenpm(需要 Node.js 22+) npm install -g @anthropic-ai/claude-codeWhen installing with npm, do not add
sudo.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 .
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"}}macOS / Linux 环境变量 # 写进 ~/.zshrc 或 ~/.bashrc,然后重开终端export ANTHROPIC_BASE_URL="https://1zheai.com"export ANTHROPIC_AUTH_TOKEN="sk-你的Key"Windows PowerShell # 持久写入当前用户,重开终端后生效[Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL", "https://1zheai.com", "User")[Environment]::SetEnvironmentVariable("ANTHROPIC_AUTH_TOKEN", "sk-你的Key", "User")# 只在当前窗口生效$env:ANTHROPIC_BASE_URL = "https://1zheai.com"$env:ANTHROPIC_AUTH_TOKEN = "sk-你的Key"Windows CMD setx ANTHROPIC_BASE_URL "https://1zheai.com"setx ANTHROPIC_AUTH_TOKEN "sk-你的Key"Fill
ANTHROPIC_BASE_URLwith the root address; do not add/v1, Claude Code will append/v1/messagesitself.Launch and confirm
Run
claudein 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- The base URL line shows
Why Use ANTHROPIC_AUTH_TOKEN
Section titled “Why Use ANTHROPIC_AUTH_TOKEN”Claude Code has two variables that can hold the API key; the difference is as follows (official explanation ):
| Variable | How Sent | Behavior |
|---|---|---|
ANTHROPIC_AUTH_TOKEN | Authorization: Bearer <值> | Takes effect immediately once set, no confirmation prompt |
ANTHROPIC_API_KEY | x-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
envinsettings.jsonand 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.
Model Mapping
Section titled “Model Mapping”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.
| Variable | Purpose | Example Value |
|---|---|---|
ANTHROPIC_MODEL | Model used at startup | claude-sonnet-5-5 |
ANTHROPIC_DEFAULT_OPUS_MODEL | Model the opus alias points to | claude-opus-5-5 |
ANTHROPIC_DEFAULT_SONNET_MODEL | Model the sonnet alias points to | claude-sonnet-5-5 |
ANTHROPIC_DEFAULT_HAIKU_MODEL | Model for the haiku alias and background tasks | claude-haiku-5-5 |
ANTHROPIC_DEFAULT_FABLE_MODEL | Model the fable alias points to | claude-fable-5-1 |
{ "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.
VS Code Extension
Section titled “VS Code Extension”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)):
{ "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.
Optional Settings
Section titled “Optional Settings”| Variable | Purpose |
|---|---|
API_TIMEOUT_MS | Request timeout, default 600000 (10 minutes); long tasks that easily time out can be increased |
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 | Turns 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=1 | Used when encountering 400 errors like “Extra inputs are not permitted” |
CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 | Lets 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.
