Migrate from OpenAI SDK
If you already have a project on the OpenAI official SDK (or any OpenAI-compatible SDK), migrating to primerouter usually takes one line: point base_url at https://primerouter.ai/v1 and swap the api_key for a primerouter key.
Python
Before:
from openai import OpenAI
client = OpenAI(api_key="sk-openai-...")After:
from openai import OpenAI
client = OpenAI(
api_key="sk-primerouter-...",
base_url="https://primerouter.ai/v1", # change this
)Business code (client.chat.completions.create(...)) stays unchanged — original gpt-4o, claude-3-5-sonnet, gemini-1.5-pro etc. continue to work, or switch to primerouter's headline Chinese models like deepseek-chat, qwen-max, glm-4-plus, moonshot-v1-8k.
TypeScript / JavaScript
const client = new OpenAI({
apiKey: process.env.PRIMEROUTER_KEY,
baseURL: 'https://primerouter.ai/v1',
})Go (langchaingo / sashabaranov/go-openai)
config := openai.DefaultConfig("sk-primerouter-...")
config.BaseURL = "https://primerouter.ai/v1"
client := openai.NewClientWithConfig(config)Popular tool configurations
AI coding tools have their own page
Cursor / Cline / Claude Code / OpenCode / Crush / Codex CLI / Vibecode — step-by-step config (with macOS / Linux / Windows commands, file paths, env-var persistence) lives on a dedicated page:
This section only lists chat / workflow tools.
| Tool | Where to set base_url |
|---|---|
| LobeChat | Model Provider → OpenAI → API Proxy URL |
| ChatBox | Model → OpenAI → API Host |
| NextChat | Settings → API URL |
| n8n | OpenAI node → Credentials → Base URL |
| Open WebUI | Settings → Connections → OpenAI API |
| Dify | Model provider → OpenAI-API-compatible → API endpoint |
Model mapping
primerouter doesn't require renaming — original OpenAI / Anthropic / Gemini model names continue to work. We also strongly recommend the more cost-effective Chinese frontier models:
| You write | Routes to | Notes |
|---|---|---|
gpt-4o, gpt-4o-mini | OpenAI | original preserved |
claude-3-5-sonnet, claude-opus-4 | Anthropic | original preserved |
gemini-1.5-pro, gemini-2.0-flash | original preserved | |
deepseek-chat, deepseek-reasoner | DeepSeek | ⭐ Recommended: comparable to GPT-4o, ~1/10 the price |
qwen-max, qwen-plus, qwen-turbo | Alibaba Qwen | ⭐ Strong on Chinese |
moonshot-v1-8k, moonshot-v1-128k | Moonshot Kimi | ⭐ Ultra-long context |
glm-4, glm-4-plus | Zhipu GLM | ⭐ Strong all-around |
minimax-m1 | MiniMax | |
doubao-pro | ByteDance Doubao |
Full model list and pricing: Pricing → Models.
Compatibility edges
primerouter aims for 100% call-layer compatibility, but a few cases need attention:
- Non-existent models: returns
400with a clear error — no silent fallback. - Capabilities not supported by upstream: e.g.
tool_choice="required"on GPT-3.5 — upstream's error is passed through verbatim. stream_options: every streaming-capable model supportsinclude_usage: true.
