Appearance
首次调用
OPT 使用与 OpenAI / Anthropic 兼容的 API 格式,只需修改 base_url 和 api_key 即可接入。
| PARAM | VALUE |
|---|---|
base_url (OpenAI) | https://www.sky-ze.com/v1 |
base_url (Anthropic) | https://www.sky-ze.com/v1 |
api_key | 获取 API Key |
model | 查看模型列表 |
接入 Agent 工具
OPT 已接入多种主流 AI Agent 与编程助手工具。如果你使用 Claude Code、Cursor、GitHub Copilot CLI、OpenCode 等工具,可以直接将 OPT 作为后端模型,无需编写代码即可开始使用。
详见 Agent 工具接入指南。
调用对话 API
bash
curl https://www.sky-ze.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key" \
-d '{
"model": "GLM-5.1",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "你好,请介绍一下你自己"}
],
"stream": false
}'python
from openai import OpenAI
client = OpenAI(
api_key="your-api-key",
base_url="https://www.sky-ze.com/v1"
)
response = client.chat.completions.create(
model="GLM-5.1",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "你好,请介绍一下你自己"}
]
)
print(response.choices[0].message.content)javascript
import OpenAI from 'openai'
const client = new OpenAI({
apiKey: 'your-api-key',
baseURL: 'https://www.sky-ze.com/v1'
})
const response = await client.chat.completions.create({
model: 'GLM-5.1',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: '你好,请介绍一下你自己' }
]
})
console.log(response.choices[0].message.content)以上为非流式示例。将
stream设为true即可启用 SSE 流式输出。使用 Anthropic 兼容格式请参考 Anthropic Messages 接口。
流式输出
bash
curl https://www.sky-ze.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key" \
-d '{
"model": "GLM-5.1",
"messages": [
{"role": "user", "content": "讲个故事"}
],
"stream": true
}'python
stream = client.chat.completions.create(
model="GLM-5.1",
messages=[{"role": "user", "content": "讲个故事"}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")javascript
const stream = await client.chat.completions.create({
model: 'GLM-5.1',
messages: [{ role: 'user', content: '讲个故事' }],
stream: true
})
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '')
}获取 API Key
- 登录 OPT 管理平台
- 左侧菜单 我的服务 → 我的订阅,点击你的订阅进入详情页
- 切换到 密钥管理 Tab
- 点击 + 创建 Key,输入名称(如
my-key)后点 创建 - 在列表中点 显示 查看完整密钥,或点 复制 复制到剪贴板
每个订阅可创建多个 Key,共享订阅额度。带截图的图文详版见 用户手册。
认证
所有 API 请求需在 Authorization Header 中传入 API Key:
Authorization: Bearer your-api-key安全建议
- API Key 具有账户权限,请勿在客户端代码中暴露
- 建议使用环境变量存储:
export OPT_API_KEY="your-api-key" - 如 API Key 泄露,请立即在平台中删除重建