API Documentation
Everything you need to integrate MaxRouter into your applications.
Overview
MaxRouter is fully compatible with the OpenAI API format. You can use existing OpenAI SDKs, libraries, and tools with zero code changes — just swap the base URL and API key.
What's supported:
- ✓ OpenAI Chat Completions (
/v1/chat/completions) - ✓ Anthropic Messages (
/v1/messages) - ✓ Streaming responses (SSE)
- ✓ Tool calling / Function calling
- ✓ Structured output (JSON mode)
- ✓ Image generation
Base URL
Important: For Claude Code (Anthropic protocol), use https://api.silom.cn/llm-api (without /v1).
Authentication
Pass your API key in the Authorization header:
# Using curl curl https://api.silom.cn/llm-api/v1/chat/completions \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model": "gpt-5.4", "messages": [{"role": "user", "content": "Hello"}]}'
Chat Completions
Send a conversation and get a completion from the model.
Python (OpenAI SDK)
from openai import OpenAI client = OpenAI( base_url="https://api.silom.cn/llm-api/v1", api_key="YOUR_API_KEY" ) response = client.chat.completions.create( model="gpt-5.4", messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Explain quantum computing in simple terms."} ] ) print(response.choices[0].message.content)
Node.js
import OpenAI from "openai"; const client = new OpenAI({ baseURL: "https://api.silom.cn/llm-api/v1", apiKey: "YOUR_API_KEY" }); const response = await client.chat.completions.create({ model: "gpt-5.4", messages: [{ role: "user", content: "Hello!" }] }); console.log(response.choices[0].message.content);
Streaming
Set stream: true to receive responses as Server-Sent Events (SSE).
from openai import OpenAI client = OpenAI( base_url="https://api.silom.cn/llm-api/v1", api_key="YOUR_API_KEY" ) stream = client.chat.completions.create( model="gpt-5.4", messages=[{"role": "user", "content": "Write a poem about the ocean"}], stream=True ) for chunk in stream: if chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="")
Tool Calling
Define tools (functions) that the model can call. Compatible with OpenAI's function calling format.
from openai import OpenAI client = OpenAI( base_url="https://api.silom.cn/llm-api/v1", api_key="YOUR_API_KEY" ) tools = [{ "type": "function", "function": { "name": "get_weather", "description": "Get current weather for a location", "parameters": { "type": "object", "properties": { "location": {"type": "string"} }, "required": ["location"] } } }] response = client.chat.completions.create( model="gpt-5.4", messages=[{"role": "user", "content": "What's the weather in Tokyo?"}], tools=tools )
Structured Output
Use response_format to get JSON output from the model.
response = client.chat.completions.create(
model="gpt-5.4",
messages=[{"role": "user", "content": "List 3 programming languages with their use cases"}],
response_format={
"type": "json_schema",
"json_schema": {
"name": "languages",
"schema": {
"type": "object",
"properties": {
"languages": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"use_case": {"type": "string"}
}
}
}
}
}
}
}
)
Available Models
See the Models & Pricing page for the full list with pricing.
gpt-5.5gpt-5.4gpt-5.4-minigpt-4ogpt-4o-minio3-miniclaude-sonnet-4-6claude-opus-4-8claude-opus-4-7claude-haiku-4-5gemini-3.5-flashgemini-3.1-progrok-4.3-fastkimi-k2.6gpt-image-2Model List API
Get the list of available models programmatically:
curl https://api.silom.cn/llm-api/v1/models \
-H "Authorization: Bearer YOUR_API_KEY"
Claude Code Setup
Connect Claude Code to MaxRouter for access to Claude Opus and Sonnet models.
# Using CC Switch (recommended) git clone https://github.com/farion1231/cc-switch.git cd cc-switch && python3 cc_switch.py # Or set environment variables manually export ANTHROPIC_BASE_URL="https://api.silom.cn/llm-api" export ANTHROPIC_API_KEY="YOUR_API_KEY"
Note: Claude Code uses the Anthropic protocol. The base URL does NOT include /v1.
Cursor Setup
Use MaxRouter with Cursor IDE for AI-powered coding.
- Open Cursor Settings (
Cmd+Shift+J/Ctrl+Shift+J) - Go to Models
- Set Override OpenAI Base URL to
https://api.silom.cn/llm-api/v1 - Enter your API key
Cline Setup
Connect Cline (VS Code extension) to MaxRouter.
- Open Cline sidebar in VS Code
- Click Settings
- Select OpenAI Compatible
- Base URL:
https://api.silom.cn/llm-api/v1 - Enter your API key and model name
Codex Setup
Use MaxRouter with OpenAI Codex CLI.
export OPENAI_BASE_URL="https://api.silom.cn/llm-api/v1" export OPENAI_API_KEY="YOUR_API_KEY"
Error Codes
| Code | Meaning | Solution |
|---|---|---|
| 401 | Invalid API key | Check your API key |
| 403 | Insufficient balance | Top up your account |
| 404 | Model not found | Check model name |
| 429 | Rate limit exceeded | Reduce request frequency |
| 500 | Server error | Retry or contact support |
Rate Limits
- • Default: 60 requests/minute per API key
- • Default: 1M tokens/minute per API key
- • Enterprise plans with higher limits available — contact us