迁移到 wylon 新云
wylon 新云 Token 工厂 为文本生成提供 OpenAI 与 Anthropic 兼容接口。 迁移兼容的文本调用时,通常只需要更新 Base URL、API Key 和模型 ID;图片与视频生成还需要根据调用方式调整端点、参数和任务查询流程。
按能力选择迁移路径
文本生成 arrow_forward
继续使用 OpenAI 或 Anthropic SDK,查看配置差异和完整示例。
图片生成 arrow_forward
根据交互时延选择 OpenAI Images 兼容接口或异步内容任务。
视频生成 arrow_forward
使用异步内容任务完成创建、查询和结果下载。
迁移文本生成
选择当前使用的 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 … |
ZhipuAI/GLM-5.3 … |
差异对比
下面用一段最小 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="ZhipuAI/GLM-5.3", # ← 已修改
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="ZhipuAI/GLM-5.3",
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: "ZhipuAI/GLM-5.3",
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": "ZhipuAI/GLM-5.3",
"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 … |
ZhipuAI/GLM-5.3、更多 |
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="ZhipuAI/GLM-5.3", # ← 已修改
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="ZhipuAI/GLM-5.3",
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: "ZhipuAI/GLM-5.3",
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": "ZhipuAI/GLM-5.3",
"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 密钥提交到代码仓库,也不要打包进客户端。生产环境建议使用密钥管理系统或服务端代理。
保持不变的部分
对于兼容的文本模型和参数,下列调用结构可以继续沿用。具体能力仍取决于所选模型。
| 功能 | 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,例如
ZhipuAI/GLM-5.3。