迁移到 wylon 新云
Token 工厂同时兼容 OpenAI 与 Anthropic 客户端 SDK。无论你当前是从 GPT 还是 Claude 迁移,只需更新三个配置项——不需要引入新库,也不需要重新学习请求结构。
选择你的 SDK
选择你当前使用的 SDK,查看对应的迁移步骤。
需要改什么 — OpenAI SDK
只需更新现有 OpenAI 代码中的三个值。 其他一切 —— 请求参数、响应结构、流式输出、工具使用 —— 保持完全一致。
| 配置项 | OpenAI | wylon |
|---|---|---|
base_url |
https://api.openai.com/v1 |
https://api.wylon.cn/v1 |
api_key |
OPENAI_API_KEY |
WYLON_API_KEY |
model |
gpt-4o、gpt-4o-mini … |
moonshotai/kimi-k2.5、更多 |
并排对比
下方 Diff 展示了一段最小 OpenAI 脚本及其 wylon 等价实现,仅高亮行需要修改。
from openai import OpenAI
import os
client = OpenAI(
api_key=os.environ["OPENAI_API_KEY"],
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain KV cache in one paragraph."},
],
temperature=0.6,
max_tokens=512,
)
print(response.choices[0].message.content)
from openai import OpenAI
import os
client = OpenAI(
api_key=os.environ["WYLON_API_KEY"], # ← 已修改
base_url="https://api.wylon.cn/v1", # ← 新增
)
response = client.chat.completions.create(
model="moonshotai/kimi-k2.5", # ← 已修改
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain KV cache in one paragraph."},
],
temperature=0.6,
max_tokens=512,
)
print(response.choices[0].message.content)
完整示例 — OpenAI SDK
一段可直接运行的完整脚本。设置 WYLON_API_KEY 后即可运行。
from openai import OpenAI
import os
client = OpenAI(
api_key=os.environ["WYLON_API_KEY"],
base_url="https://api.wylon.cn/v1",
)
response = client.chat.completions.create(
model="moonshotai/kimi-k2.5",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What are the benefits of open-source LLMs?"},
],
temperature=0.7,
max_tokens=512,
)
print(response.choices[0].message.content)
print(f"\nTokens used: {response.usage.total_tokens}")
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.WYLON_API_KEY,
baseURL: "https://api.wylon.cn/v1",
});
const response = await client.chat.completions.create({
model: "moonshotai/kimi-k2.5",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "What are the benefits of open-source LLMs?" },
],
temperature: 0.7,
max_tokens: 512,
});
console.log(response.choices[0].message.content);
console.log(`\nTokens used: ${response.usage.total_tokens}`);
curl https://api.wylon.cn/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $WYLON_API_KEY" \
-d '{
"model": "moonshotai/kimi-k2.5",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What are the benefits of open-source LLMs?"}
],
"temperature": 0.7,
"max_tokens": 512
}'
需要改什么 — Anthropic SDK
只需更新三个值。Anthropic SDK 的 messages.create 接口、
流式输出与工具使用无需其他改动。
| 配置项 | Anthropic | wylon |
|---|---|---|
base_url |
(默认值) | https://api.wylon.cn |
api_key |
ANTHROPIC_API_KEY |
WYLON_API_KEY |
model |
claude-opus-4-5、claude-sonnet-4-6 … |
moonshotai/kimi-k2.5、更多 |
info
关于
base_url。
Anthropic SDK 会自动追加 /v1/messages,
因此传入的 https://api.wylon.cn 末尾不要带路径,SDK 会自行拼出正确端点。
并排对比
一段最小 Anthropic 脚本及其 wylon 等价实现,仅高亮行需要修改。
import anthropic
import os
client = anthropic.Anthropic(
api_key=os.environ["ANTHROPIC_API_KEY"],
)
message = client.messages.create(
model="claude-opus-4-5",
max_tokens=512,
system="You are a helpful assistant.",
messages=[
{"role": "user", "content": "Explain KV cache in one paragraph."},
],
)
print(message.content[0].text)
import anthropic
import os
client = anthropic.Anthropic(
api_key=os.environ["WYLON_API_KEY"], # ← 已修改
base_url="https://api.wylon.cn", # ← 新增
)
message = client.messages.create(
model="moonshotai/kimi-k2.5", # ← 已修改
max_tokens=512,
system="You are a helpful assistant.",
messages=[
{"role": "user", "content": "Explain KV cache in one paragraph."},
],
)
print(message.content[0].text)
完整示例 — Anthropic SDK
一段可直接运行的完整脚本。设置 WYLON_API_KEY 后即可运行。
import anthropic
import os
client = anthropic.Anthropic(
api_key=os.environ["WYLON_API_KEY"],
base_url="https://api.wylon.cn",
)
message = client.messages.create(
model="moonshotai/kimi-k2.5",
max_tokens=512,
system="You are a helpful assistant.",
messages=[
{"role": "user", "content": "What are the benefits of open-source LLMs?"},
],
)
print(message.content[0].text)
print(f"\nInput tokens: {message.usage.input_tokens}")
print(f"Output tokens: {message.usage.output_tokens}")
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
apiKey: process.env.WYLON_API_KEY,
baseURL: "https://api.wylon.cn",
});
const message = await client.messages.create({
model: "moonshotai/kimi-k2.5",
max_tokens: 512,
system: "You are a helpful assistant.",
messages: [
{ role: "user", content: "What are the benefits of open-source LLMs?" },
],
});
console.log(message.content[0].text);
console.log(`\nInput tokens: ${message.usage.input_tokens}`);
console.log(`Output tokens: ${message.usage.output_tokens}`);
curl https://api.wylon.cn/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: $WYLON_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "moonshotai/kimi-k2.5",
"max_tokens": 512,
"system": "You are a helpful assistant.",
"messages": [
{"role": "user", "content": "What are the benefits of open-source LLMs?"}
]
}'
设置环境变量
在控制台的账户设置 → API 密钥中生成一个 wylon 密钥,然后导出到你的 Shell。 同一把密钥同时适用于 OpenAI 与 Anthropic SDK。
# 添加到 ~/.bashrc 或 ~/.profile
export WYLON_API_KEY="wl-••••••••••••••••••••••••••••••••"
# 添加到 ~/.zshrc
export WYLON_API_KEY="wl-••••••••••••••••••••••••••••••••"
# PowerShell — 当前用户持久化
[Environment]::SetEnvironmentVariable("WYLON_API_KEY", "wl-••••••••••••••••••••••••••••••••", "User")
key
妥善保管你的密钥。
不要把 API 密钥提交到代码仓库,也不要打包进客户端。
生产负载请使用密钥管理系统或服务端代理。
保持不变的部分
wylon 端到端镜像了两套 API 表面。下列能力无论你使用哪种 SDK,都无需改动现有代码。
| 功能 | OpenAI SDK | Anthropic SDK |
|---|---|---|
请求参数(temperature、max_tokens、top_p …) |
支持 | 支持 |
| 通过 SSE 的流式输出 | 支持 | 支持 |
| 函数调用与工具使用 | 支持 | 支持 |
| 结构化输出 / JSON 模式 | 支持 | 支持 |
| 多轮对话历史 | 支持 | 支持 |
| LangChain、LlamaIndex、LiteLLM 集成 | 支持 | 支持 |
info
模型 ID 不同。
OpenAI(
gpt-4o)与 Anthropic(claude-opus-4-5)的模型名在 wylon 上都不存在。
请使用 wylon 模型 ID,例如
moonshotai/kimi-k2.5。全部可用模型请见
模型页。
后续步骤
迁移完成。以下内容值得继续探索。