GPT Image 2 Images API
Call GPT Image 2 through synchronous JSON or heartbeat-protected SSE and receive a short-lived signed image URL or base64.
Generate PNG images with gpt-image-2 through the OpenAI-compatible Images API. The first release supports one image per request, medium or high quality, signed URL or base64 output, and optional SSE.
Choose an endpoint and mode
- Use https://origin.modelflare.dev/v1 for ordinary synchronous JSON requests that may take several minutes.
- Use https://modelflare.dev/v1 with stream=true for long requests through Cloudflare. Modelflare sends transport-only SSE heartbeats until the final image is ready.
- Do not redirect an in-flight POST between hosts. Choose the base URL before submitting the request.
Synchronous request
curl https://origin.modelflare.dev/v1/images/generations \
-H "Authorization: Bearer YOUR_MODELFLARE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A quiet lakeside cabin at dawn, cinematic natural light",
"n": 1,
"quality": "medium",
"size": "1024x1024",
"response_format": "url",
"output_format": "png"
}'
A URL response contains a private Modelflare link that expires after one hour:
{"created":1710000000,"data":[{"url":"https://modelflare.dev/v1/images/assets/.../content?expires=...&signature=..."}]}
Set response_format to b64_json to receive the validated PNG inline instead of storing an API output object.
The live Models & Pricing page shows medium and high price points for common sizes. Billing uses the exact requested quality and dimensions, ignores ordinary routing-group multipliers, and records the final charge in usage logs.
Streaming request
curl -N https://modelflare.dev/v1/images/generations \
-H "Authorization: Bearer YOUR_MODELFLARE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"gpt-image-2","prompt":"A white cat running through a neon street in the rain","n":1,"quality":"high","size":"1024x1024","response_format":"url","stream":true}'
SSE comments are heartbeats, not model output. Stop after image_generation.completed and data: [DONE].
Supported fields
- model: required; exactly gpt-image-2.
- prompt: required; up to 32,000 Unicode characters.
- n: optional; currently must be 1.
- quality: medium (default) or high.
- size: WIDTHxHEIGHT, using multiples of 16, a maximum edge of 3840 px, an aspect ratio up to 3:1, and 0.66–8.29 MP.
- response_format: url (default) or b64_json.
- output_format: currently png only.
- stream: optional boolean.
Image edits, variations, reference images, partial images, and unknown fields are rejected. Failed upstream, validation, download, or storage operations are not delivered as successful images and reserved Credits are returned through the request-id-safe refund path.
Use a normal API key. Channel-pinned keys are rejected, and a key with model limits enabled must include gpt-image-2.