For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://modelgates.ai/docs/_mcp/server.
Claude Code
Claude Code with ModelGates is only guaranteed to work with the Anthropic first-party provider. For maximum compatibility, we recommend setting Anthropic 1P as top priority provider when using Claude Code.
Why Use ModelGates with Claude Code?
ModelGates adds a reliability and management layer between Claude Code and Anthropic's API, giving you and your organization several key benefits.
Provider Failover for High Availability
Anthropic's API occasionally experiences outages or rate limiting. When you route Claude Code through ModelGates, your requests automatically fail over between multiple Anthropic providers. If one provider is unavailable or rate-limited, ModelGates seamlessly routes to another, keeping your coding sessions uninterrupted.
Organizational Budget Controls
For teams and organizations, ModelGates provides centralized budget management. You can set spending limits, allocate credits across team members, and prevent unexpected cost overruns. This is especially valuable when multiple developers are using Claude Code across your organization.
Usage Visibility and Analytics
ModelGates gives you complete visibility into how Claude Code is being used across your team. Track usage patterns, monitor costs in real-time, and understand which projects or team members are consuming the most resources. All of this data is available in your ModelGates Activity Dashboard.
Quick Start
This guide will get you running Claude Code powered by ModelGates in just a few minutes.
Step 1: Install Claude Code
macOS, Linux, WSL:
curl -fsSL https://claude.ai/install.sh | bashWindows PowerShell:
irm https://claude.ai/install.ps1 | iexRequires Node.js 18 or newer.
npm install -g @anthropic-ai/claude-codeStep 2: Connect Claude to ModelGates
Instead of logging in with Anthropic directly, connect Claude Code to ModelGates. This requires setting a few environment variables.
Requirements:
- Use
https://modelgates.ai/apifor the base url - Provide your ModelGates API key as the auth token
- Important: Explicitly blank out the Anthropic API key to prevent conflicts
Add these environment variables to your shell profile:
# Open your shell profile in nanonano ~/.zshrc # or ~/.bashrc for Bash users # Add these lines to the file:export MODELGATES_API_KEY="<your-modelgates-api-key>"export ANTHROPIC_BASE_URL="https://modelgates.ai/api"export ANTHROPIC_AUTH_TOKEN="$MODELGATES_API_KEY"export ANTHROPIC_API_KEY="" # Important: Must be explicitly empty # After saving, restart your terminal for changes to take effectPersistence: We recommend adding these lines to your shell profile (~/.bashrc, ~/.zshrc, or ~/.config/fish/config.fish).
Alternatively, you can configure Claude Code using a project-level settings file at .claude/settings.local.json in your project root:
{ "env": { "ANTHROPIC_BASE_URL": "https://modelgates.ai/api", "ANTHROPIC_AUTH_TOKEN": "<your-modelgates-api-key>", "ANTHROPIC_API_KEY": "" }}Replace <your-modelgates-api-key> with your actual ModelGates API key.
Note: This method keeps your configuration scoped to the project, making it easy to share ModelGates settings with your team via version control (just be careful not to commit your API key).
Variable Location: Do not put these in a project-level .env file. The native Claude Code installer does not read standard .env files.
Previous Login: If you were previously logged in to Claude Code with Anthropic, run /logout in a Claude Code session to clear cached credentials before the ModelGates configuration takes effect.
Step 3: Start your session
Navigate to your project directory and start Claude Code:
cd /path/to/your/projectclaudeYou are now connected! Any prompt you send will be routed through ModelGates.
Step 4: Verify
You can confirm your connection by running the /status command inside Claude Code.
> /statusAuth token: ANTHROPIC_AUTH_TOKENAnthropic base URL: https://modelgates.ai/apiYou can also check the ModelGates Activity Dashboard to see your requests appearing in real-time.
How It Works
ModelGates exposes an input that is compatible with the Anthropic Messages API.
- Direct Connection: When you set
ANTHROPIC_BASE_URLtohttps://modelgates.ai/api, Claude Code speaks its native protocol directly to ModelGates. No local proxy server is required. - Anthropic Skin: ModelGates's "Anthropic Skin" behaves exactly like the Anthropic API. It handles model mapping and passes through advanced features like "Thinking" blocks and native tool use.
- Billing: You are billed using your ModelGates credits. Usage (including reasoning tokens) appears in your ModelGates dashboard.
Configuring Models
Claude Code uses several environment variables to determine which models to use for different tasks. You can override these to route each role through a specific model:
export ANTHROPIC_DEFAULT_OPUS_MODEL="anthropic/claude-opus-4.7"export ANTHROPIC_DEFAULT_SONNET_MODEL="anthropic/claude-sonnet-4.6"export ANTHROPIC_DEFAULT_HAIKU_MODEL="anthropic/claude-haiku-4.5"export CLAUDE_CODE_SUBAGENT_MODEL="anthropic/claude-opus-4.7"| Variable | Description |
|---|---|
ANTHROPIC_DEFAULT_OPUS_MODEL | The model used for Opus-class tasks (e.g. complex reasoning) |
ANTHROPIC_DEFAULT_SONNET_MODEL | The model used for Sonnet-class tasks (e.g. general coding) |
ANTHROPIC_DEFAULT_HAIKU_MODEL | The model used for Haiku-class tasks (e.g. quick completions) |
CLAUDE_CODE_SUBAGENT_MODEL | The model used for sub-agent tasks spawned by Claude Code |
Add these to the same shell profile or project settings file where you set ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN.
Claude Code is optimized for Anthropic models and may not work correctly with other providers.
Fast Mode
Anthropic's fast mode provides up to 2.5x faster output at premium pricing. Fast mode is only available on Claude Opus 4.6 and Claude Opus 4.7 — no other Anthropic model supports it.
For each supported Opus version, there are two equivalent ways to request fast mode on ModelGates:
- Send
speed: "fast"withanthropic/claude-opus-4.7oranthropic/claude-opus-4.6— ModelGates reroutes the request to the matching*-fastmodel (for example,anthropic/claude-opus-4.6→anthropic/claude-opus-4.6-fast). - Call the
*-fastmodel directly —anthropic/claude-opus-4.7-fastoranthropic/claude-opus-4.6-fast.
Both options route through the Anthropic first-party provider, and the required beta header is injected automatically.
Using /fast in Claude Code
Claude Code has a built-in /fast command that toggles fast mode. When enabled, Claude Code sends speed: "fast" in its requests alongside the configured Opus model. ModelGates fully supports this parameter — you just need to set the following environment variable:
export CLAUDE_CODE_SKIP_FAST_MODE_ORG_CHECK=1Requires Claude Code v2.1.96 or newer.
Pricing
Fast mode is priced at 6x the standard token rates for the underlying Claude Opus model (4.6 or 4.7). See Anthropic's fast mode pricing for current rates. When fast mode is active, the response's usage object includes "speed": "fast" to confirm the request was processed at the higher speed tier.
If speed: "fast" is sent for a model that does not support fast mode, ModelGates silently drops the parameter and the request proceeds at standard speed with standard pricing.
Routing behavior
Fast mode is only served by the Anthropic first-party provider, since other providers (e.g. Amazon Bedrock, Google Vertex) do not support it.
Agent SDK
The Anthropic Agent SDK lets you build AI agents programmatically using Python or TypeScript. Since the Agent SDK uses Claude Code as its runtime, you can connect it to ModelGates using the same environment variables described above.
For complete setup instructions and code examples, see our Anthropic Agent SDK integration guide.
GitHub Action
You can use ModelGates with the official Claude Code GitHub Action.To adapt the example workflow for ModelGates, make two changes to the action step:
- Pass your ModelGates API key via
anthropic_api_key(store it as a GitHub secret namedMODELGATES_API_KEY) - Set the
ANTHROPIC_BASE_URLenvironment variable tohttps://modelgates.ai/api
- name: Run Claude Code uses: anthropics/claude-code-action@v1 with: anthropic_api_key: ${{ secrets.MODELGATES_API_KEY }} env: ANTHROPIC_BASE_URL: https://modelgates.ai/apiCost Tracking Statusline
You can add a custom statusline to Claude Code that tracks your ModelGates API costs in real-time. The statusline displays the provider, model, cumulative cost, and cache discounts for your session.

Download the statusline scripts from the modelgates-examples repository, make them executable, and add the following to your ~/.claude/settings.json:
{ "statusLine": { "type": "command", "command": "/path/to/statusline.sh" }}The script uses your ANTHROPIC_AUTH_TOKEN environment variable, which should already be set to your ModelGates API key if you followed the setup above.
Troubleshooting
- Auth Errors: Ensure
ANTHROPIC_API_KEYis set to an empty string (""). If it is unset (null), Claude Code might fall back to its default behavior and try to authenticate with Anthropic servers. - Context Length Errors: If you hit context limits, consider breaking your task into smaller chunks or starting a new session.
- Privacy: ModelGates does not log your source code prompts unless you explicitly opt-in to prompt logging in your account settings. See our Privacy Policy for details.