# Claude Code

## Keeps asking you to sign in, or shows Not logged in · Please run /login

Other common errors are `Unable to connect to Anthropic services` and `Claude Code might not be available in your country`. The cause is that the first-run setup didn't pick up your config and connected to the official service instead.

1. Write `ANTHROPIC_BASE_URL` and `ANTHROPIC_AUTH_TOKEN` into `env` in `~/.claude/settings.json` (see [Claude Code](https://docs.2api.dev/en/clients/claude-code/) for the format). Don't put them only in the project's `.claude/settings.json`.
2. Open `~/.claude.json` (not `settings.json`) and add `"hasCompletedOnboarding": true` at the top level.
3. Reopen your terminal and start `claude`. Type `/status`. If you see both the Anthropic base URL and Auth token lines, it is correct.

## Shows Invalid API key · Please run /login, or API Error: 401

2api rejected the key. Check these in order:

1. Run the [self-check command](https://docs.2api.dev/en/faq/#do-this-first) first. If curl also returns 401, the key itself is the problem. Copy it again from the console and don't include spaces.
2. If curl works but Claude Code reports an error, Claude Code isn't reading this key. When the same variable is set both in `env` in `settings.json` and with `export` in the terminal, `settings.json` wins. Check whether it holds an old key.
3. A malformed `settings.json` (comments, an extra comma) means only part of it is read. Check it with `jq . ~/.claude/settings.json`.
4. Too many wrong attempts in a short time cause a temporary block with `Too many invalid authentication attempts`. Wait a few minutes, then try again with the correct key.

## Shows Auth conflict, or the key you set has no effect

Both `ANTHROPIC_AUTH_TOKEN` and `ANTHROPIC_API_KEY` are set, or you signed in to an official account before.

- Keep only `ANTHROPIC_AUTH_TOKEN`. Run `unset ANTHROPIC_API_KEY` and remove it from `~/.zshrc`, `~/.bashrc` or the Windows environment variables.
- If you only use 2api, run `/logout` in Claude Code to sign out of the official account.
- To go back to the official service, delete `ANTHROPIC_BASE_URL` and both key variables.

## Shows There's an issue with the selected model

The model named in the error isn't in your group. It is often the small model, such as haiku, that is used for background tasks. Look up the models your group has with [`/v1/models`](https://docs.2api.dev/en/start/endpoints/#model-names), then set `ANTHROPIC_DEFAULT_HAIKU_MODEL` and `CLAUDE_CODE_SUBAGENT_MODEL` as described on the [Claude Code page](https://docs.2api.dev/en/clients/claude-code/#model-not-found-in-background-tasks).

## Balance drops fast, and caching doesn't seem to work

Old versions of Claude Code have a much lower cache hit rate with a custom address. Run `claude update` to upgrade to the latest version first. If that doesn't help, add `"CLAUDE_CODE_ATTRIBUTION_HEADER": "0"` to `env` in `settings.json`. You can check the cache-related columns in Usage Records (使用记录) to confirm the effect.

## Timeouts, or the reply stops halfway

Errors look like `Request timed out`, `No response from API` or `Server error mid-response`.

- Raise the timeout in `env`: `"API_TIMEOUT_MS": "900000"`.
- If a reply stops partway, just reply with "continue".
- Check your proxy settings. See [Network and error codes](https://docs.2api.dev/en/faq/network/).
- If a large request returns 504 every time, it is a server-side timeout. Contact support and include the time.

## 400 error: Extra inputs are not permitted, or anthropic-beta related

Add `"CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1"` to `env` in `settings.json` and restart.

## WebFetch fails with Unable to verify if domain is safe to fetch

Before Claude Code fetches a web page, it first runs a check against the official service. If your network can't reach the official service, the check fails. Add `"skipWebFetchPreflight": true` at the top level of `~/.claude/settings.json` (not inside `env`).

## After changing keys or providers, every request fails with Invalid signature in thinking block

The session history contains thinking content signed by another upstream. Run `/clear` or start a new session.

## PowerShell says it can't find the claude command

Claude Code isn't installed, or the install path hasn't taken effect yet. Run `irm https://claude.ai/install.ps1 | iex` to install it, then **reopen** PowerShell and run `claude --version`.

## The VS Code extension keeps asking you to sign in

See [Claude Code extension](https://docs.2api.dev/en/clients/claude-code-ide/#the-extension-keeps-asking-you-to-sign-in). Add `claudeCode.environmentVariables` and `claudeCode.disableLoginPrompt` to the editor settings.