LogoDocs NanoPhoto.AI
LogoDocs NanoPhoto.AI
Page d'accueilDocumentation Homepage

Getting Started

Getting Started

User Guide

User Guide

API

API OverviewSora Watermark Removal APIVideo Reverse Prompt APISora 2 Prompt Generator APISora 2 Video Generation APISora 2 TVC Ad APINano Banana Pro Image Generation APINano Banana 2 Image Generation API

Use Cases

Sora 2 TVC Ad Creation

Billing

Billing & Invoice

FAQ

FAQ
X (Twitter)

Nano Banana 2 Image Generation API

API for generating AI images with text-to-image and image-to-image modes using Nano Banana 2, with Google Search enhanced prompts.

Try it online: https://nanophoto.ai/nano-banana-2

Endpoints

MethodPathDescription
POST/api/nano-banana-2/generateCreate an image generation task
POST/api/nano-banana-2/check-statusCheck task status and retrieve result

Authentication

Authorization: Bearer YOUR_API_KEY

Credits

QualityCredits
1K4
2K8
4K16

Credits are pre-deducted when the task is created and automatically refunded if generation fails.

Step 1: Generate Image

POST /api/nano-banana-2/generate

Headers

HeaderValue
Content-Typeapplication/json
AuthorizationBearer YOUR_API_KEY

Body Parameters

ParameterTypeRequiredDescription
promptstringYesImage generation prompt
modestringYesgenerate (text-to-image) or edit (image-to-image)
aspectRatiostringNo16:9, 9:16, 4:3, or 3:4 (default: 16:9)
imageQualitystringNo1K, 2K, or 4K (default: 1K)
googleSearchbooleanNoEnable Google Search to enhance prompt (default: false)
inputImageUrlsstring[]ConditionalPublic image URLs for edit mode (max 14). Required when mode is edit
  • API calls only accept inputImageUrls (publicly accessible URLs) for edit mode. Base64 image upload (inputImages) is not supported via API.
  • Maximum 14 input images allowed.
  • Set googleSearch: true to let the model search the web for additional context to enhance your prompt.

Examples

Text to Image

curl -X POST "https://nanophoto.ai/api/nano-banana-2/generate" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  --data-raw '{
    "prompt": "A futuristic cityscape at sunset with flying cars and neon lights",
    "mode": "generate",
    "aspectRatio": "16:9",
    "imageQuality": "2K"
  }'

Text to Image with Google Search

curl -X POST "https://nanophoto.ai/api/nano-banana-2/generate" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  --data-raw '{
    "prompt": "The latest Tesla Cybertruck in a desert landscape",
    "mode": "generate",
    "aspectRatio": "16:9",
    "imageQuality": "2K",
    "googleSearch": true
  }'

Image to Image

curl -X POST "https://nanophoto.ai/api/nano-banana-2/generate" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  --data-raw '{
    "prompt": "Transform this photo into a watercolor painting style",
    "mode": "edit",
    "aspectRatio": "16:9",
    "imageQuality": "1K",
    "inputImageUrls": ["https://static.nanophoto.ai/demo/nano-banana-pro.webp"]
  }'

Response

{
  "success": true,
  "generationId": "abc123xyz",
  "taskId": "task-456",
  "status": "pending"
}

Step 2: Check Status (Polling)

The generation is asynchronous. Use the generationId from Step 1 to poll for the result.

POST /api/nano-banana-2/check-status

Headers

HeaderValue
Content-Typeapplication/json
AuthorizationBearer YOUR_API_KEY

Body Parameters

ParameterTypeRequiredDescription
generationIdstringYesThe generationId returned from the generate endpoint

Example

curl -X POST "https://nanophoto.ai/api/nano-banana-2/check-status" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  --data-raw '{
    "generationId": "abc123xyz"
  }'

Response

Completed

{
  "success": true,
  "status": "completed",
  "imageUrl": "https://static.nanophoto.ai/generations/abc123.png",
  "generationId": "abc123xyz",
  "progress": 100
}

Still Processing

{
  "success": true,
  "status": "pending",
  "generationId": "abc123xyz",
  "progress": 15
}

Failed

{
  "success": false,
  "status": "failed",
  "error": "Generation failed",
  "generationId": "abc123xyz",
  "progress": 0
}

Complete TypeScript Example

generate-image.ts
async function generateImage(apiKey: string) {
  // Step 1: Create generation task
  const generateRes = await fetch("https://nanophoto.ai/api/nano-banana-2/generate", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${apiKey}`,
    },
    body: JSON.stringify({
      prompt: "A serene Japanese garden with cherry blossoms and a koi pond",
      mode: "generate",
      aspectRatio: "16:9",
      imageQuality: "2K",
      googleSearch: true,
    }),
  });

  const generateData = await generateRes.json();

  if (!generateData.success) {
    throw new Error(`Generate failed: ${generateData.error}`);
  }

  const { generationId } = generateData;
  console.log(`Task created: ${generationId}`);

  // Step 2: Poll for result
  while (true) {
    await new Promise((r) => setTimeout(r, 3000)); // Wait 3 seconds

    const statusRes = await fetch("https://nanophoto.ai/api/nano-banana-2/check-status", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        Authorization: `Bearer ${apiKey}`,
      },
      body: JSON.stringify({ generationId }),
    });

    const statusData = await statusRes.json();
    console.log(`Status: ${statusData.status}, Progress: ${statusData.progress}%`);

    if (statusData.status === "completed") {
      console.log(`Image URL: ${statusData.imageUrl}`);
      return statusData.imageUrl;
    }

    if (statusData.status === "failed") {
      throw new Error(`Generation failed: ${statusData.error}`);
    }
  }
}

Polling Strategy

  • Poll every 3-5 seconds
  • Typical generation time: 10-30 seconds
  • Status flow: pending → generating → completed or failed
  • Credits are automatically refunded if the generation fails

Error Codes

errorCodeHTTP StatusDescription
LOGIN_REQUIRED401Authentication required
API_KEY_RATE_LIMIT_EXCEEDED429Rate limit exceeded
INSUFFICIENT_CREDITS402Not enough credits
INVALID_PROMPT400Prompt is missing or empty
MISSING_INPUT_IMAGE400Edit mode requires input images
TOO_MANY_IMAGES400More than 14 input images
IMAGE_URLS_REQUIRED400API calls require inputImageUrls for edit mode
CREDIT_RESERVATION_FAILED500Failed to reserve credits
GENERATION_FAILED500Image generation failed
NOT_FOUND404Generation ID not found
FORBIDDEN403Access denied (not your generation)

Nano Banana Pro Image Generation API

API for generating AI images with text-to-image and image-to-image modes using Nano Banana Pro.

Sora 2 TVC Ad Creation

Create professional TVC-style video ads in 3 simple steps using AI. From theme to finished video in minutes.

Table des matières

Endpoints
Authentication
Credits
Step 1: Generate Image
Headers
Body Parameters
Examples
Text to Image
Text to Image with Google Search
Image to Image
Response
Step 2: Check Status (Polling)
Headers
Body Parameters
Example
Response
Completed
Still Processing
Failed
Complete TypeScript Example
Polling Strategy
Error Codes