外观
curl 示例
以下命令从 TOPAPIS_API_KEY 环境变量读取密钥。开始前先按 API 鉴权 配置环境变量。
查询模型
bash
curl --fail-with-body "https://api.topapis.cn/v1/models" \
-H "Authorization: Bearer $TOPAPIS_API_KEY"将后续示例中的 YOUR_MODEL 替换为响应中的模型标识。
非流式对话
bash
curl --fail-with-body "https://api.topapis.cn/v1/chat/completions" \
-H "Authorization: Bearer $TOPAPIS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "YOUR_MODEL",
"messages": [
{ "role": "user", "content": "用三点概括 API 密钥安全要求。" }
]
}'流式对话
--no-buffer 让 curl 收到数据后立即输出:
bash
curl --no-buffer --fail-with-body \
"https://api.topapis.cn/v1/chat/completions" \
-H "Authorization: Bearer $TOPAPIS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "YOUR_MODEL",
"messages": [
{ "role": "user", "content": "逐步说明健康检查流程。" }
],
"stream": true
}'响应使用 SSE 格式,并以 data: [DONE] 结束。
图片生成
bash
curl --fail-with-body "https://api.topapis.cn/v1/images/generations" \
-H "Authorization: Bearer $TOPAPIS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "现代图书馆室内,柔和自然光,写实建筑摄影",
"size": "1024x1024",
"quality": "high",
"n": 1
}'模型名称必须存在于当前账号的 /v1/models 响应中。客户端需要同时处理 url 和 b64_json。
提交 SD2.0 视频
bash
curl --fail-with-body "https://api.topapis.cn/v1/video/generations" \
-H "Authorization: Bearer $TOPAPIS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "video-v1-5s",
"prompt": "云层掠过山谷,延时摄影,镜头固定",
"ratio": "16:9"
}'保存响应中的 task_id,再查询同一任务:
bash
curl --fail-with-body \
"https://api.topapis.cn/v1/video/generations/$TASK_ID" \
-H "Authorization: Bearer $TOPAPIS_API_KEY"状态变为 SUCCESS 后下载视频:
bash
curl --fail-with-body --location \
"https://api.topapis.cn/v1/videos/$TASK_ID/content" \
-H "Authorization: Bearer $TOPAPIS_API_KEY" \
--output result.mp4不要在未确认首次提交结果时反复创建视频任务。
