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

https://api.silom.cn/llm-api/v1

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.5
gpt-5.4
gpt-5.4-mini
gpt-4o
gpt-4o-mini
o3-mini
claude-sonnet-4-6
claude-opus-4-8
claude-opus-4-7
claude-haiku-4-5
gemini-3.5-flash
gemini-3.1-pro
grok-4.3-fast
kimi-k2.6
gpt-image-2

Model 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.

Full Claude Code guide →

# 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.

Full Cursor guide →

  1. Open Cursor Settings (Cmd+Shift+J / Ctrl+Shift+J)
  2. Go to Models
  3. Set Override OpenAI Base URL to https://api.silom.cn/llm-api/v1
  4. Enter your API key

Cline Setup

Connect Cline (VS Code extension) to MaxRouter.

Full Cline guide →

  1. Open Cline sidebar in VS Code
  2. Click Settings
  3. Select OpenAI Compatible
  4. Base URL: https://api.silom.cn/llm-api/v1
  5. 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

CodeMeaningSolution
401Invalid API keyCheck your API key
403Insufficient balanceTop up your account
404Model not foundCheck model name
429Rate limit exceededReduce request frequency
500Server errorRetry 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