Claude Code routes all its requests through whichever Anthropic-compatible API endpoint you point it at. Change one environment variable and you’re running Qwen, DeepSeek, GLM, or MiniMax through Claude Code’s full agentic workflow — including MCP tool calling, file editing, and bash execution — without touching the rest of your setup.
This guide covers how routing works, how to configure Novita AI’s endpoint as your backend, how MCP tool calls flow through a routed setup, and how to run tool execution securely in Novita’s Agent Sandbox.
What Is a Claude Code Router?
In Claude Code’s terms, a “router” is any Anthropic API-compatible endpoint that Claude Code sends its requests to. By default, that endpoint is Anthropic’s own API at api.anthropic.com. By setting ANTHROPIC_BASE_URL, you redirect those requests to a different provider — one that accepts the same API format and returns responses in the same structure.
This is worth understanding clearly: Claude Code doesn’t know or care which provider sits behind its configured endpoint. It sends an Anthropic-format message request, reads an Anthropic-format response, and continues. The router — whether it’s Novita AI, a self-hosted proxy, or a third-party aggregator — handles model selection, inference, and response formatting transparently.
Three practical reasons to use a router:
- Model access: Open-weight models like Qwen3-Coder, MiniMax M2.7, and GLM-4.7 aren’t available on Anthropic’s endpoint. Routing through Novita AI gives you access to all of them inside the same Claude Code workflow.
- Cost management: Open-weight models through providers like Novita typically cost significantly less per million tokens than Anthropic’s closed models. For high-volume agentic sessions where the model makes hundreds of tool calls, that difference adds up.
- Specialized capabilities: Some open-weight models are specifically trained for function calling and multi-step tool use, which is exactly what Claude Code’s MCP integration requires. Choosing a model tuned for tool-calling accuracy rather than a general-purpose model can reduce failed or malformed tool calls in complex workflows.
How Claude Code Routing Works
Three environment variables control routing:
| Variable | Purpose |
|---|---|
ANTHROPIC_BASE_URL | The API endpoint. Change this to route through a different provider. |
ANTHROPIC_AUTH_TOKEN | The API key for authentication at the target endpoint. |
ANTHROPIC_MODEL | The model ID to use. Must match the naming convention of the target provider. |
When ANTHROPIC_BASE_URL is set, Claude Code sends all inference requests to that URL instead of https://api.anthropic.com. The target endpoint must implement Anthropic’s message API format — the same request and response structure that Claude’s native models use.
One important detail: Anthropic’s model aliases (sonnet, opus, haiku) only resolve correctly against Anthropic’s own endpoint. When using a third-party router, set ANTHROPIC_MODEL to the provider’s specific model ID rather than an alias. An alias like sonnet passed to a non-Anthropic endpoint will either fail or return an unexpected model.
ANTHROPIC_SMALL_FAST_MODEL is a second model slot for Claude Code’s internal background tasks: summarization, context compression, and lightweight reasoning between steps. Pointing this at a faster, cheaper model keeps session costs down without affecting the quality of your primary model’s responses.
Setting Up Novita AI as Your Router
Novita AI’s Anthropic-compatible endpoint lives at https://api.novita.ai/anthropic. It accepts the same request format Claude Code sends natively and supports a broad range of open-weight models, including coding specialists and tool-calling-optimized variants.
Step 1: Get your Novita API key
- Sign up at novita.ai — free trial credits are included at signup.
- Open Key Management in your dashboard.
- Click Create New Key, copy the key immediately (it’s only shown once), and store it securely.
Step 2: Configure the environment
macOS / Linux:
export ANTHROPIC_BASE_URL="https://api.novita.ai/anthropic"
export ANTHROPIC_AUTH_TOKEN="<your-novita-api-key>"
export ANTHROPIC_MODEL="qwen/qwen3-coder-480b-a35b-instruct"
export ANTHROPIC_SMALL_FAST_MODEL="deepseek/deepseek-v4-flash"
Windows (PowerShell):
$env:ANTHROPIC_BASE_URL = "https://api.novita.ai/anthropic"
$env:ANTHROPIC_AUTH_TOKEN = "<your-novita-api-key>"
$env:ANTHROPIC_MODEL = "qwen/qwen3-coder-480b-a35b-instruct"
$env:ANTHROPIC_SMALL_FAST_MODEL = "deepseek/deepseek-v4-flash"
Windows (Command Prompt):
set ANTHROPIC_BASE_URL=https://api.novita.ai/anthropic
set ANTHROPIC_AUTH_TOKEN=<your-novita-api-key>
set ANTHROPIC_MODEL=qwen/qwen3-coder-480b-a35b-instruct
set ANTHROPIC_SMALL_FAST_MODEL=deepseek/deepseek-v4-flash
Step 3: Launch Claude Code
claude .
Claude Code starts in the current directory and routes all inference through Novita AI. MCP tools, file editing, and bash execution behave identically to a native Anthropic setup.
Available models on Novita AI
| Model | Novita model ID | Primary strength |
|---|---|---|
| Qwen3-Coder 480B | qwen/qwen3-coder-480b-a35b-instruct | Code generation, long-context reasoning |
| MiniMax M2.7 | minimax/minimax-m2.7 | Agentic tool-calling accuracy |
| DeepSeek V4 Flash | deepseek/deepseek-v4-flash | Fast iteration, cost efficiency |
| GLM-4.7 | zai-org/glm-4.7 | Coding and multi-step agentic tasks |
| Kimi K2 Instruct | moonshotai/kimi-k2-instruct | Tool use, math-heavy codebases |
These open-weight models run on modern GPU infrastructure, but their per-token cost is typically much lower. On tasks like extended refactoring sessions or automated test generation — where Claude Code makes dozens of tool calls — that difference in cost per token matters in practice.
Check novita.ai/llm-api for the current model list and verified IDs before finalizing your configuration. Model availability and IDs can change as providers add or update offerings.
Routing Tool Calls Through MCP
Claude Code’s tool-calling layer is MCP — the Model Context Protocol. When you add an MCP server with claude mcp add, Claude Code connects to it at session start and loads the tools it exposes. During a session, the routed LLM decides when to call those tools, what arguments to pass, and how to act on results.
The routing split is important: the LLM backend (your Novita AI router) handles all the reasoning — which tools to invoke, in what sequence, and with what arguments. The MCP server handles execution — it receives tool calls, runs the underlying action, and returns results. Claude Code coordinates between them.
In practice, this means the quality of your router’s tool-calling support determines how reliably complex multi-step tasks complete. A model that generates malformed function call arguments or fails to continue after tool errors will stall in the middle of a task. Models specifically fine-tuned on function-calling workflows — like Qwen3-Coder and MiniMax M2.7 — handle these sequences more consistently.
Adding an MCP server to a routed setup
# Local server (project scope) — Claude Code launches the process
claude mcp add my-server -- python my_server.py
# Remote HTTP server — connects to an already-running server
claude mcp add remote-server --transport http https://your-server.example.com/mcp
The remote HTTP option connects to a server running independently. That’s the architecture Novita Agent Sandbox is built for: the MCP server stays running and spawns sandbox instances on demand as tool calls come in.
Running Tool Execution in Agent Sandbox
When your MCP tools involve running code, processing files, or calling external systems, you want that execution to happen in an isolated environment rather than on your development machine. Novita’s Agent Sandbox provides this as a managed cloud service.
A Sandbox instance is a short-lived isolated container that your MCP server creates when Claude Code triggers a code execution tool. Each container provides:
- Isolated filesystem: separated from the host, nothing bleeds between sessions
- Pre-installed environment: Python with common data science and scripting packages
- Fast startup: sub-200ms cold start, suitable for low-latency tool-call sequences
- Per-second billing: you pay only for active execution time
- Shell and Python execution: full command-line access for multi-language workflows
The data flow in a routed Claude Code setup with Sandbox looks like this:
Claude Code
→ sends reasoning requests to Novita LLM API (the router)
→ receives tool-call decisions from the model
→ forwards tool calls to the MCP server
→ MCP server creates a Novita Sandbox instance
→ Sandbox executes the code and returns output
→ MCP server returns results to Claude Code
→ Novita LLM API reasons over results, decides next step
This separation keeps untrusted code execution contained while giving the LLM router full visibility into results for multi-step reasoning.
To use Novita Sandbox from within an MCP tool handler, install the SDK:
pip install novita-sandbox
Then create and use a sandbox instance inside your tool implementation:
from novita_sandbox.code_interpreter import Sandbox
def run_code_tool(code: str, api_key: str) -> dict:
sandbox = Sandbox.create(
template="code-interpreter-v1",
api_key=api_key,
domain="sandbox.novita.ai",
timeout=300,
)
result = sandbox.run_code(code, language="python")
sandbox.kill()
return {
"output": result.logs,
"error": result.error,
}
The code-interpreter-v1 template comes pre-installed with pandas, numpy, matplotlib, and other commonly used packages, so most data analysis and scripting tasks run without additional setup steps.
Choosing a Model for Tool-Heavy Workflows
Model choice affects two things in a routed Claude Code setup: reasoning quality for deciding what to do, and tool-calling reliability for executing it correctly. These don’t always correlate — a model that reasons well on open-ended tasks might generate inconsistent function call schemas when tools have complex argument types.
Qwen3-Coder 480B performs well on long-horizon coding tasks where Claude Code needs to read many files, plan an approach, and execute a multi-step edit sequence. Its long context handling means it’s less likely to lose track of earlier tool results partway through a complex task.
MiniMax M2.7 is tuned for agentic accuracy — specifically, it’s designed to minimize incorrect tool invocations and handle multi-turn tool sequences where each step builds on the previous result. For MCP setups with several interdependent tools, that accuracy reduces the number of recovery loops needed.
DeepSeek V4 Flash is the practical choice for ANTHROPIC_SMALL_FAST_MODEL. It’s fast and cheap, and the tasks Claude Code offloads to the small model — session summarization, context compression — don’t require the same reasoning depth as the primary coding tasks.
One practical observation: if you’re building a custom MCP server with tools that have many optional parameters or nested schemas, test the model’s call accuracy with representative examples before deploying to a long-running session. Tool-calling errors are less disruptive when caught early.
FAQ
Can I use any LLM router with Claude Code, not just Novita AI?
Yes. Any service that implements the Anthropic message API at its base URL works. This includes LiteLLM configured with the Anthropic format, self-hosted proxies, or other commercial router services. Set ANTHROPIC_BASE_URL to that endpoint, ANTHROPIC_AUTH_TOKEN to the appropriate key, and ANTHROPIC_MODEL to the model ID that endpoint recognizes.
Do MCP tools work when routing through a non-Anthropic provider?
Yes. MCP operates at the Claude Code layer, not at the API level. The router only affects which model does the reasoning about tool use. As long as the model supports function calling in the Anthropic message format, MCP tools work the same way regardless of provider.
Why doesn’t the sonnet alias work when routing through Novita AI?
Anthropic’s model aliases (sonnet, opus, haiku) are resolved by Anthropic’s endpoint, not by Claude Code. When you route through a third-party provider, Anthropic’s alias resolution isn’t involved. Set ANTHROPIC_MODEL to a specific model ID from your provider instead.
How do I switch back to Anthropic’s native models?
Unset the routing variables for the current session:
unset ANTHROPIC_BASE_URL
unset ANTHROPIC_AUTH_TOKEN
unset ANTHROPIC_MODEL
unset ANTHROPIC_SMALL_FAST_MODEL
Claude Code falls back to whatever is in your settings file or the Anthropic API default on the next launch.
Is there latency overhead from using a third-party router?
There’s a small additional network hop. For interactive sessions, this generally isn’t noticeable. For latency-sensitive automated pipelines, check the provider’s published latency numbers before committing. Novita AI publishes inference latency and throughput metrics through its LLM Metrics console.
Does the Agent Sandbox require a separate API key from the LLM router?
No. Novita AI’s API key works for both the LLM API and the Agent Sandbox. The same key you use for ANTHROPIC_AUTH_TOKEN is what you pass to Sandbox.create() in your MCP tool implementation.
Recommended Articles
- Claude MCP Add Command: How to Install MCP Servers in Claude Code
- Claude Code Default Model: How to Change, Switch, and Choose the Right One
- Build a Remote Code Execution MCP Server with Novita Sandbox and mcp-use Library
Sources checked July 16, 2026: Claude Code environment variable docs, Novita AI LLM API, Novita Agent Sandbox.
