Claude Code defaults to using Anthropic’s official API. If you need to switch to other Anthropic-compatible providers (such as third-party proxies, self-hosted gateways, etc.), you can manually edit the configuration file. This article explains how to switch API endpoints and models by modifying local configuration files.
Prerequisites
- Claude Code is installed (see Claude Code Installation Guide)
- You have an API Key compatible with the Anthropic API
Clear Old Environment Variables
Before configuring a new API, make sure to clear any existing Anthropic-related environment variables to avoid conflicts:
unset ANTHROPIC_AUTH_TOKEN
unset ANTHROPIC_BASE_URL
If these variables are permanently exported in ~/.bashrc or ~/.zshrc, please delete the corresponding lines as well; otherwise, new shells will inject the old configuration again.
Edit Configuration File
Step 1: Edit settings.json
Edit or create the Claude Code configuration file:
- macOS / Linux:
~/.claude/settings.json - Windows:
User directory\.claude\settings.json
Write the following content into the configuration file, replacing YOUR_API_KEY and YOUR_BASE_URL with your actual values:
{
"env": {
"ANTHROPIC_BASE_URL": "YOUR_BASE_URL",
"ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
"API_TIMEOUT_MS": "3000000",
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
"ANTHROPIC_MODEL": "claude-sonnet-4-20250514",
"ANTHROPIC_SMALL_FAST_MODEL": "claude-sonnet-4-20250514",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-4-20250514",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-sonnet-4-20250514",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-3-5-20241022"
}
}
Step 2: Set Onboarding Marker
Edit or create the ~/.claude.json file:
- macOS / Linux:
~/.claude.json - Windows:
User directory\.claude.json
{
"hasCompletedOnboarding": true
}
This step skips Claude Code’s first-time onboarding flow. Without this setting, you may be directed to the official login flow on startup.
Environment Variables Reference
| Variable | Description |
|---|---|
| ANTHROPIC_BASE_URL | API endpoint address; enter the address for your proxy or compatible service |
| ANTHROPIC_AUTH_TOKEN | API Key for interface authentication |
| API_TIMEOUT_MS | Request timeout in milliseconds; 3000000 is recommended for long-running tasks |
| CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC | Set to 1 to disable telemetry and other non-essential network requests; recommended for third-party APIs |
| ANTHROPIC_MODEL | Default model name to call |
| ANTHROPIC_SMALL_FAST_MODEL | Lightweight fast model for simple tasks |
| ANTHROPIC_DEFAULT_SONNET_MODEL | Default model for Sonnet series |
| ANTHROPIC_DEFAULT_OPUS_MODEL | Default model for Opus series |
| ANTHROPIC_DEFAULT_HAIKU_MODEL | Default model for Haiku series |
Verify Configuration
After starting claude, enter the following slash commands in the TUI to confirm the configuration is applied:
/status
/model
/statusshould showANTHROPIC_BASE_URLpointing to your configured address/modelshould display the current model as the model name you configured
Project-Level Configuration
In addition to global configuration, you can create a .claude/settings.json in your project root to override global settings, enabling different projects to use different API endpoints or models:
{
"env": {
"ANTHROPIC_MODEL": "claude-opus-4-20250514"
}
}
Project-level configuration takes precedence over global configuration, making it suitable for scenarios where you need to specify different models for specific projects.
Troubleshooting
1. Still routing to Official API After Startup
Check if environment variables are being overridden by old configurations in ~/.bashrc or ~/.zshrc. Run env | grep ANTHROPIC to view current environment variables.
2. Model Unavailable
Confirm that your API Key has access permissions for the corresponding model, and that the model name matches what your API provider supports.
3. Connection Timeout
Check your network connection and verify the Base URL is correct. If using a proxy, confirm that ANTHROPIC_BASE_URL is configured correctly, and set the HTTPS_PROXY environment variable if necessary.
← Back to ArticlesManage Your AI Agents with Wishmere
Wishmere comes with a built-in Gateway proxy. You can switch between different API configurations and models with one click on the web interface without manually editing configuration files. All operations support complete logging and rollback functions.