迁移到 wylon 新云
wylon 新云 Token 工厂 同时兼容 OpenAI 与 Anthropic 客户端 SDK。 无论你当前使用 GPT 还是 Claude,迁移到 wylon 通常只需要更新三个配置项:Base URL、API Key 和模型 ID。 你无需引入新 SDK,也不需要重新学习请求结构。
选择你的 SDK
选择你当前使用的 SDK,查看对应的迁移步骤。
需要改什么 — OpenAI SDK
| 配置项 | 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 … |
差异对比
下面用一段最小 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 后即可调用 wylon。
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 | 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 后即可调用 wylon。
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?"}
]
}'
设置环境变量
- 进入 wylon 控制台
- 点击账户设置 → API 密钥,生成一个新的 wylon 密钥
- 将密钥添加到你的 Shell 环境变量中,变量名为
WYLON_API_KEY(示例代码中会读取这个环境变量)
同一把密钥同时适用于 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 上都不存在。
请使用 模型目录 中提供的模型 ID,例如
moonshotai/kimi-k2.5。