Skip to content

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:

python
from openai import OpenAI
client = OpenAI(api_key="sk-openai-...")

After:

python
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

ts
const client = new OpenAI({
  apiKey: process.env.PRIMEROUTER_KEY,
  baseURL: 'https://primerouter.ai/v1',
})

Go (langchaingo / sashabaranov/go-openai)

go
config := openai.DefaultConfig("sk-primerouter-...")
config.BaseURL = "https://primerouter.ai/v1"
client := openai.NewClientWithConfig(config)

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:

👉 Coding Tools

This section only lists chat / workflow tools.

ToolWhere to set base_url
LobeChatModel Provider → OpenAI → API Proxy URL
ChatBoxModel → OpenAI → API Host
NextChatSettings → API URL
n8nOpenAI node → Credentials → Base URL
Open WebUISettings → Connections → OpenAI API
DifyModel 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 writeRoutes toNotes
gpt-4o, gpt-4o-miniOpenAIoriginal preserved
claude-3-5-sonnet, claude-opus-4Anthropicoriginal preserved
gemini-1.5-pro, gemini-2.0-flashGoogleoriginal preserved
deepseek-chat, deepseek-reasonerDeepSeek⭐ Recommended: comparable to GPT-4o, ~1/10 the price
qwen-max, qwen-plus, qwen-turboAlibaba Qwen⭐ Strong on Chinese
moonshot-v1-8k, moonshot-v1-128kMoonshot Kimi⭐ Ultra-long context
glm-4, glm-4-plusZhipu GLM⭐ Strong all-around
minimax-m1MiniMax
doubao-proByteDance Doubao

Full model list and pricing: Pricing → Models.

Compatibility edges

primerouter aims for 100% call-layer compatibility, but a few cases need attention:

  1. Non-existent models: returns 400 with a clear error — no silent fallback.
  2. Capabilities not supported by upstream: e.g. tool_choice="required" on GPT-3.5 — upstream's error is passed through verbatim.
  3. stream_options: every streaming-capable model supports include_usage: true.

Next

Built for transparent, auditable, crypto-native AI inference. About · Terms · Privacy