API 文档
本文说明如何使用 CobabaAi 调用聚合模型。所有请求使用 本站 Base URL 与 你在控制台创建的令牌。
WARNING
请勿将 API Key 写入前端代码或公开仓库。
基础信息
| 项目 | 值 |
|---|---|
| Base URL | https://cobabaai.com/v1 |
| 认证方式 | Authorization: Bearer <你的令牌> |
| 内容类型 | application/json |
创建令牌:控制台 → 令牌管理。
http
Authorization: Bearer sk-xxxxxxxxxxxxxxxxChat Completions(对话)
适用于 Gemini、GPT 等文本模型。
bash
curl https://cobabaai.com/v1/chat/completions \
-H "Authorization: Bearer sk-你的令牌" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-pro-preview",
"messages": [
{"role": "user", "content": "你好,用一句话介绍 CobabaAi"}
],
"stream": false
}'流式调用:将 "stream": true,并按 SSE 规范读取响应。
Images Generations(OpenAI 兼容出图)
适用于 gpt-image-2 等模型。
bash
curl https://cobabaai.com/v1/images/generations \
-H "Authorization: Bearer sk-你的令牌" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A cute cat drinking coffee on the moon",
"size": "1024x1024"
}'POST /v1/api/generate(统一 JSON 出图)
适用于 nano-banana、gpt-image 等,model、prompt 必填。
| 字段 | 说明 |
|---|---|
model | 如 nano-banana-fast |
prompt | 提示词 |
images | 可选,参考图 URL 或 base64 |
aspectRatio | 如 1:1 |
imageSize | 如 1K |
replyType | json / stream / async |
async 时返回任务 id,再用 /v1/draw/result 查询。
bash
curl https://cobabaai.com/v1/api/generate \
-H "Authorization: Bearer sk-你的令牌" \
-H "Content-Type: application/json" \
-d '{
"model": "nano-banana-fast",
"prompt": "A cat on the moon",
"images": [],
"aspectRatio": "1:1",
"imageSize": "1K",
"replyType": "async"
}'Nano Banana 异步任务
提交任务
bash
curl https://cobabaai.com/v1/draw/nano-banana \
-H "Authorization: Bearer sk-你的令牌" \
-H "Content-Type: application/json" \
-d '{
"model": "nano-banana-fast",
"prompt": "A cat wearing an astronaut suit on the moon",
"aspectRatio": "1:1",
"images": [],
"webHook": "-1"
}'成功返回本地 task_xxx 任务 ID。
查询结果
bash
curl https://cobabaai.com/v1/draw/result \
-H "Authorization: Bearer sk-你的令牌" \
-H "Content-Type: application/json" \
-d '{"id": "task_xxx"}'自定义接口支持情况
| 接口 | 状态 | 说明 |
|---|---|---|
POST /v1/api/generate | 已支持 | 统一 JSON 出图 |
POST /v1/draw/nano-banana | 已支持 | Legacy Nano Banana |
POST /v1/draw/completions | 已支持 | 自定义绘图任务提交 |
POST /v1/draw/result | 已支持 | 查询任务,不重复扣费 |
GET /client/common/getCredits | 仅管理员 | 渠道余额查询 |
GET /client/common/getModelStatus | 仅管理员 | 渠道模型状态 |
| 其他视频 / 角色接口 | 暂不支持 | 以控制台更新为准 |
错误码
| HTTP | 错误码 | 说明 |
|---|---|---|
| 401 | invalid_api_key / token_invalid | 令牌错误或过期 |
| 403 | access_denied / token_model_forbidden | 无权限访问该模型 |
| 404 | task_not_found | 任务 ID 不存在 |
| 429 | rate_limit_exceeded | 频率限制或上游繁忙 |
| 503 | model_not_found | 当前无可用渠道 |
| 500/502 | upstream_error | 上游异常 |
体验场专用路径(已登录)
在站内 体验场 已登录时,可使用:
POST /api/user/playground/api/generate(推荐)- 或
POST /api/user/playground/draw/nano-banana
轮询 POST /api/user/playground/draw/result,并携带 Cookie 及 Header:
http
New-Api-User: 你的用户ID与控制台文档的关系
登录后 控制台 → API 文档 中的示例与本页一致,且 Base URL 会自动填充为当前站点域名。