Nano Banana Images API Integration Guide
This article introduces the integration and usage of the Nano Banana Images API. This interface supports two capabilities: Image Generation (generate) and Image Editing (edit).
¶ Application Process
To use the Nano Banana Images API, first go to the AI 聚合|元宪智能 Console to obtain your API Token and keep it for future use.
If you are not logged in or registered, you will be automatically redirected to the login page and prompted to register or log in. Once completed, you will automatically return to the current page.
One API Token can be used to call all services on the platform. There is no need to apply for each service separately. Upon your first application, you will receive free credits to try the service. When your credits are insufficient, you can recharge your general balance through the Console.
📘 Full Documentation: Nano Banana Images API →
¶ API Overview
- Base URL:
https://api.yxai-tech.top - Endpoint:
POST /nano-banana/images - Authentication Method:Include
authorization: Bearer {token}in the HTTP Header. - Request Headers:
accept: application/jsoncontent-type: application/json
- Actions (action):
generate: Generate images based on text prompts.edit: Edit images based on provided images.
- Models (model) (optional):
nano-banana(default): Based on Gemini 2.5 Flash Image, offering fast speed and low cost.nano-banana-2-lite: Based on Gemini 3.1 Flash Lite Image, supports only 1K resolution and offers fast generation.nano-banana-2: Based on Gemini 3.1 Flash Image Preview, delivering Pro-level quality with Flash speed.nano-banana-2.1: A new-generation efficient image model that supports 1K, 2K, and 4K image generation and editing.nano-banana-pro: Based on Gemini 3 Pro Image Preview, delivering the highest quality.nano-banana:official,nano-banana-2-lite:official,nano-banana-2:official,nano-banana-pro:official: Official channel versions of the corresponding models, offering better image quality and stability, with different pricing.
- Asynchronous Callback: Optional. Receive task completion notifications and results through
callback_url. - Number of Images: Optional. Specify 1–4 images through
count. The default is 1 image. Each image is generated through an independent generation call. Ordinary technical failures or safety refusals from the provider only affect the corresponding call. Other successfully generated images will still be returned, and billing is based on the actual number of successfully generated images. - Nano Banana 2 Per-Image Pricing: For
nano-banana-2,4Kcosts 0.33 Credits per image, while1Kand2Kcost 0.28 Credits per image. Billing is based on the number of successfully returned images.
¶ Quick Start: Generate Images (action=generate)
Minimum required parameters: action, prompt
When you only want to generate an image directly from a prompt, simply set action to generate and provide a clear prompt.
¶ Request Example (cURL)
curl -X POST 'https://api.yxai-tech.top/nano-banana/images' \
-H 'authorization: Bearer {token}' \
-H 'accept: application/json' \
-H 'content-type: application/json' \
-d '{
"action": "generate",
"model": "nano-banana-pro",
"prompt": "A photorealistic close-up portrait of an elderly Japanese ceramicist with deep, sun-etched wrinkles and a warm, knowing smile. He is carefully inspecting a freshly glazed tea bowl. The setting is his rustic, sun-drenched workshop. The scene is illuminated by soft, golden hour light streaming through a window, highlighting the fine texture of the clay. Captured with an 85mm portrait lens, resulting in a soft, blurred background (bokeh). The overall mood is serene and masterful. Vertical portrait orientation.",
"count": 1
}'
¶ Request Example (Python)
import requests
url = "https://api.yxai-tech.top/nano-banana/images"
headers = {
"authorization": "Bearer {token}",
"accept": "application/json",
"content-type": "application/json",
}
payload = {
"action": "generate",
"model": "nano-banana-pro",
"prompt": (
"A photorealistic close-up portrait of an elderly Japanese ceramicist "
"with deep, sun-etched wrinkles and a warm, knowing smile. He is carefully "
"inspecting a freshly glazed tea bowl. The setting is his rustic, sun-drenched "
"workshop. The scene is illuminated by soft, golden hour light streaming through "
"a window, highlighting the fine texture of the clay. Captured with an 85mm "
"portrait lens, resulting in a soft, blurred background (bokeh). The overall mood "
"is serene and masterful. Vertical portrait orientation."
),
"count": 1
}
resp = requests.post(url, json=payload, headers=headers)
print(resp.json())
¶ Successful Response Example
{
"success": true,
"task_id": "70e6931b-6e34-43db-9e36-8765e2809d04",
"trace_id": "60df8d38-f265-4986-aec7-75c9220bced2",
"data": [
{
"prompt": "A photorealistic close-up portrait of an elderly Japanese ceramicist with deep, sun-etched wrinkles and a warm, knowing smile. He is carefully inspecting a freshly glazed tea bowl. The setting is his rustic, sun-drenched workshop. The scene is illuminated by soft, golden hour light streaming through a window, highlighting the fine texture of the clay. Captured with an 85mm portrait lens, resulting in a soft, blurred background (bokeh). The overall mood is serene and masterful. Vertical portrait orientation.",
"image_url": "https://cdn.acedata.cloud/assets/examples/nanobanana/1d0160b4-93f9-4229-8926-ea9ef0bed336-34b3dc2195e8.png"
}
]
}
¶ Field Descriptions
success: Whether the current request was successful.task_id: Task ID.trace_id: Trace ID, used for troubleshooting.count: The number of images requested for generation or editing. Supports 1–4, with a default of 1.dataonly contains successfully generated images, and billing is based on the actual number of returned images. Each generation call is forced to use the provider's native safety policies. If one call is rejected, it will not affect other successful calls. If all calls are rejected, a 403 response will be returned.data[]: Result list.prompt: The prompt used for generation (returned in the response).image_url: Direct URL of the generated image.
Note:
/nano-banana/imagesonly requiresactionandpromptto generate images.
¶ Edit Images (action=edit)
When you want to edit an existing image, set action to edit, pass the list of images to be edited through image_urls (one or multiple images), and provide a prompt describing the editing objectives.
For example, here we provide a photo of a person and a photo of a piece of clothing, and let the person wear that clothing. We can pass in image links at the same time and specify the action as edit. The URL can be an HTTP URL, a publicly accessible link using the https or http protocol, or a Base64-encoded image, such as data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA+gAAAVGCAMAAAA6u2FyAAADAFBMVEXq6uwdHCEeHyMdHS....
¶ Request Example (cURL)
curl -X POST 'https://api.yxai-tech.top/nano-banana/images' \
-H 'authorization: Bearer {token}' \
-H 'accept: application/json' \
-H 'content-type: application/json' \
-d '{
"action": "edit",
"prompt": "let this man wear on this T-shirt",
"image_urls": [
"https://cdn.acedata.cloud/v8073y.png",
"https://cdn.acedata.cloud/44xlah.png"
],
"count": 1
}'
¶ Request Example (Python)
import requests
url = "https://api.yxai-tech.top/nano-banana/images"
headers = {
"authorization": "Bearer {token}",
"accept": "application/json",
"content-type": "application/json",
}
payload = {
"action": "edit",
"prompt": "let this man wear on this T-shirt",
"image_urls": [
"https://cdn.acedata.cloud/v8073y.png",
"https://cdn.acedata.cloud/44xlah.png"
],
"count": 1
}
resp = requests.post(url, json=payload, headers=headers)
print(resp.json())
¶ Successful Response Example
{
"success": true,
"task_id": "93f11baf-347b-4bb4-9520-8653cb46d6a3",
"trace_id": "a9063166-26ed-4451-85b5-54e896817c69",
"data": [
{
"prompt": "let this man wear on this T-shirt",
"image_url": "https://platform.cdn.acedata.cloud/nanobanana/8e9e0253-26f4-45b9-b3f8-ac1aed1c284b.png"
}
]
}
¶ Field Descriptions
image_urls[]: List of image URLs to be edited (must be publicly accessible). Multiple images can be provided, and the service will combine these materials with thepromptto complete the editing.- Other fields are the same as those returned by "Generate Image."
¶ Asynchronous Callback (Optional, Recommended)
Generation or editing may take some time. To avoid occupying resources with long-lived connections, it is recommended to use Webhook callbacks through callback_url:
- Add
callback_urlto the request body, such as your server-side Webhook address (must be publicly accessible and support POST JSON). - The API will return immediately with a response containing
task_id(or basic results). - When the task is completed, the platform will send the complete JSON to
callback_urlviaPOST. You can associate the request with the result usingtask_id.
Callback Payload Example (the field structure is consistent with the synchronous successful response):
{
"success": true,
"task_id": "6a97bf49-df50-4129-9e46-119aa9fca73c",
"trace_id": "9b4b1ff3-90f2-470f-b082-1061ec2948cc",
"data": [
{
"prompt": "a white siamese cat",
"image_url": "https://platform.cdn.acedata.cloud/nanobanana/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.png"
}
]
}
¶ Error Handling
When a request fails, a standard error format and trace ID will be returned. Common errors are as follows:
- 400
token_mismatched: Invalid request or incorrect parameters. - 400
api_not_implemented: The interface has not been implemented (please contact support). - 401
invalid_token: Authentication failed or Token is missing. - 403
forbidden: The provider's native safety policy rejected the request or generated result. This call will not return an image or incur charges; for multi-image requests, other successful calls may still be returned and charged. - 429
too_many_requests: Request rate limit exceeded. - 500
api_error: Server-side exception.
¶ Error Response Example
{
"success": false,
"error": {
"code": "api_error",
"message": "Internal server error."
},
"trace_id": "2cf86e86-22a4-46e1-ac2f-032c0f2a4e89"
}
¶ Parameter Reference and Notes
- Required:
action,prompt - For Editing Only:
image_urls(array, at least 1 item) - Optional:
model(defaults tonano-banana; options includenano-banana-2-lite,nano-banana-2,nano-banana-2.1, andnano-banana-pro; except fornano-banana-2.1, corresponding:officialversions from the official channel are also available),aspect_ratio(autoor a specific aspect ratio, such as1:1or16:9),resolution(resolution, such as1K,2K, or4K;nano-banana-2-liteonly supports1K),callback_url(for asynchronous callbacks) - Headers:
authorization: Bearer {token}must be provided; it is recommended to setaccepttoapplication/json - Image Accessibility:
image_urlsmust be direct links that are publicly accessible (HTTP/HTTPS); HTTPS is recommended - Idempotency and Tracking: Keep
task_idandtrace_idfor troubleshooting and result association
Explicitly passing "aspect_ratio": "auto" will select the closest preset based on the ratio, orientation, or layout specified in the prompt, and is suitable for both generation and editing. For example, if the prompt says "YouTube thumbnail," it can select 16:9. If the prompt does not specify size requirements or automatic selection is unavailable, text-to-image generation uses the default aspect ratio, while image editing follows the first reference image and uses the closest supported aspect ratio. If this field is omitted, the default aspect ratio or reference image ratio will be used. If there is already a clearly specified aspect ratio requirement, pass the specific ratio directly.

