Overview

Use your API key to generate images via a simple HTTP endpoint. Credits are automatically deducted based on the number of images generated.

Endpoint

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

Authentication

Include your API key in the Authorization header. Don't have one yet? Create an API key here.

Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Request Body (Client)

{
  "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"
}

Supported values for model:

Supported values for image_size:

  • 1:1
  • 16:9
  • 9:16
  • 4:3
  • 3:4
  • 2:3
  • 3:2
  • 4:5
  • 5:4

Additional sizes supported by gemini-3.1-flash models only:

  • 21:9
  • 1:4
  • 4:1
  • 8:1
  • 1:8

Credit Deduction

  • gemini-2.5-flash-image: Per image: 2 credits
  • gemini-2.5-flash-image-hd: Per image: 5 credits
  • gemini-3.1-flash-image-preview-512: Per image: 4 credits
  • gemini-3.1-flash-image-preview: Per image: 4 credits
  • gemini-3.1-flash-image-preview-2k: Per image: 6 credits
  • gemini-3.1-flash-image-preview-4k: Per image: 8 credits
  • gemini-3-pro-image-preview: Per image: 8 credits
  • gemini-3-pro-image-preview-2k: Per image: 8 credits
  • gemini-3-pro-image-preview-4k: Per image: 16 credits
  • If credits are insufficient, the API returns an error.

Response

All responses use a unified JSON format:

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

If num is greater than 1, the API returns multiple image URLs:

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

Error responses:

{
  "code": 400,
  "message": "insufficient credits"
}

Common error messages:

  • 400: Invalid request parameters
  • 401: Invalid API key
  • 500: Server error

Examples

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;
}

Python

import requests


def generate():
  url = 'https://api.nanobananaapi.dev/v1/images/generate'
  headers = {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json',
  }
  payload = {
    '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',
  }

  res = requests.post(url, headers=headers, json=payload, timeout=60)
  res.raise_for_status()
  result = res.json()
  if result.get('code') != 0:
    raise Exception(result.get('message'))
  return result.get('data')


print(generate())

Go

package main

import (
  "bytes"
  "encoding/json"
  "fmt"
  "io"
  "net/http"
  "time"
)

func main() {
  url := "https://api.nanobananaapi.dev/v1/images/generate"
  payload := map[string]any{
    "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",
  }

  bodyBytes, err := json.Marshal(payload)
  if err != nil {
    panic(err)
  }

  req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(bodyBytes))
  if err != nil {
    panic(err)
  }
  req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
  req.Header.Set("Content-Type", "application/json")

  client := &http.Client{Timeout: 60 * time.Second}
  resp, err := client.Do(req)
  if err != nil {
    panic(err)
  }
  defer resp.Body.Close()

  respBody, err := io.ReadAll(resp.Body)
  if err != nil {
    panic(err)
  }

  fmt.Println(string(respBody))
}

Java

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;

public class Main {
  public static void main(String[] args) throws Exception {
    String json = "{\n" +
      "  \"prompt\": \"A serene mountain landscape at sunset with a lake reflecting the orange sky\",\n" +
      "  \"num\": 1,\n" +
      "  \"model\": \"gemini-3-pro-image-preview\",\n" +
      "  \"image_size\": \"16:9\"\n" +
      "}";

    HttpClient client = HttpClient.newBuilder()
      .connectTimeout(Duration.ofSeconds(10))
      .build();

    HttpRequest request = HttpRequest.newBuilder()
      .uri(URI.create("https://api.nanobananaapi.dev/v1/images/generate"))
      .timeout(Duration.ofSeconds(60))
      .header("Authorization", "Bearer YOUR_API_KEY")
      .header("Content-Type", "application/json")
      .POST(HttpRequest.BodyPublishers.ofString(json))
      .build();

    HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
    System.out.println(response.body());
  }
}