Use Cases
| Suitable for users who want to use Claude models in the terminal for code analysis, code modification, and Agent tasks. |
|---|
| Claude Code uses the Anthropic Messages protocol. Select a Claude model from the model restriction list. Using non-Claude models such as GPT or Gemini with Claude Code is not recommended. |
|---|
Set ANTHROPIC_BASE_URL to https://api.maitoken.com without adding /v1. Claude Code will automatically send requests to https://api.maitoken.com/v1/messages . |
|---|
1. macOS / Linux Configuration
Check Claude Code: Open a terminal and run
claude --version. If the command is not found, install Claude Code by following its installation instructions.Select a Model: Copy an available Claude Model ID from the model restriction list in the MaiToken console.
Set the Gateway URL: Set
ANTHROPIC_BASE_URLto https://api.maitoken.com .Configure Authentication: Store your MaiToken Key in
ANTHROPIC_AUTH_TOKEN. Claude Code will automatically send the authentication information using theAuthorization: Bearerformat.Set the Model: Store the exact Claude Model ID in
ANTHROPIC_MODEL, and then runclaudein the same terminal window.
export ANTHROPIC_BASE_URL="https://api.maitoken.com"export ANTHROPIC_AUTH_TOKEN="<your MaiToken Key>"export ANTHROPIC_MODEL="<Claude Model ID>" claude2. Windows PowerShell Configuration
Open PowerShell and run the following commands:
$env:ANTHROPIC_BASE_URL="https://api.maitoken.com"$env:ANTHROPIC_AUTH_TOKEN="<your MaiToken Key>"$env:ANTHROPIC_MODEL="<Claude Model ID>" claudeLogin Note: When authenticating through the MaiToken gateway with ANTHROPIC_AUTH_TOKEN, you do not need to log in to Claude.ai. The directory trust confirmation displayed when you first open a project is not an account login.
| To prevent background model errors, assign available models to the model aliases used by Claude Code. Claude Code may use the sonnet, opus, and haiku aliases for different tasks. If testing produces permission errors for other models, set all the following variables to the same available Claude Model ID. |
|---|
macOS / Linux
export ANTHROPIC_DEFAULT_SONNET_MODEL="<Claude Model ID>"export ANTHROPIC_DEFAULT_OPUS_MODEL="<Claude Model ID>"export ANTHROPIC_DEFAULT_HAIKU_MODEL="<Claude Model ID>"export CLAUDE_CODE_SUBAGENT_MODEL="<Claude Model ID>"Windows PowerShell
$env:ANTHROPIC_DEFAULT_SONNET_MODEL="<Claude Model ID>"$env:ANTHROPIC_DEFAULT_OPUS_MODEL="<Claude Model ID>"$env:ANTHROPIC_DEFAULT_HAIKU_MODEL="<Claude Model ID>"$env:CLAUDE_CODE_SUBAGENT_MODEL="<Claude Model ID>"| Variable | Value |
|---|---|
ANTHROPIC_BASE_URL |
https://api.maitoken.com |
ANTHROPIC_AUTH_TOKEN |
<your MaiToken Key> |
ANTHROPIC_MODEL |
<Claude Model ID> |
| Actual Request URL | https://api.maitoken.com/v1/messages , automatically constructed by Claude Code |
Test the Configuration
Test a Basic Conversation: Enter “Reply with OK only.” If you receive a valid response, the API Key, gateway URL, and Model ID are configured correctly.
Test Project Reading: Open a test project and enter “Read the current project and list only the files at the first directory level. Do not modify any files.”
Test Agent Capabilities: After receiving the directory listing, ask the Agent to create a file named
test-maitoken.txtand writehellointo it. Do not use a real production project for testing.
Common Issues
| Issue | Solution |
|---|---|
| 401 / Unauthorized | Confirm that you are using ANTHROPIC_AUTH_TOKEN and that the variable was set in the same terminal window used to start claude. |
| 404 /v1/messages | Set ANTHROPIC_BASE_URL to https://api.maitoken.com only. Do not include /v1 or /v1/messages. |
| Model unavailable | Select the exact Claude Model ID from the model restriction list. Do not use the localized display name. |
| Claude Code calls other models after startup | Set ANTHROPIC_DEFAULT_SONNET_MODEL, ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_HAIKU_MODEL, and CLAUDE_CODE_SUBAGENT_MODEL. |
| Chat works but files cannot be modified | Confirm that the current directory is writable and that both the model and gateway fully support Anthropic tool calling and streaming output. |
