Nano Banana 2

Google Gemini 3.1 Flash Image 图片生成模型。闪电般速度,Pro 级质量。支持文生图、图片编辑、4K 输出、精准文字渲染和角色一致性。

模型

模型名称输出宽高比
nano-banana-2图片 (JPG/PNG)1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9, 1:4, 4:1, 1:8, 8:1, auto

定价

按分辨率计费:

分辨率积分价格
1K(默认)16 积分$0.08
2K24 积分$0.12
4K36 积分$0.18

创建任务

curl -X POST https://api.aivideoapi.ai/v1/images/generations \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nano-banana-2",
    "callback_url": "https://your-server.com/webhook",
    "input": {
      "prompt": "一只戴墨镜的猫坐在沙滩上,数字艺术风格",
      "resolution": "1K",
      "aspect_ratio": "16:9",
      "output_format": "png"
    }
  }'

请求体

字段类型必填说明
modelstring固定为 nano-banana-2
inputobject生成参数,见下方
callback_urlstring任务完成/失败时接收通知的 URL

Input 参数

字段类型必填说明
promptstring图片描述(最长 20,000 字符)
resolutionstring1K(默认)、2K4K
aspect_ratiostring宽高比,默认 auto。见 宽高比
output_formatstringjpg(默认)或 png
image_urlsstring[]最多 14 张图片 URL,用于图片编辑(支持 JPEG、PNG、WebP)

宽高比

标准宽/竖屏超宽
1:12:3, 3:221:9
4:3, 3:49:16, 16:94:1, 1:4
4:5, 5:4auto8:1, 1:8

示例:文生图

curl -X POST https://api.aivideoapi.ai/v1/images/generations \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nano-banana-2",
    "callback_url": "https://your-server.com/webhook",
    "input": {
      "prompt": "夕阳下的赛博朋克城市,霓虹灯倒映在湿漉漉的街道上",
      "resolution": "2K",
      "aspect_ratio": "21:9",
      "output_format": "png"
    }
  }'

示例:图片编辑

curl -X POST https://api.aivideoapi.ai/v1/images/generations \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nano-banana-2",
    "callback_url": "https://your-server.com/webhook",
    "input": {
      "prompt": "将这张照片转换为水彩画风格",
      "image_urls": [
        "https://example.com/photo.jpg"
      ],
      "resolution": "4K"
    }
  }'

示例:文字渲染

curl -X POST https://api.aivideoapi.ai/v1/images/generations \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nano-banana-2",
    "callback_url": "https://your-server.com/webhook",
    "input": {
      "prompt": "一张生日卡片,上面用优雅的手写字体写着 \"生日快乐!\",四周有花卉装饰",
      "resolution": "2K",
      "aspect_ratio": "3:2",
      "output_format": "png"
    }
  }'

响应

{
  "code": 200,
  "msg": "success",
  "data": {
    "taskId": "397ce9f2-c04e-4244-ac33-3af19a7cc297"
  }
}

查询任务

curl https://api.aivideoapi.ai/v1/tasks/{taskId} \
  -H "Authorization: Bearer sk-your-api-key"

状态变化:pending -> processing -> completedfailed

已完成

{
  "id": "397ce9f2-c04e-4244-ac33-3af19a7cc297",
  "status": "completed",
  "model": "nano-banana-2",
  "created_at": 1775383908,
  "completed_at": 1775383910,
  "output": {
    "urls": [
      "https://file.aivideoapi.ai/images/2026/04/05/abc123.png"
    ],
    "metadata": {
      "model": "nano-banana-2",
      "costTime": 70
    }
  }
}

图片 URL 永久有效。

失败

{
  "id": "57c8772c-f834-46f3-9b7d-81f92e104050",
  "status": "failed",
  "model": "nano-banana-2",
  "created_at": 1775383908,
  "error": {
    "code": "upstream_error",
    "message": "Image generation failed"
  }
}

任务失败时,预扣积分会自动退还。

回调通知

创建任务时传入 callback_url,任务完成或失败时系统会自动向该 URL 发送 POST 请求,格式与查询任务响应一致。


常见错误码

请求失败时,API 返回 JSON 格式的错误响应:

{
  "error": {
    "code": "insufficient_credits",
    "message": "Your credit balance is too low. Please top up.",
    "type": "billing_error"
  }
}

错误码一览

HTTP 状态码错误码类型说明
400invalid_requestinvalid_request_error缺少必填参数或参数无效
401invalid_api_keyauthentication_errorAPI Key 无效、已禁用或已删除
402insufficient_creditsbilling_error积分余额不足,请充值
403ip_not_allowedpermission_error请求 IP 不在 Key 的白名单中
404model_not_foundinvalid_request_error模型不存在或已停用
404task_not_foundinvalid_request_error任务 ID 不存在
429rate_limit_exceededrate_limit_error请求过于频繁,请降低频率
429spend_limit_exceededbilling_error达到 Key 的消费限额(每小时/每天/总量)
500internal_errorapi_error服务器内部错误
503upstream_errorupstream_error上游 AI 服务返回错误

常见场景

invalid_request (400)

缺少必填字段或参数格式错误时返回。

{
  "error": {
    "code": "invalid_request",
    "message": "'model' is required.",
    "type": "invalid_request_error"
  }
}

insufficient_credits (402)

积分不足。可通过 GET /v1/credits 查询余额,前往 Dashboard > Billing 充值。

invalid_api_key (401)

可能原因:

  • Key 不以 sk- 开头
  • Key 已被禁用或删除
  • 用户账户已被封禁

upstream_error (503)

上游 AI 服务返回错误,可能原因:

  • 输入内容包含敏感或违规信息
  • 上游服务暂时不可用
  • 请求参数不被上游支持

因上游错误导致任务失败时,预扣积分会自动退还。