Nano Banana Images API 串接說明
本文介紹 Nano Banana Images API 的串接與使用。該介面支援兩種功能:影像生成(generate) 與 影像編輯(edit)。
¶ 申請流程
要使用 Nano Banana Images API,首先到 零壹AI 控制台 取得您的 API Token,留作備用。

如果你尚未登入或註冊,系統會自動跳轉到登入頁面邀請你註冊和登入,完成後會自動返回目前頁面。
通用應用程式的 API Key 可用於帳號已開放的服務;專用應用程式的 Key 按該應用程式的服務範圍使用。請檢查 Key 的權限、有效期限和額度,並確認應用程式餘額足以支付本次請求。可用試用額度以帳號顯示為準,餘額不足時點擊「儲值」按鈕即可。
📘 完整文件:Nano Banana Images API →
¶ 介面概覽
- 基礎 URL:
https://api.01ai.cloud - 端點:
POST /nano-banana/images - 驗證方式:HTTP Header 中帶入
authorization: Bearer {token} - 請求標頭:
accept: application/jsoncontent-type: application/json
- 動作(action):
generate:根據文字提示詞生成圖片edit:基於指定圖片進行編輯
- 模型(model)(選填):
nano-banana(預設):基於 Gemini 2.5 Flash Image,速度快,成本低nano-banana-2-lite:基於 Gemini 3.1 Flash Lite Image,僅支援 1K,生成速度快nano-banana-2:基於 Gemini 3.1 Flash Image Preview,Pro 級品質 + Flash 速度nano-banana-2.1:新一代高效影像模型,支援 1K、2K、4K 圖片生成與編輯nano-banana-pro:基於 Gemini 3 Pro Image Preview,最高品質nano-banana:official、nano-banana-2-lite:official、nano-banana-2:official、nano-banana-pro:official:對應模型的官方管道版本,畫質與穩定性更佳,計費不同
- 非同步回呼:選填,透過
callback_url接收任務完成通知與結果 - 圖片數量:選填,透過
count指定 1–4 張,預設 1 張;每張圖片由獨立的生成呼叫完成;一般技術失敗或供應商安全拒絕只影響對應的呼叫,其餘成功圖片照常回傳,並按實際成功張數計費 - Nano Banana 2 按張計費:
nano-banana-2的4K為 0.33 Credits/張,1K和2K為 0.28 Credits/張。以成功回傳的張數為準。
¶ 快速開始:生成圖片(action=generate)
最少必填參數:action、prompt
當你只想根據提示詞直接生成圖片時,設定 action 為 generate,並提供清晰的 prompt 即可。
¶ 請求範例(cURL)
curl -X POST 'https://api.01ai.cloud/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
}'
¶ 請求範例(Python)
import requests
url = "https://api.01ai.cloud/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())
¶ 成功回傳範例
{
"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"
}
]
}
¶ 欄位說明
success:本次請求是否成功。task_id:任務 ID。trace_id:鏈路追蹤 ID,便於排查問題。count:請求生成或編輯的圖片數量,支援 1–4,預設 1。data只包含生成成功的圖片,並按實際回傳張數計費。每個生成呼叫都強制使用供應商原生安全政策;某個呼叫被拒不會影響其他成功的呼叫,全部呼叫均被拒時回傳 403。data[]:結果清單。prompt:用於生成的提示詞(回顯)。image_url:生成圖片的直連 URL。
註:
/nano-banana/images僅需action與prompt即可生成圖片
¶ 編輯圖片(action=edit)
當你希望基於現有圖片進行編輯時,設定 action 為 edit,並透過 image_urls 傳入待編輯的圖片連結清單(1 張或多張),同時提供描述編輯目標的 prompt。
比如這裡我們提供一張人物照片、一張衣服照片,讓人物穿上這件衣服,就可以同時傳入圖片連結,並且指定 action 為 edit,URL 可以是 HTTP URL,以 https 或 http 協定的公開可存取連結,也可以是 Base64 編碼的圖片,如 data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA+gAAAVGCAMAAAA6u2FyAAADAFBMVEXq6uwdHCEeHyMdHS....
¶ 請求範例(cURL)
curl -X POST 'https://api.01ai.cloud/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
}'
¶ 請求範例(Python)
import requests
url = "https://api.01ai.cloud/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())
¶ 成功回傳範例
{
"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"
}
]
}
¶ 欄位說明
image_urls[]:待編輯圖片 URL 清單(必須可從公網存取)。可傳多張,服務會結合這些素材與prompt完成編輯。- 其餘欄位與「生成圖片」回傳相同。
¶ 非同步回呼(可選,建議)
生成或編輯可能需要一些時間。為避免長連線占用資源,建議透過 callback_url 使用 Webhook 回呼:
- 在請求本文中新增
callback_url,例如你的伺服器端 Webhook 位址(需可從公網存取,支援 POST JSON)。 - API 會 立即回傳 包含
task_id的回應(或包含基本結果)。 - 當任務完成後,平台將以
POST的方式將完整 JSON 傳送至callback_url。你可以透過task_id將請求與結果關聯。
回呼負載範例(欄位結構與同步成功回傳一致):
{
"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"
}
]
}
¶ 錯誤處理
呼叫失敗時會回傳標準錯誤格式與追蹤 ID。常見錯誤如下:
- 400
token_mismatched:請求不合法或參數錯誤。 - 400
api_not_implemented:介面未實作(請聯絡支援)。 - 401
invalid_token:驗證失敗或缺少 Token。 - 403
forbidden:提供方原生安全策略拒絕了請求或生成結果。該呼叫不會回傳圖片,也不會計費;多圖請求仍可回傳並計費其他成功呼叫。 - 429
too_many_requests:請求頻率超過限制。 - 500
api_error:伺服器端異常。
¶ 錯誤回應範例
{
"success": false,
"error": {
"code": "api_error",
"message": "Internal server error."
},
"trace_id": "2cf86e86-22a4-46e1-ac2f-032c0f2a4e89"
}
¶ 參數對照與注意事項
- 必填:
action、prompt - 編輯專用:
image_urls(陣列,至少 1 項) - 可選:
model(預設nano-banana,可選nano-banana-2-lite、nano-banana-2、nano-banana-2.1、nano-banana-pro;除nano-banana-2.1外還有對應的:official官方管道版本)、aspect_ratio(auto或具體寬高比,如1:1、16:9)、resolution(解析度,如1K、2K、4K;nano-banana-2-lite僅支援1K)、callback_url(用於非同步回呼) - Headers:必須提供
authorization: Bearer {token};accept建議設為application/json - 圖片可存取性:
image_urls必須為可從公網存取的直接連結(HTTP/HTTPS),建議使用 HTTPS - 冪等與追蹤:保留
task_id與trace_id,便於故障排查與結果關聯
明確傳入 "aspect_ratio": "auto" 會根據提示詞裡的比例、方向或版面配置選擇最接近的預設值,適用於生成和編輯。例如提示詞寫「YouTube 縮圖」,就可以選到 16:9。提示詞沒有尺寸要求或自動判斷不可用時,文字生成圖片使用預設畫幅,圖片編輯跟隨第一張參考圖,使用最接近的受支援比例。省略該欄位時使用預設畫幅或參考圖比例。已有明確的畫幅要求時,直接傳入具體比例。

