文生图 API
图片模型使用 mode: "text_to_image"。
推荐模型
| 模型 | Key | 适用场景 |
|---|---|---|
| Nano Banana | google/nano-banana |
快速创意草图和轻量生产图片。 |
| Nano Banana Pro | google/nano-banana-pro |
专业商业视觉和更高质量输出。 |
| GPT Image 2 | openai/gpt-image-2 |
复杂指令跟随和布局敏感的图片。 |
Nano Banana Pro 示例
curl https://img2vid.net/api/v1/generations \
-H "Authorization: Bearer $BUBLE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "google/nano-banana-pro",
"mode": "text_to_image",
"prompt": "A premium hero image for a skincare serum bottle on translucent glass, soft reflections, editorial lighting",
"aspect_ratio": "16:9",
"resolution": "1K",
"output_format": "png"
}'
GPT Image 2 示例
curl https://img2vid.net/api/v1/generations \
-H "Authorization: Bearer $BUBLE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-image-2",
"mode": "text_to_image",
"prompt": "Create a clean editorial layout image showing a modern workspace with a laptop, notebook, and coffee. Keep the composition balanced with clear negative space on the right side.",
"aspect_ratio": "16:9",
"resolution": "1K"
}'
SDK 示例
下面的 SDK 代码与上方 HTTP 示例使用同一套公开 API 结构:model、mode、prompt、媒体 URL 等稳定字段直接传入,模型专属选项保持为扁平的生成参数。
这些代码使用 Nano Banana Pro 示例。如果使用 GPT Image 2,请把 model 改为 openai/gpt-image-2,并只保留该模型支持的参数。
TypeScript / JavaScript
import { Buble } from '@buble/sdk';
const buble = new Buble();
const task = await buble.generations.create({
model: 'google/nano-banana-pro',
mode: 'text_to_image',
prompt:
'A premium hero image for a skincare serum bottle on translucent glass, soft reflections, editorial lighting',
aspect_ratio: '16:9',
resolution: '1K',
output_format: 'png',
});
const result = await buble.generations.wait(task.data.id);
console.log(result.data);
Python
from buble_ai import Buble
client = Buble()
task = client.generations.create(
model='google/nano-banana-pro',
mode='text_to_image',
prompt='A premium hero image for a skincare serum bottle on translucent glass, soft reflections, editorial lighting',
aspect_ratio='16:9',
resolution='1K',
output_format='png',
)
result = client.generations.wait(task["data"]["id"])
print(result["data"])
Go
package main
import (
"context"
"fmt"
"log"
buble "github.com/bublehq/sdks/go"
)
func main() {
ctx := context.Background()
client := buble.NewClient()
task, err := client.Generations.Create(ctx, &buble.CreateGenerationRequest{
Model: "google/nano-banana-pro",
Mode: "text_to_image",
Prompt: "A premium hero image for a skincare serum bottle on translucent glass, soft reflections, editorial lighting",
Params: map[string]any{
"aspect_ratio": "16:9",
"resolution": "1K",
"output_format": "png",
},
})
if err != nil {
log.Fatal(err)
}
result, err := client.Generations.Wait(ctx, task.Data.ID)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", result.Data)
}
Rust
use buble::{Client, CreateGenerationRequest, WaitOptions};
#[tokio::main]
async fn main() -> buble::Result<()> {
let client = Client::from_env();
let task = client
.generations()
.create(
CreateGenerationRequest::new("google/nano-banana-pro")
.mode("text_to_image")
.prompt("A premium hero image for a skincare serum bottle on translucent glass, soft reflections, editorial lighting")
.param("aspect_ratio", "16:9")?
.param("resolution", "1K")?
.param("output_format", "png")?,
)
.await?;
let result = client
.generations()
.wait(&task.data.id, WaitOptions::default())
.await?;
println!("{:?}", result.data);
Ok(())
}
Swift
import Buble
let client = try BubleClient.fromEnvironment()
let task = try await client.generations.create(
try CreateGenerationRequest(model: "google/nano-banana-pro")
.mode("text_to_image")
.prompt("A premium hero image for a skincare serum bottle on translucent glass, soft reflections, editorial lighting")
.param("aspect_ratio", "16:9")
.param("resolution", "1K")
.param("output_format", "png")
)
let result = try await client.generations.wait(task.data.id)
print(result.data)
Dart / Flutter
import 'package:buble/buble.dart';
Future<void> main() async {
final client = BubleClient.fromEnvironment();
final task = await client.generations.create(
CreateGenerationRequest(
model: 'google/nano-banana-pro',
mode: 'text_to_image',
prompt:
'A premium hero image for a skincare serum bottle on translucent glass, soft reflections, editorial lighting',
).withParams({
'aspect_ratio': '16:9',
'resolution': '1K',
'output_format': 'png',
}),
);
final result = await client.generations.wait(task.data.id);
print(result.data.raw);
}
Elixir
client = Buble.Client.new!()
{:ok, task} =
Buble.Generations.create(client, %{
model: "google/nano-banana-pro",
mode: "text_to_image",
prompt:
"A premium hero image for a skincare serum bottle on translucent glass, soft reflections, editorial lighting",
aspect_ratio: "16:9",
resolution: "1K",
output_format: "png",
})
{:ok, result} = Buble.Generations.wait(client, get_in(task, ["data", "id"]))
IO.inspect(result["data"])
Java
import ai.buble.sdk.BubleClient;
import ai.buble.sdk.Envelope;
import ai.buble.sdk.generations.CreateGenerationRequest;
import ai.buble.sdk.generations.GenerationTask;
public class Example {
public static void main(String[] args) {
BubleClient client = BubleClient.fromEnv();
Envelope<GenerationTask> task = client.generations().create(
CreateGenerationRequest.builder()
.model("google/nano-banana-pro")
.mode("text_to_image")
.prompt("A premium hero image for a skincare serum bottle on translucent glass, soft reflections, editorial lighting")
.param("aspect_ratio", "16:9")
.param("resolution", "1K")
.param("output_format", "png")
.build()
);
Envelope<GenerationTask> result = client.generations().wait(task.getData().getId());
System.out.println(result.getData().getStatus());
}
}
.NET
using Buble.Sdk;
using Buble.Sdk.Generations;
var client = BubleClient.FromEnv();
var request = new CreateGenerationRequest
{
Model = "google/nano-banana-pro",
Mode = "text_to_image",
Prompt = "A premium hero image for a skincare serum bottle on translucent glass, soft reflections, editorial lighting",
}
.WithParam("aspect_ratio", "16:9")
.WithParam("resolution", "1K")
.WithParam("output_format", "png");
var task = await client.Generations.CreateAsync(request);
var result = await client.Generations.WaitAsync(task!.Data!.Id!);
Console.WriteLine(result.Data.Status);
PHP
<?php
use Buble\BubleClient;
use Buble\Generations\CreateGenerationRequest;
$client = BubleClient::fromEnv();
$request = new CreateGenerationRequest(
model: 'google/nano-banana-pro',
mode: 'text_to_image',
prompt: 'A premium hero image for a skincare serum bottle on translucent glass, soft reflections, editorial lighting',
);
$task = $client->generations()->create(
$request
->withParam('aspect_ratio', '16:9')
->withParam('resolution', '1K')
->withParam('output_format', 'png')
);
$result = $client->generations()->wait($task['data']['id']);
print_r($result['data']);
Ruby
require 'buble'
client = Buble::Client.new
task = client.generations.create(
model: 'google/nano-banana-pro',
mode: 'text_to_image',
prompt: 'A premium hero image for a skincare serum bottle on translucent glass, soft reflections, editorial lighting',
aspect_ratio: '16:9',
resolution: '1K',
output_format: 'png',
)
result = client.generations.wait(task['data']['id'])
puts result['data']