---
title: "Claude Code Integration"
description: "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."
headingIds: {"Shortest Path":"section-1","Full Steps":"section-2","Why Use ANTHROPIC_AUTH_TOKEN":"section-3","Model Mapping":"section-4","VS Code Extension":"section-5","Optional Settings":"section-6","FAQ":"section-7"}
---

<aside className="docs-publication" data-pagefind-ignore>

Documentation maintained by [1ZheAI](https://1zheai.com/en/editorial/#publisher). [Sources and corrections](https://1zheai.com/en/editorial/).

Found an error? [Contact support](mailto:support@1zheai.com) with the page address and a description. Do not send API keys or account credentials.

</aside>
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

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`:

```json title="~/.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.

## Full Steps

<Steps>
<Step title="Install Claude Code">

If already installed, you can skip this. The following commands come from [Claude Code official installation docs ](https://code.claude.com/docs/en/setup):

<CodeGroup>
```bash title="macOS / Linux"
curl -fsSL https://claude.ai/install.sh | bash
```
```powershell title="Windows PowerShell"
irm https://claude.ai/install.ps1 | iex
```
```bash title="Homebrew"
brew install --cask claude-code
```
```bash title="npm（需要 Node.js 22+）"
npm install -g @anthropic-ai/claude-code
```
</CodeGroup>

When installing with npm, do not add `sudo`.

</Step>
<Step title="Get an API key">

Create a new API key in the [console ](https://1zheai.com/console?lng=en); it is recommended to dedicate one specifically for Claude Code on this machine. See [Obtaining and Managing API Keys ](/en/docs/api-keys/).

</Step>
<Step title="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`.

<CodeGroup>
```json title="settings.json（推荐）"
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://1zheai.com",
    "ANTHROPIC_AUTH_TOKEN": "sk-你的Key"
  }
}
```
```bash title="macOS / Linux 环境变量"
# 写进 ~/.zshrc 或 ~/.bashrc，然后重开终端
export ANTHROPIC_BASE_URL="https://1zheai.com"
export ANTHROPIC_AUTH_TOKEN="sk-你的Key"
```
```powershell title="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"
```
```bat title="Windows CMD"
setx ANTHROPIC_BASE_URL "https://1zheai.com"
setx ANTHROPIC_AUTH_TOKEN "sk-你的Key"
```
</CodeGroup>

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

</Step>
<Step title="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 ](/en/docs/usage-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
```

</Step>
</Steps>

## Why Use ANTHROPIC_AUTH_TOKEN

Claude Code has two variables that can hold the API key; the difference is as follows ([official explanation ](https://code.claude.com/docs/en/authentication)):

| 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 `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`.

## 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` |

```json title="~/.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 ](/en/docs/models/). While running, you can also use `/model claude-opus-5-5` to switch temporarily.

## 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)):

```json title="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.

## 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 ](/en/docs/models/).

Do not set `DISABLE_PROMPT_CACHING`; it will turn off caching and the bill will noticeably increase, see [Prompt Caching ](/en/docs/prompt-caching/).

## FAQ

<AccordionGroup>
<Accordion title="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).

</Accordion>
<Accordion title="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 ](/en/docs/troubleshooting/).

</Accordion>
<Accordion title="404">

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

</Accordion>
<Accordion title="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`.

</Accordion>
<Accordion title="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 ](/en/docs/quickstart-cc-switch/); one click to switch.

</Accordion>
<Accordion title="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.

</Accordion>
</AccordionGroup>
