从 OpenRouter 迁移
替换 Base URL、Key 和模型 ID,并移除 OpenRouter 专有参数。
01需要修改的配置
| 配置 | OpenRouter | OpenCC |
|---|---|---|
| Base URL | https://openrouter.ai/api/v1 | https://api.opencc.si/v1 |
| API Key | OpenRouter Key | 控制台创建的 OpenCC Key |
| 模型 ID | 通常包含厂商/前缀 | 使用模型列表中的完整 ID |
不要机械地删除厂商前缀。以 /v1/models 返回的 ID 为准;没有对应模型时先更换模型。
02SDK 迁移示例
Python
from openai import OpenAI
client = OpenAI(
base_url="https://api.opencc.si/v1",
api_key="<OPENCC_API_KEY>",
)
response = client.chat.completions.create(
model="<MODEL_ID>",
messages=[{"role": "user", "content": "你好"}],
)
print(response.choices[0].message.content)03需要移除的专有参数
- provider.order、only、ignore、sort 等路由偏好参数。
- :nitro、:online、:batch 等 OpenRouter 模型后缀。
- HTTP-Referer、X-OpenRouter-Title 等 OpenRouter 归因请求头。
- plugins、transforms 及其他 OpenRouter 专用字段。
04迁移验收
- 用同一段生产提示词对比迁移前后的输出、Token 用量和耗时。
- 确认代码不再依赖 OpenRouter 的余额、generation 或 credits 接口。
- 清理旧 Key 和仅用于 OpenRouter 的请求头后再上线。