OpenAI Images API Integration Guide & Examples

MethodPathUseBodyRequired fields
POST/v1/images/generationsImage generationJSONmodel, prompt
POST/v1/images/editsImage edits / masked editingmultipart/form-data or JSONprompt, 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_url at https://api.modelgo.ai/v1 and use your ModelGo API key as api_key.

Image generation

bash
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

bash
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 as model, prompt and size may appear only once and must be plain form fields.
  • mask is optional: a PNG the same size as the first image[]; 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:

bash
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_url is a public https link or a data:image/png;base64,... URL; mask / markup likewise take {"image_url": "..."}.
  • file_id is not supported (ModelGo has no Files API) and returns 400; use image_url instead.
  • When model is omitted, the default is again gpt-image-2.5-sunburst.
  • Some models or routes do not support the JSON form; they return 400 provider_unsupported asking 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:

bash
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), then image_edit.completed (the final image and usage).
  • Billing is identical to the non-stream call, from the usage in image_edit.completed.
  • Some routes do not support streaming edits; they return 400 provider_unsupported asking you to drop stream.

Parameters

The table below lists the gpt-image family's parameters:

FieldApplies toDescription
modelAllgpt-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
promptAllRequired. What to draw; in edits, how to change the image
image[]edits (multipart)Required. One or more reference images (png / jpeg / webp)
imagesedits (JSON)Required. [{"image_url": "https://... or data:image/png;base64,..."}]; file_id is not supported
maskeditsOptional. PNG mask; {"image_url": "..."} in the JSON form
input_fidelityModel-dependent editsOmit for gpt-image-2. Do not treat low / high as universal values for 2.5 / 2.6; see Model-specific input fidelity
stream / partial_imageseditsstream=true streams the response; partial_images is the number of interim images. See Streaming edits
nAllNumber of images, default 1
sizeAllDefault auto; common WIDTHxHEIGHT values such as 1024x1024, 1536x1024
qualityAlllow / medium / high / auto, default auto; gpt-image-2.5-* adds xhigh / max
output_formatAllpng / jpeg; webp and svg (including the svg object) are not supported and return 400
output_compressionAll0–100, jpeg / webp only
backgroundAllopaque / transparent / auto
  • Only send the values listed in the table. The gateway does not block other values; the upstream usually returns 400 with a reason, but it may also silently ignore the parameter and still return 200. The same holds for other models.
  • For other models' parameters see Seedream and Qwen Image.

Model-specific input fidelity

ModelHow to handle input_fidelity
gpt-image-2Omit 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-sunburstOmit 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-sunburstOmit 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:

ModelDefault shaperesponse_format
gpt-image family (gpt-image-2 / gpt-image-2.5-*)b64_jsonNot 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:

python
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)

python
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 JSON image field — /v1/images/edits is not enabled for Seedream.
  • doubao-seedream-4.0 is served on image generation too, but n must be omitted or 1 (render several images with a sequential set, sequential_image_generation: "auto"); image to image uses the JSON image field, and /v1/images/edits is 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.