使用 nano-banana-2-1 生成图片
本页由 ModelFold 文档站根据上游官方 OpenAPI 文档同步生成。接口路径、参数、示例与官方保持一致;品牌与 API 域名已替换为 ModelFold。
接口
POST /jobs/createTask
完整 URL: https://ai.modelfold.online/v1/jobs/createTask
鉴权:所有请求都需要
Authorization: Bearer <API_KEY>请求头。
基于 Nano Banana 2-1 模型实现图像生成
查询任务状态
提交任务后,可通过统一的查询端点查看任务进度并获取生成结果:
- 获取任务详情 — 了解如何查询任务状态并获取生成结果
TIP
生产环境中,建议使用 callBackUrl 参数接收生成完成的自动通知,而非轮询状态端点。
相关资源
请求参数
请求体 (application/json)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 用于生成任务的模型名称。必填字段。 - 该端点必须使用 nano-banana-2-1 模型 默认值:"nano-banana-2-1"。 可选值:nano-banana-2-1。 示例:nano-banana-2-1。 |
callBackUrl | string | 否 | 接收生成任务完成通知的回调 URL。可选配置,建议在生产环境中使用。 - 任务生成完成后,系统会向该 URL POST 任务状态与结果 - 回调内容包含生成的资源 URL 与任务相关信息 - 您的回调端点需要支持接收带 JSON 负载的 POST 请求 - 也可以选择调用任务详情端点,主动轮询任务状态 - 为确保回调安全性,请参阅 Webhook 校验指南 了解签名验证实现方法 示例: https://your-domain.com/api/callback。 |
input | object | 是 | 生成任务的输入参数 |
input.aspect_ratio | string | 否 | 生成图像的宽高比 默认值:"auto"。 可选值:1:1 / 2:3 / 3:2 / 1:4 / 4:1 / 3:4 / 4:3 / 4:5 / 5:4 / 1:8 / 8:1 / 9:16 / 16:9 / 21:9 / auto。 示例:auto。 |
input.image_input | array<string> | 否 | 用于图像变换或作为参考的输入图像(最多支持 10 张图片)(为上传后的文件 URL,非文件内容;支持的类型:image/jpeg、image/png、image/webp;最大文件大小:30.0MB) |
input.output_format | string | 否 | 生成图像的输出格式 默认值:"jpg"。 可选值:jpg / png。 示例:jpg。 |
input.prompt | string | 是 | 用于描述待生成图像的文本提示词(最大长度:20000 字符) 示例:一幅高度细致的插画:香蕉造型的未来飞船在夜晚的霓虹城市上空飞行,光影真实、具有电影感效果、4K 质量。。 |
input.resolution | string | 否 | 生成图像的分辨率 默认值:"1K"。 可选值:1K / 2K / 4K。 示例:1K。 |
请求示例
bash
curl -X POST "https://ai.modelfold.online/v1/jobs/createTask" \
-H "Authorization: Bearer $MODELFOLD_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "nano-banana-2-1",
"callBackUrl": "https://your-domain.com/api/callback",
"input": {
"prompt": "一幅高度细致的插画:香蕉造型的未来飞船在夜晚的霓虹城市上空飞行,光影真实、具有电影感效果、4K 质量。",
"aspect_ratio": "auto",
"resolution": "2K",
"output_format": "jpg",
"image_input": []
}
}'json
{
"model": "nano-banana-2-1",
"callBackUrl": "https://your-domain.com/api/callback",
"input": {
"prompt": "一幅高度细致的插画:香蕉造型的未来飞船在夜晚的霓虹城市上空飞行,光影真实、具有电影感效果、4K 质量。",
"aspect_ratio": "auto",
"resolution": "2K",
"output_format": "jpg",
"image_input": []
}
}响应
200 — 请求成功
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
code | integer | 否 | Status code of the request. The HTTP status is 200 even when the request fails, so always check this field: 200 means success; any other value means the request failed and msg describes the reason. Common values: 401 invalid or missing API key; 402 insufficient credits; 429 rate limit exceeded; 422 or 500 the request could not be processed (read msg and check your parameters before retrying). 可选值:200 / 401 / 402 / 404 / 422 / 429 / 433 / 455 / 500 / 501 / 505。 示例:200。 |
msg | string | 否 | Response message, error description upon failure 示例:success。 |
data | object | 是 | — |
data.taskId | string | 是 | The task ID can be used with the "Get Task Details" endpoint to query the task status. 示例:dc1928bfcbc77cb6c85f3359a9c718b3。 |
json
{
"code": 200,
"msg": "success",
"data": {
"taskId": "task_nano-banana-2-1_1765178625768"
}
}回调
onImageGenerated
回调地址:{$request.body#/callBackUrl}(即请求体里的 callBackUrl)。
任务成功或失败时发送回调。
回调体参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
code | integer | 否 | 200:成功;501:失败,原因见 data.failCode 与 data.failMsg。 可选值:200 / 501。 示例:200。 |
msg | string | 否 | 状态消息 示例:Playground task completed successfully.。 |
data | object | 否 | — |
data.completeTime | integer | 否 | 任务完成时间,Unix 毫秒时间戳 示例:1786427040000。 |
data.costTime | integer | 否 | 处理耗时(秒),成功和失败回调都会返回。 示例:48。 |
data.createTime | integer | 否 | 任务创建时间,Unix 毫秒时间戳 示例:1786426989000。 |
data.creditsConsumed | number | 否 | 本任务消耗的积分;失败任务为 0。 示例:5。 |
data.model | string | 否 | 图片生成使用的模型 示例:nano-banana-2-1。 |
data.param | string | 否 | 创建任务时提交的参数,JSON 字符串格式 示例:{"input":"{\"image_input\":[],\"aspect_ratio\":\"auto\",\"output_format\":\"jpg\",\"prompt\":\"一幅高度细致的插画:香蕉造型的未来飞船在夜晚的霓虹城市上空飞行,光影真实、具有电影感效果、4K 质量。\",\"resolution\":\"2K\"}","callBackUrl":"https://your-domain.com/api/callback","model":"nano-banana-2-1"}。 |
data.resultJson | string | 否 | 图片生成结果,JSON 字符串格式。resultUrls 为生成图片的 URL 列表。仅在 state 为 success 时出现。 示例:{"resultUrls":["https://tempfile.aiquickdraw.com/workers/images/image_90b6bf4499a80b74a2b5ee640b7aaf70.jpg"]}。 |
data.state | string | 否 | 任务状态 可选值:success / fail。 示例:success。 |
data.taskId | string | 否 | 任务 ID 示例:a2a1622f9daca036d85f4b63e74eb4af。 |
data.updateTime | integer | 否 | 完成时间请以 completeTime 为准;updateTime 可能与 createTime 相同。 示例:1786427040000。 |
data.failCode | string | 否 | 失败码,数字字符串,如 "400"、"500"。仅在 state 为 fail 时出现。 示例:500。 |
data.failMsg | string | 否 | 失败原因,仅在 state 为 fail 时出现。 示例:<error detail>。 |
成功
json
{
"code": 200,
"msg": "Playground task completed successfully.",
"data": {
"taskId": "a2a1622f9daca036d85f4b63e74eb4af",
"model": "nano-banana-2-1",
"state": "success",
"param": "{\"input\":\"{\\\"image_input\\\":[],\\\"aspect_ratio\\\":\\\"auto\\\",\\\"output_format\\\":\\\"jpg\\\",\\\"prompt\\\":\\\"一幅高度细致的插画:香蕉造型的未来飞船在夜晚的霓虹城市上空飞行,光影真实、具有电影感效果、4K 质量。\\\",\\\"resolution\\\":\\\"2K\\\"}\",\"callBackUrl\":\"https://your-domain.com/api/callback\",\"model\":\"nano-banana-2-1\"}",
"resultJson": "{\"resultUrls\":[\"https://tempfile.aiquickdraw.com/workers/images/image_90b6bf4499a80b74a2b5ee640b7aaf70.jpg\"]}",
"completeTime": 1786427040000,
"createTime": 1786426989000,
"costTime": 48,
"creditsConsumed": 5,
"updateTime": 1786427040000
}
}失败
json
{
"code": 501,
"msg": "Playground task failed.",
"data": {
"taskId": "a2a1622f9daca036d85f4b63e74eb4af",
"model": "nano-banana-2-1",
"state": "fail",
"param": "{\"input\":\"{\\\"image_input\\\":[],\\\"aspect_ratio\\\":\\\"auto\\\",\\\"output_format\\\":\\\"jpg\\\",\\\"prompt\\\":\\\"一幅高度细致的插画:香蕉造型的未来飞船在夜晚的霓虹城市上空飞行,光影真实、具有电影感效果、4K 质量。\\\",\\\"resolution\\\":\\\"2K\\\"}\",\"callBackUrl\":\"https://your-domain.com/api/callback\",\"model\":\"nano-banana-2-1\"}",
"failCode": "500",
"failMsg": "<error detail>",
"completeTime": 1786427040000,
"createTime": 1786426989000,
"costTime": 48,
"creditsConsumed": 0,
"updateTime": 1786427040000
}
}