GPT Image 2 API

GPT Image 2 is suited for high-instruction-following image generation and image editing workflows with larger prompt budgets.

Model keys

  • openai/gpt-image-2 — GPT Image 2

Supported modes and inputs

Model Mode Label Input requirements
openai/gpt-image-2 text_to_image Text to Image Prompt max 20000 chars
openai/gpt-image-2 image_to_image Image to Image Prompt max 20000 chars
Images reference: 1-16 files, 10 MB, formats jpg, png, webp

Options

Model Option Default Allowed values Applies to
openai/gpt-image-2 resolution 1K 1K, 2K, 4K All modes
openai/gpt-image-2 aspect_ratio 16:9 auto, 1:1, 16:9, 9:16, 4:3, 3:4 All modes

Pricing

Model Pricing
openai/gpt-image-2 1 credit per image; option multipliers: resolution={"1K":1,"2K":1,"4K":2}

Production guidance

  • Pass mode explicitly.
  • Use only option values listed above.
  • Upload media with POST /api/v1/files before calling media-input modes.
  • Use the exact model key for the variant you want.

Example: text to image

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": "A premium editorial product image of a minimalist ceramic coffee grinder on a warm walnut counter, soft studio lighting",
    "aspect_ratio": "16:9",
    "resolution": "1K"
  }'

Example: image to image

Upload an image first, then pass the returned URL to image_urls.

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": "image_to_image",
    "prompt": "Transform the source into a clean commercial product image while preserving the main object",
    "image_urls": ["https://example.com/source.png"],
    "aspect_ratio": "16:9",
    "resolution": "1K"
  }'

SDK examples

The examples below use this page's public model key, mode, and parameter values. They assume you have already initialized the SDK client as shown in the Quickstart and imported the required language SDK types. For media-input modes, upload local files first and pass the returned URL through public fields such as image_urls, start_frame, or video_urls.

JavaScript / TypeScript

const task = await buble.generations.create({
  model: 'openai/gpt-image-2',
  mode: 'text_to_image',
  prompt:
    'A premium editorial product image of a minimalist ceramic coffee grinder on a warm walnut counter, soft studio lighting',
  aspect_ratio: '16:9',
  resolution: '1K',
});

const result = await buble.generations.wait(task.data.id);
console.log(result.data.result?.images?.[0]?.url);

Python

task = client.generations.create(
    model="openai/gpt-image-2",
    mode="text_to_image",
    prompt="A premium editorial product image of a minimalist ceramic coffee grinder on a warm walnut counter, soft studio lighting",
    aspect_ratio="16:9",
    resolution="1K",
)

result = client.generations.wait(task["data"]["id"])
print(result["data"]["result"]["images"][0]["url"])

Go

task, err := client.Generations.Create(ctx, &buble.CreateGenerationRequest{
	Model:  "openai/gpt-image-2",
	Mode:   "text_to_image",
	Prompt: "A premium editorial product image of a minimalist ceramic coffee grinder on a warm walnut counter, soft studio lighting",
	Params: map[string]any{
		"aspect_ratio": "16:9",
		"resolution": "1K",
	},
})
if err != nil {
	return err
}

result, err := client.Generations.Wait(ctx, task.Data.ID)
if err != nil {
	return err
}
fmt.Println(result.Data.Result.Images[0].URL)

Rust

let task = client.generations().create(
    CreateGenerationRequest::new("openai/gpt-image-2")
        .mode("text_to_image")
        .prompt("A premium editorial product image of a minimalist ceramic coffee grinder on a warm walnut counter, soft studio lighting")
        .param("aspect_ratio", "16:9")?
        .param("resolution", "1K")?,
).await?;

let result = client
    .generations()
    .wait(&task.data.id, WaitOptions::default())
    .await?;

Swift

let task = try await client.generations.create(
    try CreateGenerationRequest(model: "openai/gpt-image-2")
        .mode("text_to_image")
        .prompt("A premium editorial product image of a minimalist ceramic coffee grinder on a warm walnut counter, soft studio lighting")
        .param("aspect_ratio", "16:9")
        .param("resolution", "1K")
)

let result = try await client.generations.wait(task.data.id)
print(result.data.result?.images?.first?.url.absoluteString ?? "")

Dart / Flutter

final task = await client.generations.create(
  CreateGenerationRequest(
    model: 'openai/gpt-image-2',
    mode: 'text_to_image',
    prompt: 'A premium editorial product image of a minimalist ceramic coffee grinder on a warm walnut counter, soft studio lighting',
  ).withParam('aspect_ratio', '16:9').withParam('resolution', '1K'),
);

final result = await client.generations.wait(task.data.id);
print(result.data.result?.images.firstOrNull?.url);

Elixir

{:ok, task} =
  Buble.Generations.create(client, %{
    model: "openai/gpt-image-2",
    mode: "text_to_image",
    prompt: "A premium editorial product image of a minimalist ceramic coffee grinder on a warm walnut counter, soft studio lighting",
    aspect_ratio: "16:9",
    resolution: "1K"
  })

{:ok, result} = Buble.Generations.wait(client, task["data"]["id"])
IO.puts(result["data"]["result"]["images"] |> List.first() |> Map.fetch!("url"))

Java

Envelope<GenerationTask> task = client.generations().create(
        CreateGenerationRequest.builder()
                .model("openai/gpt-image-2")
                .mode("text_to_image")
                .prompt("A premium editorial product image of a minimalist ceramic coffee grinder on a warm walnut counter, soft studio lighting")
                .param("aspect_ratio", "16:9")
                .param("resolution", "1K")
                .build());

Envelope<GenerationTask> result = client.generations().wait(task.getData().getId());

.NET

var task = await client.Generations.CreateAsync(new CreateGenerationRequest
{
    Model = "openai/gpt-image-2",
    Mode = "text_to_image",
    Prompt = "A premium editorial product image of a minimalist ceramic coffee grinder on a warm walnut counter, soft studio lighting"
}.WithParam("aspect_ratio", "16:9").WithParam("resolution", "1K"));

var result = await client.Generations.WaitAsync(task!.Data!.Id!);

PHP

$task = $client->generations()->create(
    CreateGenerationRequest::make(
        model: 'openai/gpt-image-2',
        mode: 'text_to_image',
        prompt: 'A premium editorial product image of a minimalist ceramic coffee grinder on a warm walnut counter, soft studio lighting',
    )
    ->withParam('aspect_ratio', '16:9')
    ->withParam('resolution', '1K')
);

$result = $client->generations()->wait($task['data']['id']);

Ruby

task = client.generations.create(
  model: "openai/gpt-image-2",
  mode: "text_to_image",
  prompt: "A premium editorial product image of a minimalist ceramic coffee grinder on a warm walnut counter, soft studio lighting",
  aspect_ratio: "16:9",
  resolution: "1K"
)

result = client.generations.wait(task.dig("data", "id"))
puts result.dig("data", "result", "images", 0, "url")