上传并生成
上传源图片并在 Buble 生成请求中使用。
上传并生成
这个端到端示例会先上传一张源图片,然后用它创建图生图任务。
1. 上传源图片
curl https://buble.ai/api/v1/files \
-H "Authorization: Bearer $BUBLE_API_KEY" \
-F "file=@./room.png" \
-F "file_type=image" \
-F "model=google/nano-banana-pro" \
-F "mode=image_to_image"保存返回的 data.url。
2. 创建生成任务
curl https://buble.ai/api/v1/generations \
-H "Authorization: Bearer $BUBLE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "google/nano-banana-pro",
"mode": "image_to_image",
"prompt": "Redesign this room as a premium modern Japanese-inspired interior with warm oak, paper lantern lighting, low furniture, and calm editorial styling",
"image_urls": ["https://example.com/uploaded-room.png"],
"aspect_ratio": "16:9",
"resolution": "1K",
"output_format": "png"
}'3. 轮询结果
curl https://buble.ai/api/v1/generations/YOUR_GENERATION_ID \
-H "Authorization: Bearer $BUBLE_API_KEY"Node.js 版本
import fs from 'node:fs';
const fileForm = new FormData();
fileForm.append(
'file',
new Blob([fs.readFileSync('./room.png')], { type: 'image/png' }),
'room.png'
);
fileForm.append('file_type', 'image');
fileForm.append('model', 'google/nano-banana-pro');
fileForm.append('mode', 'image_to_image');
const upload = await fetch('https://buble.ai/api/v1/files', {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.BUBLE_API_KEY}` },
body: fileForm,
});
const { data: uploaded, error: uploadError } = await upload.json();
if (uploadError) throw new Error(uploadError.message);
const generation = await fetch('https://buble.ai/api/v1/generations', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.BUBLE_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'google/nano-banana-pro',
mode: 'image_to_image',
prompt:
'Redesign this room as a premium modern Japanese-inspired interior.',
image_urls: [uploaded.url],
aspect_ratio: '16:9',
resolution: '1K',
output_format: 'png',
}),
});
const { data: task, error } = await generation.json();
if (error) throw new Error(error.message);
console.log(task.id);