Skip to content
OpenAI logo

OpenAI GPT Image 2

Text-to-ImageOpenAIProxied

OpenAI's next-generation image model that creates and edits images from text prompts, with support for multiple quality levels, sizes, and output formats. Note: transparent backgrounds are not supported — use openai/gpt-image-1.5 for transparent PNGs.

Model Info
Terms and Licenselink
More informationlink
PricingView pricing in the Cloudflare dashboard

Usage

TypeScript
const response = await env.AI.run(
'openai/gpt-image-2',
{
prompt: 'A golden retriever puppy playing in autumn leaves',
},
{
gateway: { id: 'default' },
}
)
console.log(response)
Simple Generation

Examples

High Quality — Generate a high-quality detailed image
TypeScript
const response = await env.AI.run(
'openai/gpt-image-2',
{
prompt:
'A detailed botanical illustration of exotic tropical flowers with fine line work and watercolor textures',
quality: 'high',
},
{
gateway: { id: 'default' },
}
)
console.log(response)
High Quality
Custom Size — Generate a portrait-oriented image
TypeScript
const response = await env.AI.run(
'openai/gpt-image-2',
{
prompt:
'A towering redwood forest with sunbeams filtering through the canopy, misty atmosphere',
size: '1024x1536',
},
{
gateway: { id: 'default' },
}
)
console.log(response)
Custom Size
WebP Output — Generate an image in WebP format for smaller file size
TypeScript
const response = await env.AI.run(
'openai/gpt-image-2',
{
prompt:
'A neon-lit cyberpunk cityscape at night with rain-slicked streets and holographic billboards',
quality: 'high',
output_format: 'webp',
},
{
gateway: { id: 'default' },
}
)
console.log(response)
WebP Output
Image Edit — Edit an existing image by providing it in the images array as base64 (a raw string or a data:image/{png|jpeg|webp};base64,... URI). This routes the call to OpenAI's /v1/images/edits endpoint. The example uses a tiny 32x32 smiley-face PNG - real inputs are the full base64 encoding of your source image.
TypeScript
const response = await env.AI.run(
'openai/gpt-image-2',
{
prompt:
'Transform this cartoon smiley into a photorealistic 3D clay sculpture sitting on a marble pedestal, studio lighting',
images: [
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAnklEQVR42u2XQRLAIAgD8/839i/26qFCACm0ozPe1KwcQsAoXvgcAABxpwFowl4QWITHxW0LCBhxVngF4gKIirMQyBRnIJAtrkE8AuwWnyFEgKzfS1UA+3sWTju3BGAu7gKYIfBW+Q/AAQgBeMCkt1wVsLZjcwUYG2Z9wGLHZitWk1DEisubUYt2XB5IWkSyFqG0RSxvMZi0Gc1+Ox3fm00ZJ5mGVtkAAAAASUVORK5CYII=',
],
},
{
gateway: { id: 'default' },
}
)
console.log(response)
Image Edit
Multi-Image Edit — Compose multiple input images by passing up to 16 base64 strings in the images array. The model blends the references; useful for combining subjects, styles, or reference shots. The example pairs a smiley-face PNG with a red ball PNG.
TypeScript
const response = await env.AI.run(
'openai/gpt-image-2',
{
prompt:
'Combine these into a single photorealistic scene: a ceramic smiley-face mug next to a red rubber ball on a sunlit wooden table',
images: [
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAnklEQVR42u2XQRLAIAgD8/839i/26qFCACm0ozPe1KwcQsAoXvgcAABxpwFowl4QWITHxW0LCBhxVngF4gKIirMQyBRnIJAtrkE8AuwWnyFEgKzfS1UA+3sWTju3BGAu7gKYIfBW+Q/AAQgBeMCkt1wVsLZjcwUYG2Z9wGLHZitWk1DEisubUYt2XB5IWkSyFqG0RSxvMZi0Gc1+Ox3fm00ZJ5mGVtkAAAAASUVORK5CYII=',
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAhklEQVR42u2XsRHAMAgDNY73nye7OG2KgGUnGCWH76j/oTACPfnhcwIA3AoTGIFXRTADPlqjakYEDJwFWyJLAk/hrAQi4YwEouEjiVuBt+FXCVcgqntvCtjVvTUF7OremkIJlEAJ6Aikf0QSX3H6MpJYx+mBRCKSSYRSiVgucZjInGa/vY5PvB72/7IdMuAAAAAASUVORK5CYII=',
],
},
{
gateway: { id: 'default' },
}
)
console.log(response)
Multi-Image Edit

Parameters

prompt
stringrequiredText prompt describing the image to generate or edit
quality
stringenum: low, medium, high, autoQuality of the generated image
size
stringenum: 1024x1024, 1024x1536, 1536x1024, autoSize of the generated image
background
stringenum: transparent, opaque, autoBackground transparency setting. Use transparent for images with no background, opaque for a solid background, or auto to let the model decide.
output_format
stringenum: png, webp, jpegOutput format for the generated image

API Schemas (Raw)

Input
Output