API 文档
API 沿用 OpenAI 的路径和响应格式。Base URL:https://your-domain/v1。调用以美元从账户余额中扣费,与创作页共用同一份余额。
鉴权
在 API 密钥 页面创建密钥(格式如 sk-jg-…),并在每次请求中携带:
Authorization: Bearer sk-jg-xxxxxxxxxxxxxxxx模型列表
GET/v1/models
curl https://your-domain/v1/models \
-H "Authorization: Bearer $API_KEY"视频生成
视频生成为异步接口:请求会立即返回任务。轮询直到状态为 completed,再获取视频。
POST/v1/videos
curl https://your-domain/v1/videos \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "seedance-2.5",
"prompt": "麦田中的女孩回眸微笑,镜头缓慢推近,夕阳逆光",
"seconds": 5,
"resolution": "720p",
"aspect_ratio": "16:9"
}'GET/v1/videos/{id}
status 取值为 queued、in_progress、completed 或 failed。已完成的任务包含 video_url;失败的任务包含 error.message,费用会自动退还。建议每 3–5 秒轮询一次。
curl https://your-domain/v1/videos/$TASK_ID \
-H "Authorization: Bearer $API_KEY"视频就绪前,GET /v1/videos/{id}/content 返回 409。
图片生成
图片接口为同步接口:响应中直接返回生成好的图片。
POST/v1/images/generations
curl https://your-domain/v1/images/generations \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "nano-banana-2",
"prompt": "白底上的磨砂玻璃香水瓶,极简产品图,柔和侧光",
"aspect_ratio": "1:1",
"n": 1
}'参考素材
部分模型可以同时参考图片、视频和音频。分别通过 images、videos、audios 传入,并在提示词中用 @image1、@video1、@audio1 引用——按类型分别从 1 开始编号,顺序与数组一致。我们会为不同的服务商自动转换这些标签。
curl https://your-domain/v1/videos \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "seedance-2.5",
"prompt": "@image1 从 @video1 的场景中走进房间,运镜与 @video1 保持一致,背景音乐使用 @audio1",
"seconds": 5,
"aspect_ratio": "16:9",
"first_frame": "https://example.com/start.png",
"images": [
"https://example.com/character.png"
],
"videos": [
"https://example.com/camera-move.mp4"
],
"audios": [
"https://example.com/music.mp3"
],
"generate_audio": true
}'每个模型的上限和支持情况见模型页(例如最多 9 张图片、3 个视频、3 段音频)。素材数量超限时返回 too_many_images / too_many_videos / too_many_audios;模型不支持的字段返回 feature_not_supported。
请求体
视频和图片接口使用相同的请求体。各模型支持的取值见对应的模型页面。
| 字段 | 类型 | 说明 |
|---|---|---|
| model | string | 必填。模型 ID。 |
| prompt | string | 必填。1–8000 个字符。 |
| seconds | number | 视频时长(秒),需在模型支持的范围内。 |
| resolution | string | 分辨率,例如 720p。 |
| aspect_ratio | string | 画面比例,例如 16:9。 |
| n | integer | 生成张数,不超过模型上限。 |
| images | string[] | 参考图 URL(http/https),不超过模型上限。 |
| videos | string[] | 参考视频 URL(http/https),数量不超过模型上限。 |
| audios | string[] | 参考音频 URL(http/https),数量不超过模型上限。 |
| first_frame | string | 视频首帧图片 URL(模型支持时)。 |
| last_frame | string | 视频尾帧图片 URL(模型支持时),需与 first_frame 一起使用。 |
| generate_audio | boolean | 是否同时生成声音(模型支持时)。 |
| seed | integer | 整数随机种子。相同的种子和参数会得到相近的结果。 |
| extra | object | 可选,模型专属参数。 |
未填写的可选字段将使用模型默认值。
计费与错误
- 计费币种为美元。响应中的
cost_usd是本次生成的费用,为十进制字符串(如"0.5000",不足一美分的价格最多保留 4 位小数)。 - 提交时按模型价格从余额预扣费用,生成失败自动退还。每一笔变动都可在账单中查看。
401密钥缺失或无效 ·402insufficient_balance:余额不足,充值后即可继续 ·400模型不支持该参数 ·404模型或任务不存在。- API 错误格式为
{"error": {"message": "…", "type": "…", "code": "…"}}。请根据code判断错误类型,向用户展示message。 - 错误信息支持多语言:传入
X-Locale(en、zh-CN、zh-TW、ja、ko),或使用Accept-Language。
HTTP/1.1 402 Payment Required
{
"error": {
"message": "Insufficient balance: $0.50 needed, $0.10 available",
"type": "insufficient_quota",
"code": "insufficient_balance"
}
}