三步拿到第一个回复。
注册后在控制台 → API Key 新建一个。Key 只在创建时显示一次,请立即保存。
https://yun.nmgshenghang.cn/v1
curl https://yun.nmgshenghang.cn/v1/chat/completions \
-H "Authorization: Bearer $SHSL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "glm-5.3",
"messages": [{"role": "user", "content": "你好"}]
}'
from openai import OpenAI
client = OpenAI(
api_key="sk-shsl-...",
base_url="https://yun.nmgshenghang.cn/v1"
)
r = client.chat.completions.create(
model="glm-5.3",
messages=[{"role": "user", "content": "你好"}]
)
print(r.choices[0].message.content)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "sk-shsl-...",
baseURL: "https://yun.nmgshenghang.cn/v1"
});
const r = await client.chat.completions.create({
model: "glm-5.3",
messages: [{ role: "user", content: "你好" }]
});
console.log(r.choices[0].message.content);
所有接口都在请求头带 Key。
Authorization: Bearer sk-shsl-xxxxxxxxxxxxxxxx
25 个模型统一接口,价格与上下文长度都明码标注。
同一模型可能由多个通道供货,切换只改 model 字符串:
glm-5.3 → 通道一 glm-5.3-oc → 通道二(如已开通) 能力完全相同,价格可能不同。切换只改 model,Key 不变。
下表是当前可调用的模型(打开页面时实时拉取,加模型后自动更新):
| model(调用时填这个) | 名称 | 供应商 | 类型 | 输入价 | 输出价 | 单位 | 上下文 |
|---|---|---|---|---|---|---|---|
| 正在加载… | |||||||
GET /v1/models(需要 Key)。POST /v1/chat/completions
{
"model": "glm-5.3",
"messages": [
{"role": "system", "content": "你是一个简洁的助手"},
{"role": "user", "content": "你好"}
],
"temperature": 0.7,
"max_tokens": 1024,
"stream": false
}
{
"id": "req-6e8e665f265c1ad5779c0271",
"object": "chat.completion",
"model": "glm-5.3",
"choices": [{
"index": 0,
"message": {"role": "assistant", "content": "你好!有什么可以帮你?"},
"finish_reason": "stop"
}],
"usage": {"prompt_tokens": 18, "completion_tokens": 12, "total_tokens": 30}
}
| 参数 | 说明 |
|---|---|
model 必填 | 见「模型选择」的表格 |
messages 必填 | role 支持 system / user / assistant / tool |
temperature | 0~2,越大越发散 |
top_p | 0~1,与 temperature 二选一 |
max_tokens | 最大输出长度 |
stream | true 时返回 SSE 流 |
stop | 停止词,字符串或数组 |
tools / tool_choice | 函数调用,与 OpenAI 一致 |
response_format | 如 {"type":"json_object"} |
stream 设为 true,服务端以 SSE 逐块返回。
stream = client.chat.completions.create(
model="glm-5.3",
messages=[{"role": "user", "content": "写一段 200 字的介绍"}],
stream=True
)
for chunk in stream:
delta = chunk.choices[0].delta.content
if delta:
print(delta, end="", flush=True)
usage(token 数)在最后一帧返回。自己解析 SSE 时记得处理 data: [DONE]。与 OpenAI function calling 格式完全一致。
{
"model": "glm-5.3",
"messages": [{"role": "user", "content": "北京今天天气怎么样"}],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "查询城市天气",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}
}]
}
content 换成数组,图片传 URL 或 base64。仅支持带视觉能力的模型。
{
"model": "deepseek-v4.1-flash",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "这张图里有什么"},
{"type": "image_url", "image_url": {"url": "https://example.com/a.jpg"}}
]
}]
}
POST /v1/embeddings
no_upstream。接口已按 OpenAI 规范实现,接入后下面示例可直接使用。
{"model": "bge-m3", "input": ["第一段文本", "第二段文本"]}
→ {"data": [{"index": 0, "embedding": [0.013, -0.024, ...]}, ...],
"usage": {"prompt_tokens": 12, "total_tokens": 12}}
POST /v1/images/generations · 按张计费
{
"model": "qwen-image-3.0",
"prompt": "一只橘猫坐在窗台上,午后阳光",
"n": 1,
"size": "1024x1024"
}
→ {
"created": 1792635822,
"data": [{"url": "https://dashscope-....png"}],
"usage": {"images": 1, "cost_cents": 18, "cost_yuan": 0.18}
}
异步两步:创建任务 → 轮询结果。按秒计费。
{
"model": "minimax-h3-max",
"prompt": "海边的日落,慢镜头",
"duration": 6,
"ratio": "16:9",
"resolution": "768P"
}
→ {"id":"455001208295701","status":"queued","poll_url":"/v1/videos/455001208295701","usage":{"seconds":6,"cost_yuan":3}}
GET /v1/videos/455001208295701
Authorization: Bearer $SHSL_API_KEY
→ {"id":"455001208295701","status":"succeeded","video_url":"https://..."}
| 参数 | 取值 |
|---|---|
duration | 秒数,例如 5 / 6 / 10 |
ratio | 16:9、4:3、1:1、3:4、9:16、21:9(不能是 adaptive) |
resolution | 480P、768P |
status | queued → processing → succeeded / failed |
POST /v1/audio/speech · 按万字符计费
no_upstream。接口已按 OpenAI 规范实现,接入后即可使用。
{
"model": "cosyvoice-v3.5-flash",
"input": "你好,这是一段测试语音",
"voice": "<音色ID>",
"response_format": "mp3",
"speed": 1.0
}
→ {"url": "https://...mp3", "chars": 12, "usage": {"characters": 12, "cost_yuan": 0.001}}
voice 必填。cosyvoice 系列没有系统音色,需要先在控制台创建「声音复刻 / 声音设计」音色。两个查询接口。
GET /v1/models # 当前可调用的模型(含价格、上下文、能力) GET /v1/me # 我的余额与额度
| HTTP | type | 含义 | 怎么处理 |
|---|---|---|---|
| 401 | authentication_error | Key 缺失或无效 | 检查 Authorization 头 |
| 402 | insufficient_balance | 余额不足 | 控制台充值 |
| 404 | model_not_found | 模型不存在或已下架 | 用 GET /v1/models 查可用名 |
| 429 | rate_limit_exceeded | 触发限流 | 指数退避重试 |
| 502 | upstream_error | 上游供应商异常 | 换同模型的其他供应商重试 |
| 400 | invalid_request_error | 参数不合法 | 看 error.message |
{"error": {"message": "模型不存在或已下线: xxx", "type": "model_not_found", "code": "model_not_found"}}
| 类型 | 算法 | 单位 |
|---|---|---|
| 文本 | 输入 tokens ÷ 1,000,000 × 输入价 + 输出 tokens ÷ 1,000,000 × 输出价 | 元 / 百万 tokens |
| 图像 | 张数 × 单价 | 元 / 张 |
| 视频 | 时长秒数 × 单价 | 元 / 秒 |
| 语音 | 字符数 ÷ 10,000 × 单价 | 元 / 万字符 |
glm-5.3 → glm-5.3-flash)三种机器可读格式,直接喂给任何 AI 助手就能生成可运行的调用代码。
| 地址 | 格式 | 适合 |
|---|---|---|
/llms.txt | 纯文本 | 直接粘贴给 ChatGPT / Claude / 豆包等对话助手 |
/docs/api.md | Markdown | 喂给 AI 或放进知识库 |
/openapi.json | OpenAPI 3.0 | Apifox / Postman / Cursor 等工具 |
请先读取 https://yun.nmgshenghang.cn/llms.txt 这份接口文档, 然后帮我用 Python 写一个封装类: 支持流式输出、工具调用、失败自动重试 (502 时换同模型的其他供应商,429 时指数退避)。 不要用占位符,给出可以直接运行的完整代码。