Developer API
Generate images and videos from your own code with a REST API and an API key.
The Nano Banana REST API lets your code and agents generate images and videos with the same models, prices and credits as the website.
Quick start
Create an API key in your account settings. The key is shown only once, so store it somewhere safe. Manage API keys
Send a generation request, then poll the returned task until it finishes.
curl -X POST https://nanobanana0.com/api/v1/images \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt": "a lighthouse at dawn", "dry_run": true}'Authentication
Send the key in the Authorization header as a Bearer token. Keys start with nb0_. Never put a key in client-side code or a public repository; delete it in settings if it leaks.
Authorization: Bearer nb0_...Each key allows 60 requests per minute, and an account can hold up to 10 keys. Over the limit the API answers 429 with a Retry-After header.
Endpoints
https://nanobanana0.com/api/v1
| Method | Path | Description |
|---|---|---|
| POST | /images | Start an image generation. Returns 202 with a task. |
| POST | /videos | Start a video generation. Returns 202 with a task. |
| GET | /tasks/{id} | Status and outputs of a task. |
| GET | /models | Models with their parameters and credit prices. |
| GET | /credits | Your credit balance. |
Request body
| Field | Details |
|---|---|
prompt | Required. What to generate, up to 4000 characters. |
model | Model id from /models. Omit it to use the default model. |
params | Model parameters such as aspect_ratio, as listed for the model in /models. |
count | Number of outputs, within the range the model allows. |
reference_ids | IDs of reference images already uploaded to your account, up to 16. |
mode | Input mode: text, image or reference. Inferred from the inputs when omitted. |
dry_run | When true, validates and prices the request without charging credits or starting a task. |
Examples
Generate an image
curl -X POST https://nanobanana0.com/api/v1/images \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt": "a lighthouse at dawn", "params": {"aspect_ratio": "16:9"}}'Poll the task
curl https://nanobanana0.com/api/v1/tasks/TASK_ID \
-H "Authorization: Bearer $API_KEY"{
"id": "TASK_ID",
"object": "task",
"status": "succeeded",
"kind": "image",
"credits_charged": 10,
"credits_refunded": 0,
"outputs": [
{ "index": 0, "status": "succeeded", "url": "https://...", "media_type": "image/png" }
]
}Get a quote without spending credits
curl -X POST https://nanobanana0.com/api/v1/images \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"prompt": "a lighthouse at dawn", "dry_run": true}'Task status
A task is processing until every output finishes. It then ends as succeeded, partial (some outputs failed) or failed. Credits are charged when the task starts, and credits for failed outputs are refunded. Poll every few seconds; output URLs appear as each output succeeds.
Errors
{ "error": "Not enough credits", "code": "insufficient_credits" }| HTTP status | Code | Meaning |
|---|---|---|
| 400 | invalid_request, model_unavailable | The request is invalid, or the model is not available. |
| 401 | unauthorized | The API key is missing, wrong or deleted. |
| 402 | insufficient_credits | Not enough credits for this request. |
| 403 | forbidden | The account cannot use this resource, or is suspended. |
| 404 | not_found | The task or resource does not exist. |
| 429 | rate_limited | Too many requests. Wait for the Retry-After seconds. |
| 502 | upstream_unavailable | The generation provider is temporarily unavailable. Try again later. |
| 500 | internal_error | Unexpected server error. Try again later. |
For AI agents
AI assistants can use Nano Banana through the MCP server, or read the Skill file to learn how to call this API.