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.
| 1 | Authorization: Bearer sk-your-api-key-here |
Models & Pricing
| Type | Credits | Description |
|---|---|---|
| text-to-image | 20 | Generate images from text prompts |
| edit | 24 | Edit existing images with text instructions (up to 14 reference images) |
Endpoints
/api/generateSubmit a text-to-image or image editing task. Returns a task_id for polling.
Text description for the image. Max 5000 characters.
text-to-image or edit. Auto-detected if images is provided. Defaults to text-to-image.
Image URLs for editing. Required when type is edit. Max 14 images.
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.
1k, 2k, or 4k. Defaults to 1k.
png or jpeg. Defaults to png.
Request Example — Text-to-Image
| 1 | curl -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
| 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 →
/api/statusPoll this endpoint to check the progress of your task. We recommend polling every 2-3 seconds.
The task ID received from the generate endpoint.
Request Example
| 1 | curl -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 | } |
Error Codes
| Code | Description |
|---|---|
| 200 OK | Success |
| 400 Requisição Inválida | Bad Request — missing or invalid parameters |
| 401 Não autorizado | Unauthorized — missing or invalid API key |
| 402 | Insufficient Credits — top up your account |
| 404 Não encontrado | Not Found — task does not exist |
| 500 Erro Interno do Servidor | Internal Server Error — retry or contact support |
Need help? Contact Support