OpenAI Images API Integration Guide & Examples
| Method | Path | Use | Body | Required fields |
|---|---|---|---|---|
POST | /v1/images/generations | Image generation | JSON | model, prompt |
POST | /v1/images/edits | Image edits / masked editing | multipart/form-data or JSON | prompt, reference images (image[] in multipart, images in JSON); model optional, default gpt-image-2.5-sunburst |
Requests and responses follow the OpenAI Images API format; without stream the complete image is returned synchronously (for streamed edits see Streaming edits). The catalog includes gpt-image-2, gpt-image-2.5-flare, gpt-image-2.5-sunburst, gpt-image-2.6-flare and gpt-image-2.6-sunburst. They share endpoint formats, but parameter support can differ by model and route; changing only model does not make every option compatible. In particular, omit input_fidelity for gpt-image-2; see Model-specific input fidelity. Seedream (image generation only) and Qwen Image can also be called on these endpoints; the differences are below and on each model's page.
With the official OpenAI SDK, point
base_urlathttps://api.modelgo.ai/v1and use your ModelGo API key asapi_key.
Image generation
curl https://api.modelgo.ai/v1/images/generations \
-H "Authorization: Bearer $MODELGO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A fluffy ginger cat sitting on a sunlit windowsill, film look",
"size": "1536x1024",
"quality": "high"
}'Image edits
curl https://api.modelgo.ai/v1/images/edits \
-H "Authorization: Bearer $MODELGO_API_KEY" \
-F "model=gpt-image-2" \
-F "prompt=Replace the background with a neon night street, keep the cat's pose" \
-F "image[]=@./cat.png" \
-F "mask=@./mask.png"image[]may repeat to send several reference images; text fields such asmodel,promptandsizemay appear only once and must be plain form fields.maskis optional: a PNG the same size as the firstimage[]; transparent areas are repainted.- The whole request body, every uploaded image included, is capped at 10 MiB.
- If the model does not offer the image-editing endpoint, the call returns
400 model_protocol_not_offered; the protocols listed in the Model Catalog are authoritative.
JSON form
You can also send OpenAI's official JSON form (Content-Type: application/json), giving reference images as links:
curl https://api.modelgo.ai/v1/images/edits \
-H "Authorization: Bearer $MODELGO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2.5-sunburst",
"prompt": "Replace the background with a neon night street, keep the cat in the same pose",
"images": [{"image_url": "https://example-cdn.com/cat.png"}],
"quality": "low",
"size": "1024x1024"
}'images[].image_urlis a public https link or adata:image/png;base64,...URL;mask/markuplikewise take{"image_url": "..."}.file_idis not supported (ModelGo has no Files API) and returns400; useimage_urlinstead.- When
modelis omitted, the default is againgpt-image-2.5-sunburst. - Some models or routes do not support the JSON form; they return
400 provider_unsupportedasking you to send multipart.
Streaming edits
With stream=true (optionally partial_images for the number of interim images) the response is text/event-stream, in both the multipart and the JSON form:
curl -N https://api.modelgo.ai/v1/images/edits \
-H "Authorization: Bearer $MODELGO_API_KEY" \
-F "model=gpt-image-2" \
-F "prompt=Replace the background with a neon night street" \
-F "image[]=@./cat.png" \
-F "stream=true" \
-F "partial_images=1"- Events are zero or more
image_edit.partial_image(interim images, base64), thenimage_edit.completed(the final image andusage). - Billing is identical to the non-stream call, from the
usageinimage_edit.completed. - Some routes do not support streaming edits; they return
400 provider_unsupportedasking you to dropstream.
Parameters
The table below lists the gpt-image family's parameters:
| Field | Applies to | Description |
|---|---|---|
model | All | gpt-image-2 / gpt-image-2.5-flare / gpt-image-2.5-sunburst / gpt-image-2.6-flare / gpt-image-2.6-sunburst. Required for generations; optional for edits, defaulting to gpt-image-2.5-sunburst when omitted |
prompt | All | Required. What to draw; in edits, how to change the image |
image[] | edits (multipart) | Required. One or more reference images (png / jpeg / webp) |
images | edits (JSON) | Required. [{"image_url": "https://... or data:image/png;base64,..."}]; file_id is not supported |
mask | edits | Optional. PNG mask; {"image_url": "..."} in the JSON form |
input_fidelity | Model-dependent edits | Omit for gpt-image-2. Do not treat low / high as universal values for 2.5 / 2.6; see Model-specific input fidelity |
stream / partial_images | edits | stream=true streams the response; partial_images is the number of interim images. See Streaming edits |
n | All | Number of images, default 1 |
size | All | Default auto; common WIDTHxHEIGHT values such as 1024x1024, 1536x1024 |
quality | All | low / medium / high / auto, default auto; gpt-image-2.5-* adds xhigh / max |
output_format | All | png / jpeg; webp and svg (including the svg object) are not supported and return 400 |
output_compression | All | 0–100, jpeg / webp only |
background | All | opaque / transparent / auto |
- Only send the values listed in the table. The gateway does not block other values; the upstream usually returns
400with a reason, but it may also silently ignore the parameter and still return200. The same holds for other models. - For other models' parameters see Seedream and Qwen Image.
Model-specific input fidelity
| Model | How to handle input_fidelity |
|---|---|
gpt-image-2 | Omit it. The official image-edit API reference explicitly says to omit this parameter for GPT Image 2. |
gpt-image-2.5-flare / gpt-image-2.5-sunburst | Omit by default. Send it only when the selected model and route explicitly document support and accepted values; do not assume low / high apply. |
gpt-image-2.6-flare / gpt-image-2.6-sunburst | Omit by default. Being listed for image generation and edits does not establish support for this optional parameter. |
The examples on this page omit input_fidelity. When switching models, remove this field from saved edit requests rather than automatically copying it to the new model. If a request returns 400 naming input_fidelity as unsupported, remove the field before retrying; changing its value to low or high does not establish compatibility.
Response shape
Whether data[] carries url or b64_json follows each model's official behavior; the gateway does not convert between the two:
| Model | Default shape | response_format |
|---|---|---|
gpt-image family (gpt-image-2 / gpt-image-2.5-*) | b64_json | Not supported; ignored if sent, always returns b64_json |
Qwen Image (qwen-image-3.0 / qwen-image-3.0-pro) | url (valid for 24 hours) | b64_json is ignored; the response still carries a url |
Seedream (doubao-seedream-*) | url (valid for 24 hours) | Both url and b64_json are supported |
When switching models, do not hard-code data[0].url or data[0].b64_json; read whichever field is present:
import base64
import urllib.request
item = resp["data"][0]
if item.get("b64_json"):
image = base64.b64decode(item["b64_json"])
else:
image = urllib.request.urlopen(item["url"]).read()Python example (official OpenAI SDK)
import base64, os
from openai import OpenAI
client = OpenAI(api_key=os.environ["MODELGO_API_KEY"], base_url="https://api.modelgo.ai/v1")
r = client.images.generate(model="gpt-image-2", prompt="A ginger cat on a windowsill, film look",
size="1536x1024", quality="high")
open("cat.png", "wb").write(base64.b64decode(r.data[0].b64_json))
with open("cat.png", "rb") as img:
e = client.images.edit(model="gpt-image-2", prompt="Replace the background with a neon night street", image=[img])
open("cat-neon.png", "wb").write(base64.b64decode(e.data[0].b64_json))Seedream
- The Seedream 5.0 family (
doubao-seedream-5.0-pro/-lite/-flash) is served only on this page's image generation endpoint; the body carries the official Ark fields. Image to image uses the JSONimagefield —/v1/images/editsis not enabled for Seedream. doubao-seedream-4.0is served on image generation too, butnmust be omitted or1(render several images with a sequential set,sequential_image_generation: "auto"); image to image uses the JSONimagefield, and/v1/images/editsis not enabled for this model.
Billing
The gpt-image family is billed per token (text input, image input and image output priced separately), from the response usage; output tokens grow with size and quality. Other models' metering is on their own pages; unit prices are in the console's model list. Error handling: Errors & Rate Limits.
Other image models: Seedream, Qwen Image, Gemini image.