模型 API 接入文件
Nano Banana 2 API 接入文件
透過 Rivya Public API v1 呼叫 Nano Banana 2,包含模型 ID nano-banana-2、輸入類型、參數、Files API 規則、點數和回應範例。
API 可呼叫文字或 URL 可用;參考模式使用 Files API圖片
API 模型 ID
nano-banana-2
輸入類型
text, file
Files API
參考素材模式需要
基礎點數
5
能力類型
圖片
計費方式
FIXED
Prompt 上限
20000 字元
請求欄位
模型 ID 放在頂層欄位。模型專屬控制項放入 params。
| Key | 類型 | 必填 | 預設值 | 說明 |
|---|---|---|---|---|
| model | string | 是 | nano-banana-2 | 使用 nano-banana-2 作為 API 模型 ID。 |
| prompt | string | 是 | - | 這個模型最多 20000 個字元。 |
| params | object | 否 | - | 模型專屬參數物件。可用 keys 請見下方參數表。 |
| client_request_id | string | 否 | - | 可選的用戶端請求 ID,方便你在自己的系統中追蹤請求。 |
模型參數
| Key | 類型 | 必填 | 預設值 | 範圍 | 選項 | 說明 |
|---|---|---|---|---|---|---|
| aspect_ratio | select | 否 | auto | - | auto, 1:1, 16:9, 9:16, 3:2, 2:3, 4:3, 3:4, 5:4, 4:5, 21:9, 4:1, 1:4, 8:1, 1:8 | 長寬比 |
| resolution | select | 否 | 1K | - | 1K, 2K, 4K | 解析度 |
| output_format | select | 否 | jpg | - | jpg, png | 輸出格式 |
| google_search | select | 否 | false | - | false, true | Google Search |
上傳策略
先上傳參考文件,再把回傳的 URL 和 durationToken 放入 params.referenceMediaItems。
參考素材規則
參考圖片: 圖片專案最多可上傳 14 個圖片檔案。
最大文件數
14
支援文件類型
image
Duration token
影片和音訊參考素材需要時長驗證時,應攜帶 /api/v1/files 回傳的 durationToken。
| kind | 大小上限 | MIME 類型 |
|---|---|---|
| image | 30 MB | image/jpeg, image/png, image/webp |
最小請求
{
"model": "nano-banana-2",
"prompt": "A clean editorial product image on a soft studio background",
"params": {
"aspect_ratio": "auto",
"resolution": "1K",
"output_format": "jpg",
"google_search": "false"
}
}參考文件請求
{
"model": "nano-banana-2",
"prompt": "A clean editorial product image on a soft studio background",
"params": {
"aspect_ratio": "auto",
"resolution": "1K",
"output_format": "jpg",
"google_search": "false",
"referenceMediaItems": [
{
"url": "https://cdn.example.com/reference-image.png",
"kind": "image",
"name": "reference-image.png",
"mimeType": "image/png"
}
]
}
}建立回應
建立 endpoint 會回傳公開 task id。繼續輪詢狀態 endpoint,直到任務成功或失敗。
{
"id": "task_nano_banana_2_example",
"status": "queued",
"model": "nano-banana-2",
"reserved_credits": 5,
"final_credits": 0,
"created_at": "2026-05-11T00:00:00.000Z",
"updated_at": "2026-05-11T00:00:00.000Z",
"result": null,
"error": null
}常見錯誤
validation_failed, insufficient_credits, idempotency_conflict, rate_limited, not_found
部分模式需要透過 Files API 上傳參考素材。