Claude Code
Use Onefast API in Claude Code, Anthropic's official command-line coding assistant.
1. Install
Shell
npm install -g @anthropic-ai/claude-code@latest
Requires Node.js 18 or later.
2. Configure
Edit (or create) ~/.claude/settings.json. On Windows the path is %USERPROFILE%\.claude\settings.json:
~/.claude/settings.json
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.onefast.ai",
"ANTHROPIC_AUTH_TOKEN": "sk-xxx",
"CLAUDE_CODE_ATTRIBUTION_HEADER": "0",
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
}
}
- Set
ANTHROPIC_BASE_URLto the root URL — without/v1. - Set
ANTHROPIC_AUTH_TOKENto your key. We recommend creating a dedicated key for Claude Code with Claude groups selected.
You can also configure it temporarily with environment variables:
macOS / Linux
export ANTHROPIC_BASE_URL="https://api.onefast.ai"
export ANTHROPIC_AUTH_TOKEN="sk-xxx"
claude
Windows PowerShell
$env:ANTHROPIC_BASE_URL = "https://api.onefast.ai"
$env:ANTHROPIC_AUTH_TOKEN = "sk-xxx"
claude
3. Verify
Shell
claude -p "Introduce yourself in one sentence."
If you get a normal reply, you're set. In the interactive UI, use /model to switch models (e.g. claude-opus-4-8, claude-sonnet-4-6).
Troubleshooting
It still asks me to log in / isn't using my key
If you have ever logged in to an Anthropic account (Claude Pro/Max) on this machine, the locally saved login credentials take precedence over ANTHROPIC_AUTH_TOKEN. Run /logout in Claude Code and try again, or give it a separate config directory:
Shell
export CLAUDE_CONFIG_DIR="$HOME/.claude-api"
On macOS, also check whether a leftover CLAUDE_CODE_OAUTH_TOKEN environment variable exists in your terminal; if so, run unset CLAUDE_CODE_OAUTH_TOKEN.
401 / 403 errors
- 401: the key is wrong or deleted — check
ANTHROPIC_AUTH_TOKEN. - 403
has no access to model: the key has a model allowlist; add the Claude models to it. - See Errors for more.
Long tasks disconnect midway
Claude Code can go a long time without output while it thinks. This is normal; the gateway keeps the connection open for up to 10 minutes. If you get disconnected often, check the idle timeout of your local proxy or corporate network.