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
- Open
https://www.getunikey.ai/. - Log in.
- Open the API key or token page.
- Create an API key.
- Store it securely.
3. Configure with settings.json
This is the easiest configuration because it does not modify your global shell profile.
| System | File path |
|---|---|
| macOS | /Users/<your-name>/.claude/settings.json |
| Linux / WSL | /home/<your-name>/.claude/settings.json |
| Windows | C:\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.
Recommended model IDs
claude-sonnet-4-6claude-sonnet-4-5claude-opus-4-6claude-opus-4-5claude-haiku-4-5gpt-5.2gpt-5.4gpt-5.4-minigpt-5.5deepseek-v3.2kimi-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
| Symptom | Fix |
|---|---|
claude command not found | Restart the terminal. If still failing, reinstall Claude Code. |
| 401 unauthorized | Check ANTHROPIC_AUTH_TOKEN; remove extra spaces and quotation mistakes. |
| 403 access denied | Confirm the account has access to the selected model and enough credits. |
| Request timeout | Keep API_TIMEOUT_MS high, then retry on a stable network. |
| Wrong model | Run /status inside Claude Code and check ANTHROPIC_MODEL. |
| Settings not applied | Confirm the file path is exactly ~/.claude/settings.json or %USERPROFILE%\.claude\settings.json, then restart the terminal. |