Nano Banana 2.1 API
Nano Banana 2.1 文字生圖與圖像編輯模型的完整 API 參考文件。
模型版本
此 API 支援兩種模型版本:
快速比較
支援的長寬比
兩個模型皆支援 14 種長寬比:
16:9, 9:16, 1:1, 3:2, 2:3, 3:4, 4:3, 5:4, 4:5, 21:9, 1:4, 4:1, 1:8, 8:1
透過獨立的數值參數 width 與 height 指定比例;例如,width: 16 與 height: 9 表示選擇 16:9。這些值表示比例,而非輸出圖像的像素尺寸。
Nano Banana 2.1(文字生圖)
端點
POST /api/v1/image/task
身分驗證
Authorization: Bearer YOUR_API_KEY
請求參數
必填參數
注意: width:height 比例必須為以下之一:16:9、9:16、1:1、3:2、2:3、3:4、4:3、5:4、4:5、21:9、1:4、4:1、1:8、8:1。
選填參數
請求範例
const response = await fetch('https://api.flaq.ai/api/v1/image/task', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model_name: 'nano-banana-2.1',
prompt: 'A serene mountain landscape at sunset',
width: 16,
height: 9,
resolution: '2k',
enable_web_search: true,
enable_image_search: false
})
});
const { data } = await response.json();
const taskId = data.task_id;
Nano Banana 2.1 Edit(圖像編輯)
端點
POST /api/v1/image/task
請求參數
必填參數
注意: width:height 比例必須為上文列出的 14 種支援比例之一。
選填參數
單圖編輯範例
{
model_name: 'nano-banana-2.1-edit',
prompt: 'Change the sky to sunset colors',
width: 16,
height: 9,
resolution: '2k',
image_url_list: ['https://example.com/image.jpg'],
enable_web_search: false,
enable_image_search: true
}
多圖合成範例
{
model_name: 'nano-banana-2.1-edit',
prompt: 'Combine these images into a cohesive landscape',
width: 16,
height: 9,
resolution: '2k',
image_url_list: ['https://example.com/image1.jpg', 'https://example.com/image2.jpg', 'https://example.com/image3.jpg'],
enable_web_search: false,
enable_image_search: false
}
計費說明: 參考圖從第一張起按張計費。每啟用一項搜尋選項,每次生成都會另外收取固定費用,與圖像數量無關。具體費率請查看目前的價格。
回應格式
初始回應
{
"code": 0,
"message": "success",
"data": {
"task_id": "{task_id}",
"response_url": "https://api.flaq.ai/api/v1/image/{task_id}",
"task_status": "submitted"
}
}
輪詢回應
{
"code": 0,
"message": "success",
"data": {
"task_id": "{task_id}",
"response_url": "https://api.flaq.ai/api/v1/image/{task_id}",
"task_status": "processing",
"task_status_msg": null,
"task_result": null
}
}
成功回應
{
"code": 0,
"message": "success",
"data": {
"task_id": "{task_id}",
"response_url": "https://api.flaq.ai/api/v1/image/{task_id}",
"task_status": "succeed",
"task_status_msg": null,
"task_result": {
"credit": 0.074,
"images": [
{
"url": "https://example.com/generated-image.png"
}
]
}
}
}
狀態值
submitted:任務已接受
processing:任務正在執行
succeed:任務已成功完成
failed:任務失敗
最佳實務
文字生圖建議
- 描述圖像: 在提示詞中包含主體、光線與構圖。
- 選擇解析度: 每次請求皆須傳入
1k、2k 或 4k。
- 選擇長寬比: 傳入與 14 種支援比例之一對應的
width 與 height 值。
- 選擇搜尋選項: 省略任一搜尋旗標時,其預設值為
false;需要時將其設為 true。
圖像編輯建議
- 提供參考圖: 在
image_url_list 中提供 1 至 14 個可存取的圖像 URL。
- 描述編輯內容: 在提示詞中說明需要更改或保留的內容。
- 選擇輸出設定: 提供必填的
resolution、width 與 height 值。
- 選擇搜尋選項: 網頁搜尋與圖像搜尋可分別啟用。