Text-to-Image
Generate an image from a text prompt with Nano Banana 2 Lite.
The model ID is gemini-3.1-flash-lite-image, without a -preview suffix.
This model supports 1K output only and has an independent price and API-key
permission. Enabling Nano Banana 2 does not automatically enable Nano Banana 2 Lite.
Do not request 2K or 4K; those sizes are not configured for this model.
POST /api/v1/generationsThis is the asynchronous native API: a successful request returns 202 Accepted.
Poll GET /api/v1/jobs/{job_id} to retrieve the result.
For a synchronous Gemini-compatible call, see the SDK quickstart.
Headers
Section titled “Headers”| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer <MOONEZ_API_KEY>. The key must have permission for Nano Banana 2 Lite. |
Content-Type | Yes | application/json |
Idempotency-Key | No | Repeating the same key returns the original job_id; see Authentication. |
| Field | Required | Description |
|---|---|---|
model | Yes | gemini-3.1-flash-lite-image |
prompt | Yes | The prompt, at least one character long. |
aspect_ratio | Yes | Aspect ratio, such as 16:9 or auto. |
resolution | Yes | Resolution: 1K only. |
callback_url | No | Webhook URL for this job. |
metadata | No | An arbitrary JSON object. |
timeout | No | Total execution budget in seconds, from 30 to 1200. |
With aspect_ratio: "auto", Moonez.ai does not specify an aspect ratio to the provider.
This value applies to the native API; in the Gemini-compatible API, simply omit
generationConfig.imageConfig.aspectRatio.
For text-only input, omit input_images_urls and input_images_base64.
For editing, see Image-to-image.
Request examples
Section titled “Request examples”Set your key in the MOONEZ_API_KEY environment variable.
curl -sS https://api.moonez.ai/api/v1/generations \ -H "Authorization: Bearer $MOONEZ_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gemini-3.1-flash-lite-image", "prompt": "Draw a red panda astronaut against a nebula.", "aspect_ratio": "16:9", "resolution": "1K" }'import os
import requests
response = requests.post( "https://api.moonez.ai/api/v1/generations", headers={"Authorization": f"Bearer {os.environ['MOONEZ_API_KEY']}"}, json={ "model": "gemini-3.1-flash-lite-image", "prompt": "Draw a red panda astronaut against a nebula.", "aspect_ratio": "16:9", "resolution": "1K", }, timeout=30,)response.raise_for_status()print(response.json())const response = await fetch("https://api.moonez.ai/api/v1/generations", { method: "POST", headers: { Authorization: `Bearer ${process.env.MOONEZ_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ model: "gemini-3.1-flash-lite-image", prompt: "Draw a red panda astronaut against a nebula.", aspect_ratio: "16:9", resolution: "1K", }), signal: AbortSignal.timeout(30_000),});if (!response.ok) throw new Error(`Generation request failed: ${response.status}`);console.log(await response.json());Response
Section titled “Response”202 Accepted means the job has been accepted, not that generation is complete.
{ "job_id": "0193a7f2-1c4a-7e0b-9b3a-2f1d8c6e4a55", "status": "queued", "status_url": "/api/v1/jobs/0193a7f2-1c4a-7e0b-9b3a-2f1d8c6e4a55"}Poll status_url with the same Authorization header until the status is done
or failed. If the model returns an image, its link is available in result.image_url.
The model may also return text; check the result contents.
See API errors for 401, 402, 403, 422, and 503 responses.