API Reference

NanoBanana 2 API

Generate images from text or edit existing images with Google's NanoBanana 2 model. Supports up to 4K resolution.

Authentication

Pass your API key as a Bearer token in the Authorization header.

http
1Authorization: Bearer sk-your-api-key-here

Models & Pricing

TypeCreditsDescription
text-to-image20Generate images from text prompts
edit24Edit existing images with text instructions (up to 14 reference images)

Endpoints

POST/api/generate

Submit a text-to-image or image editing task. Returns a task_id for polling.

Body ParametersJSON
prompt:string

Text description for the image. Max 5000 characters.

type:optional string

text-to-image or edit. Auto-detected if images is provided. Defaults to text-to-image.

images:optional array of strings

Image URLs for editing. Required when type is edit. Max 14 images.

aspect_ratio:optional string

1:1, 3:2, 2:3, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, or 21:9. Defaults to 1:1.

resolution:optional string

1k, 2k, or 4k. Defaults to 1k.

output_format:optional string

png or jpeg. Defaults to png.

Request Example — Text-to-Image

bash
1curl -X POST https://banana2api.com/api/generate \
2 -H "Authorization: Bearer YOUR_API_KEY" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "prompt": "A futuristic cyberpunk city with neon lights, cinematic style",
6 "aspect_ratio": "16:9",
7 "resolution": "2k"
8 }'

Request Example — Image Editing

json
1{
2 "type": "edit",
3 "prompt": "Turn the cat into a tiger, keep the background",
4 "images": ["https://example.com/cat.jpg"],
5 "aspect_ratio": "1:1"
6}

Task created. Use the task_id to poll for results.

1{
2 "code": 200,
3 "message": "success",
4 "data": {
5 "task_id": "n82abc123def456nb2",
6 "type": "text-to-image",
7 "status": "IN_PROGRESS"
8 }
9}

If the API returns 402, your account has insufficient credits. Top up credits →

Playground da APIPOST
GET/api/status

Poll this endpoint to check the progress of your task. We recommend polling every 2-3 seconds.

Body ParametersJSON
task_id:string

The task ID received from the generate endpoint.

Request Example

bash
1curl -X GET "https://banana2api.com/api/status?task_id=n82abc123def456nb2" \
2 -H "Authorization: Bearer YOUR_API_KEY"

Task completed successfully. The response array contains result image URLs.

1{
2 "code": 200,
3 "message": "success",
4 "data": {
5 "task_id": "n82abc123def456nb2",
6 "status": "SUCCESS",
7 "type": "text-to-image",
8 "model": "nano-banana-2",
9 "consumed_credits": 20,
10 "response": [
11 "https://generated-image-url.com/image1.png"
12 ],
13 "request": {
14 "prompt": "A futuristic cyberpunk city..."
15 },
16 "created_at": "2025-03-20T10:00:00Z"
17 }
18}
Playground da APIGET

Error Codes

CodeDescription
200 OKSuccess
400 Requisição InválidaBad Request — missing or invalid parameters
401 Não autorizadoUnauthorized — missing or invalid API key
402 Insufficient Credits — top up your account
404 Não encontradoNot Found — task does not exist
500 Erro Interno do ServidorInternal Server Error — retry or contact support

Need help? Contact Support