概览

使用您的 API Key 通过简单的 HTTP 接口生成图片。系统会根据生成的图片数量自动扣减积分。

接口信息

  • 方法:POST
  • URL:https://api.nanobananaapi.dev/v1/images/generate

认证方式

在请求头中加入 API Key:

Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

请求体(用户侧)

{
  "prompt": "A serene mountain landscape at sunset with a lake reflecting the orange sky",
  "num": 1,
  "model": "gemini-3-pro-image-preview",
  "image_size": "16:9"
}

积分扣减

  • gemini-2.5-flash-image: 每张图片:2 积分
  • gemini-3-pro-image-preview: 每张图片:10 积分
  • 若积分不足则返回错误信息。

返回格式

统一返回 JSON:

{
  "code": 0,
  "message": "ok",
  "data": {
    "url": "https://api.nanobananaapi.dev/v1/images/1234567890.png"
  }
}

错误返回:

{
  "code": -1,
  "message": "insufficient credits"
}

常见错误信息:

  • invalid api key
  • invalid request type
  • insufficient credits
  • generate failed

调用示例

curl

curl -X POST "https://api.nanobananaapi.dev/v1/images/generate" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A serene mountain landscape at sunset with a lake reflecting the orange sky",
    "num": 1,
    "model": "gemini-3-pro-image-preview",
    "image_size": "16:9"
  }'

Node.js

async function generate() {
  const res = await fetch('https://api.nanobananaapi.dev/v1/images/generate', {
    method: 'POST',
    headers: {
      Authorization: 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      prompt:
        'A serene mountain landscape at sunset with a lake reflecting the orange sky',
      num: 1,
      model: 'gemini-3-pro-image-preview',
      image_size: '16:9',
    }),
  });

  const result = await res.json();
  if (result.code !== 0) throw new Error(result.message);
  return result.data;
}