5 分钟接入,所有 SDK 都能用
BlueRouter 完整兼容 OpenAI 协议。已有的 `openai`、`openai-node`、`langchain`、`vercel/ai`、`anthropic` SDK 全部可以直接用。
3. 替换 base URL
将现有 OpenAI / Anthropic SDK 的 base URL 改为 https://bluerouter.wtnslog.site/v1,模型使用 BlueRouter model id。
查看代码配置清单
按下面 5 项配置客户端,就能把任意 OpenAI 兼容请求切到 BlueRouter。
| Checklist | Value | Notes |
|---|---|---|
| Base URL | https://bluerouter.wtnslog.site/v1 | 配置到 OpenAI 兼容 SDK 的 base_url / baseURL。 |
| API Key header | Authorization: Bearer $BLUEROUTER_API_KEY | 把控制台生成的完整 key 保存为 BLUEROUTER_API_KEY,不要写进前端代码。 |
| OpenAI endpoint | POST /chat/completions | 普通 OpenAI 兼容 SDK 使用这个 endpoint。 |
| Anthropic endpoint | POST /v1/messages | Claude Code / Anthropic Messages 兼容客户端使用这个 endpoint。 |
| Model ID format | BlueRouter model id | 例如 glm-4.7、gpt-4o-mini、deepseek-reasoner;BlueRouter 会把模型 ID 原样转发到上游。 |
| Restricted keys | Console -> API Keys -> Allowed models dropdown | 创建 key 时从下拉列表选择允许模型;默认使用 BlueRouter 推荐模型 glm-4.7。去 API Keys。 |
cURL
先用 curl 验证联通性:
bash
curl https://bluerouter.wtnslog.site/v1/chat/completions \
-H "Authorization: Bearer $BLUEROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "glm-4.7",
"messages": [
{ "role": "user", "content": "Hello, BlueRouter!" }
],
"stream": true
}'Python · openai SDK
已有 OpenAI 代码?只改一行 base_url:
python
from openai import OpenAI
client = OpenAI(
base_url="https://bluerouter.wtnslog.site/v1",
api_key="$BLUEROUTER_API_KEY",
)
stream = client.chat.completions.create(
model="glm-4.7",
messages=[{"role": "user", "content": "Hello, BlueRouter!"}],
stream=True,
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="", flush=True)Node.js · openai SDK
typescript
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://bluerouter.wtnslog.site/v1",
apiKey: process.env.BLUEROUTER_API_KEY,
});
const stream = await client.chat.completions.create({
model: "glm-4.7",
messages: [{ role: "user", content: "Hello, BlueRouter!" }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}Claude Code · Anthropic Messages
BlueRouter 提供 Anthropic 兼容的 /v1/messages,用户只需要配置 Anthropic 环境变量,内部兼容由 BlueRouter 处理。
bash
# Claude Code / Anthropic-compatible clients
export ANTHROPIC_BASE_URL="https://bluerouter.wtnslog.site"
export ANTHROPIC_API_KEY="$BLUEROUTER_API_KEY"
export ANTHROPIC_MODEL="gpt-5.5"
# The client will call:
# POST https://bluerouter.wtnslog.site/v1/messages
# BlueRouter handles the internal compatibility layer.bash
curl https://bluerouter.wtnslog.site/v1/messages -H "x-api-key: $BLUEROUTER_API_KEY" -H "anthropic-version: 2023-06-01" -H "Content-Type: application/json" -d '{
"model": "gpt-5.5",
"messages": [{"role":"user","content":"hello"}]
}'支持的模型
BlueRouter 可路由到 200+ 上游模型,使用 BlueRouter 模型 ID 格式:
base url
# Browse the full BlueRouter catalog in the console:
# /model-plaza
#
# Common ids you can drop in as the "model" field:
# gpt-4o gpt-4o-mini gpt-5.5
# claude-3-5-sonnet claude-opus-4-7 gemini-2.5-pro
# deepseek-chat deepseek-reasoner glm-4.7
# gpt-5.2 gpt-5.5 o4-mini