加载中...
加载中...
Ciyuano 词元圈完全兼容 OpenAI Chat Completions API,只需修改 base_url 和 api_key 即可无缝接入。
三步完成接入,即刻使用 AI 大模型 API。
注册账号后在控制台创建 API Key,格式为sk-relay-xxx
使用 OpenAI 官方 SDK,支持 Python、Node.js 等多种语言
修改 base_url 为 Ciyuano 词元圈地址,即可像使用 OpenAI 一样调用
# 1. 安装 SDK
pip install openai
# 2. 创建客户端
from openai import OpenAI
client = OpenAI(
base_url="http://www.ciyuano.com/v1",
api_key="sk-relay-your-api-key"
)
# 3. 调用 API
response = client.chat.completions.create(
model="deepseek-v4",
messages=[{`{`}"role": "user", "content": "Hello!"{`}`}]
)
print(response.choices[0].message.content)所有 API 请求都需要在 Header 中携带 Bearer Token 进行认证。
Authorization: Bearer sk-relay-xxxxxAPI Key 以 sk-relay- 为前缀,后跟随机字符串
注册账号后,在控制台创建 API Key
请勿将 API Key 暴露在客户端代码或公开仓库中
核心接口,兼容 OpenAI Chat Completions API 格式。
http://www.ciyuano.com/v1/chat/completions| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型 ID,如 deepseek-v4、glm-5、qwen-plus、auto |
messages | array | 是 | 消息列表,包含对话历史 |
stream | boolean | 否 | 是否使用流式输出,默认 false |
temperature | number | 否 | 采样温度,范围 0-2,默认 1。值越低输出越确定 |
top_p | number | 否 | 核采样概率,范围 0-1。建议不要与 temperature 同时修改 |
max_tokens | integer | 否 | 最大输出 token 数 |
frequency_penalty | number | 否 | 频率惩罚,范围 -2 到 2。正值降低重复词频率 |
presence_penalty | number | 否 | 存在惩罚,范围 -2 到 2。正值增加新话题概率 |
stop | string / array | 否 | 停止词,模型生成到该词时停止 |
| 字段 | 类型 | 说明 |
|---|---|---|
role | string | system / user / assistant / tool |
content | string | 消息内容 |
{
"model": "deepseek-v4",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello!"
}
],
"stream": false,
"temperature": 0.7,
"max_tokens": 2048
}{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1700000000,
"model": "deepseek-v4",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 8,
"total_tokens": 28
}
}设置 stream: true 即可启用流式输出,响应将以 Server-Sent Events (SSE) 格式逐块返回。
每个数据块以 data: 开头,内容为 JSON 对象,包含增量内容 (delta)。
流式响应以 data: [DONE] 作为结束标记,客户端应据此判断流已结束。
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1700000000,"model":"deepseek-v4","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1700000000,"model":"deepseek-v4","choices":[{"index":0,"delta":{"content":"!"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1700000000,"model":"deepseek-v4","choices":[{"index":0,"delta":{"content":" How"},"finish_reason":null}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1700000000,"model":"deepseek-v4","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]当前支持的模型列表。你也可以通过 API 动态获取模型列表。
http://www.ciyuano.com/v1/chat/completions| 模型 ID | 名称 | 说明 | 上下文窗口 |
|---|---|---|---|
deepseek-chat | DeepSeek V4 | deepseek - deepseek-chat | 128K |
glm-5 | GLM-5 | zhipu - glm-5 | 128K |
auto | Auto (自动路由) | 自动在所有可用渠道间负载均衡 | - |
部分模型支持别名映射,中转服务会自动将用户请求的模型 ID映射到上游渠道的实际模型 ID。例如:
"deepseek-v4" → "deepseek-chat"
"glm-5" → "glm-5"
"qwen-plus" → "qwen-plus"
"auto" → 自动选择可用渠道API 返回的错误响应格式兼容 OpenAI,包含错误码和错误信息。
| 状态码 | 错误类型 | 说明 |
|---|---|---|
401 | invalid_request_error | API Key 无效或格式错误 |
402 | insufficient_balance | 余额不足,请充值后继续使用 |
403 | invalid_request_error | API Key 已禁用或已过期 |
429 | rate_limit_error | 请求过于频繁,请稍后重试 |
500 | server_error | 服务器内部错误,请稍后重试 |
{
"error": {
"message": "Invalid API key format",
"type": "invalid_request_error"
}
}使用 OpenAI SDK 或直接 HTTP 请求调用 API 的完整示例。
from openai import OpenAI
client = OpenAI(
base_url="http://www.ciyuano.com/v1",
api_key="sk-relay-your-api-key"
)
response = client.chat.completions.create(
model="deepseek-v4",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
temperature=0.7
)
print(response.choices[0].message.content)注册 Ciyuano 词元圈账号后,登录控制台(/user/dashboard),在 API Key 管理页面创建新的 Key。Key 格式为 sk-relay-xxx,创建后请妥善保存,系统不会再次显示完整 Key。
登录控制台即可查看当前余额、用量统计和请求日志。计费基于 Token 用量,不同模型和渠道的价格可能不同,具体价格请参考控制台中的渠道信息。
系统会根据你的账户等级和余额情况设置合理的请求频率限制。如果遇到 429 错误,请稍后重试或联系管理员提升限额。
如果请求返回 "No available channel for model" 错误,说明当前没有可用的上游渠道支持该模型。请尝试使用 auto 模型自动路由,或联系管理员检查渠道配置。
支持。中转服务完全兼容 OpenAI API 格式,包括 Function Calling(tool_calls)和 JSON Mode 等高级特性,具体取决于上游模型的支持情况。