Skip to main content

Claude Code x UniKey setup guide

Claude Code can use UniKey through the Anthropic-compatible Messages API. UniKey Relay is built on NewAPI, and the Claude Code configuration should point to the UniKey base URL:

ANTHROPIC_BASE_URL=https://www.getunikey.ai
ANTHROPIC_AUTH_TOKEN=<your UniKey API key>
ANTHROPIC_MODEL=claude-sonnet-4-6

1. Install Claude Code​

macOS / Linux / WSL​

Open Terminal:

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

Restart the terminal, then verify:

claude --version

Windows PowerShell​

Open PowerShell:

irm https://claude.ai/install.ps1 | iex

Close and reopen PowerShell, then verify:

claude --version

npm alternative​

If you already have Node.js 18+:

npm install -g @anthropic-ai/claude-code
claude --version

2. Create a UniKey API key​

  1. Open https://www.getunikey.ai/.
  2. Log in.
  3. Open the API key or token page.
  4. Create an API key.
  5. Store it securely.

3. Configure with settings.json​

This is the easiest configuration because it does not modify your global shell profile.

SystemFile path
macOS/Users/<your-name>/.claude/settings.json
Linux / WSL/home/<your-name>/.claude/settings.json
WindowsC:\Users\<your-name>\.claude\settings.json

Create the .claude folder if it does not exist.

macOS/Linux/WSL:

mkdir -p ~/.claude
nano ~/.claude/settings.json

Windows PowerShell:

New-Item -ItemType Directory -Force "$env:USERPROFILE\.claude"
notepad "$env:USERPROFILE\.claude\settings.json"

Paste this JSON and replace sk-... with your UniKey API key:

{
"env": {
"ANTHROPIC_AUTH_TOKEN": "sk-...",
"ANTHROPIC_BASE_URL": "https://www.getunikey.ai",
"ANTHROPIC_MODEL": "claude-sonnet-4-6",
"API_TIMEOUT_MS": "3000000"
}
}

Save the file and restart the terminal.

4. Configure with environment variables​

Use this if you prefer shell-level configuration.

macOS zsh​

Edit:

nano ~/.zshrc

Add:

export ANTHROPIC_BASE_URL="https://www.getunikey.ai"
export ANTHROPIC_AUTH_TOKEN="sk-..."
export ANTHROPIC_MODEL="claude-sonnet-4-6"

Reload:

source ~/.zshrc

Linux bash​

Edit:

nano ~/.bashrc

Add:

export ANTHROPIC_BASE_URL="https://www.getunikey.ai"
export ANTHROPIC_AUTH_TOKEN="sk-..."
export ANTHROPIC_MODEL="claude-sonnet-4-6"

Reload:

source ~/.bashrc

Windows PowerShell​

Edit your PowerShell profile:

notepad $PROFILE

Add:

$env:ANTHROPIC_BASE_URL = "https://www.getunikey.ai"
$env:ANTHROPIC_AUTH_TOKEN = "sk-..."
$env:ANTHROPIC_MODEL = "claude-sonnet-4-6"

Reload:

. $PROFILE

5. Run Claude Code​

claude

Ask:

Reply with one sentence saying Claude Code is connected through UniKey.

If it responds, the configuration is working.

6. Switch models​

Temporary switch for the current command:

ANTHROPIC_MODEL=claude-opus-4-6 claude

Windows PowerShell:

$env:ANTHROPIC_MODEL = "claude-opus-4-6"; claude

Permanent switch: update ANTHROPIC_MODEL in settings.json, ~/.zshrc, ~/.bashrc, or $PROFILE, then restart the terminal.

  • claude-sonnet-4-6
  • claude-sonnet-4-5
  • claude-opus-4-6
  • claude-opus-4-5
  • claude-haiku-4-5
  • gpt-5.2
  • gpt-5.4
  • gpt-5.4-mini
  • gpt-5.5
  • deepseek-v3.2
  • kimi-k2.5

Claude Code depends on reliable tool-use behavior. If one model fails during coding tasks, switch to a Claude-compatible model first.

Troubleshooting​

SymptomFix
claude command not foundRestart the terminal. If still failing, reinstall Claude Code.
401 unauthorizedCheck ANTHROPIC_AUTH_TOKEN; remove extra spaces and quotation mistakes.
403 access deniedConfirm the account has access to the selected model and enough credits.
Request timeoutKeep API_TIMEOUT_MS high, then retry on a stable network.
Wrong modelRun /status inside Claude Code and check ANTHROPIC_MODEL.
Settings not appliedConfirm the file path is exactly ~/.claude/settings.json or %USERPROFILE%\.claude\settings.json, then restart the terminal.