gpt-image-2
Text-to-image generation with reference-image support, 13 aspect ratios and 1K, 2K or 4K output, through an OpenAI-compatible API.
- Image generation
- Reference images
- Sync & async
- PNG output
Pricing
Per generated image. Failed generations are refunded automatically.
Official prices are approximate list prices for reference. Full comparison.
Examples
Generated on YexAPI with gpt-image-2, shown with their prompts and settings. Images are resized for the web.



Code
Synchronous calls with the OpenAI SDKs, or async tasks for long jobs. Async guide.
curl https://api.yexapi.com/v1/images/generations \
-H "Authorization: Bearer $YEXAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A minimalist poster of a paper boat on calm water",
"size": "1024x1024"
}'from openai import OpenAI
client = OpenAI(
api_key="YOUR_YEXAPI_KEY",
base_url="https://api.yexapi.com/v1", # the only change
)
result = client.images.generate(
model="gpt-image-2",
prompt="A minimalist poster of a paper boat on calm water",
size="1024x1024",
)
print(result.data[0].url)import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.YEXAPI_API_KEY,
baseURL: "https://api.yexapi.com/v1", // the only change
});
const result = await client.images.generate({
model: "gpt-image-2",
prompt: "A minimalist poster of a paper boat on calm water",
size: "1024x1024",
});
console.log(result.data[0].url);# 1. Submit: returns a task ID immediately
curl https://api.yexapi.com/v1/images/generations/async \
-H "Authorization: Bearer $YEXAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "gpt-image-2", "prompt": "A tiny robot watering a bonsai tree", "size": "16:9", "resolution": "4k"}'
# 2. Poll until "status" is "completed" or "failed"
curl https://api.yexapi.com/v1/images/generations/TASK_ID \
-H "Authorization: Bearer $YEXAPI_API_KEY"Parameters
Request body for POST /v1/images/generations, /v1/images/generations/async and /v1/images/edits.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | string | Yes | — | gpt-image-2 |
prompt | string | Yes | — | Description of the image, up to 32,000 characters. |
size | string | No | auto | WIDTHxHEIGHT (e.g. 1536x1024), an aspect ratio (e.g. 16:9) or auto. Details. |
resolution | string | No | 1k | 1k, 2k or 4k. Determines the price tier. |
n | integer | No | 1 | Only 1 is supported. |
response_format | string | No | url | url or b64_json. |
image | string | string[] | No | — | Public http(s) URLs of up to 14 reference images. |
background | string | No | — | transparent for a transparent background. |
FAQ
What does the resolution tier mean?
The tier (1K, 2K or 4K) sets the output scale and the price. You can pick it with resolution or let it follow the longer edge of a WIDTHxHEIGHT size. Exact output pixels are chosen by the model and can differ slightly from the request.
Which sizes and aspect ratios are supported?
13 aspect ratios from 21:9 to 9:21, plus auto. OpenAI-style sizes such as 1024x1024 and 1536x1024 are mapped to the nearest ratio automatically.
Can I use reference images?
Yes. Pass up to 14 public image URLs in image, either on /v1/images/edits or on the generation endpoints. File uploads and masks are not supported.
How long does a generation take?
Most 1K and 2K images are ready in 30–60 seconds; 4K can take longer. For long jobs, use the async endpoint.
Do failed generations cost anything?
No. The reserved amount is refunded automatically when a generation fails.
Can I use the images commercially?
You may use the images you generate subject to our Terms of Service and Acceptable Use Policy, and to applicable law.