Skip to navigation

Replace background with GPT Image 2

Replace the background of an image from a text prompt while keeping the automatically detected foreground subject; no mask is needed. Upload the source image using multipart/form-data. Returns a generation_id; poll GET /v2/generations/{generation_id} or supply a webhook_url.

Authentication

Api-Keystring

API key for access control. Use in the header with the name "Api-Key"

Query parameters

dry_runbooleanOptionalDefaults to false

When true, the request is validated and priced but not run: nothing is generated, stored, or billed, and no safety review is performed. The response is a PriceQuote object instead of the usual response for this endpoint. Send exactly the request you would send to generate, so the quote reflects the same options.

Request

The source image and a prompt describing its new background.
imagefileRequired
The source image. JPEG, PNG, WEBP, HEIF, AVIF, GIF, BMP, TIFF, and MPO are supported, up to 50 MB. Multipart requests only.
promptstringRequiredformat: "\S"1-4000 characters

Plain-language description of the desired new background.

qualityenumOptionalDefaults to high

The generation quality level. Defaults to high.

Allowed values:
num_imagesintegerOptional1-8Defaults to 1
The number of images to generate.
privatebooleanOptional
Whether to keep the result private. When omitted, defaults to your plan's setting. Enterprise generations are always private.
webhook_urlstringOptionalformat: "uri"<=2048 characters

HTTPS URL that Ideogram delivers the generated result to. Ideogram sends a JSON POST to this URL once all images for the request have finished generating. The body mirrors the synchronous generate response: request_id, created, and a data array containing every generated image (url, prompt, resolution, seed, is_image_safe). Each delivery is signed with Ed25519 and verifiable against the public keys at https://api.ideogram.ai/v1/.well-known/jwks.json. Must be HTTPS; private and loopback hosts and the cloud metadata service are rejected.

Response

Background replacement accepted for asynchronous processing.
generation_idstring

The generation ID to poll with GET /v2/generations/{generation_id}.

Errors

400
Bad Request Error
401
Unauthorized Error
402
Payment Required Error
403
Forbidden Error
404
Not Found Error
422
Unprocessable Entity Error
429
Too Many Requests Error
503
Service Unavailable Error