GPT Image

EndpointCapabilityBodyRequired fields
POST /v1/images/generationsText to imageJSONmodel, prompt
POST /v1/images/editsImage to image / mask editing (multiple references)multipart/form-datamodel, prompt, image[]

Both models share the same parameter set and the same endpoints; only the model field differs. Their output token counts and prices differ (see "Billing").

The ModelGo gateway accepts gpt-image-2 / gpt-image-1.5 requests on the official OpenAI Images API paths with the official request/response shapes unchanged; the gateway routes to a supplier and bills the call. Which supplier renders the image is invisible to the caller. Images are returned synchronously — there is no polling.

With the official OpenAI SDK, point base_url at https://api.modelgo.ai/v1 and use your ModelGo API key as api_key.

1. Create an image

Text to image

POST https://api.modelgo.ai/v1/images/generations

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 orange cat sitting on a sunny windowsill, film grain",
    "size": "1536x1024",
    "quality": "high",
    "output_format": "png"
  }'

Image to image / mask editing

POST https://api.modelgo.ai/v1/images/edits (multipart/form-data)

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" \
  -F "size=1024x1024" \
  -F "quality=medium" \
  -F "input_fidelity=high"
  • image[] may be repeated to send several reference images in one request.
  • Text fields such as model, prompt, size, quality and n must appear once, as plain form fields (not file parts); otherwise the request gets a 400.
  • mask is optional: a PNG with the same dimensions as the first image[]; transparent areas are repainted.

Response

json
{
  "created": 1757318400,
  "data": [{"b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."}],
  "usage": {
    "input_tokens": 17,
    "input_tokens_details": {"text_tokens": 17, "image_tokens": 0},
    "output_tokens": 5488,
    "output_tokens_details": {"image_tokens": 5488, "text_tokens": 0},
    "total_tokens": 5505
  }
}

Images are always returned as data[].b64_json (base64). Save to a file:

bash
curl -s 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 red ball on a wooden table"}' \
  | python3 -c 'import sys,json,base64; open("out.png","wb").write(base64.b64decode(json.load(sys.stdin)["data"][0]["b64_json"]))'

2. Parameters

FieldTypeApplies toDescription
modelstringallgpt-image-2 / gpt-image-1.5
promptstringallRequired. Describes the image; for edits, describes the change to make
image[]fileeditsRequired. One or more reference images (png / jpeg / webp)
maskfileeditsOptional. PNG mask with the same dimensions as the image; transparent areas are repainted
input_fidelitystringeditsHow closely to follow the reference image, low / high
nintallNumber of images, default 1
sizestringallDefault auto. gpt-image-2: common WxH values such as 1024x1024, 1536x1024 and 3840x2160; finer dimension and pixel limits follow the upstream documentation, and its reason is returned in the 400 message. gpt-image-1.5: 1024x1024 / 1536x1024 / 1024x1536 / auto only
qualitystringalllow / medium / high / auto, default auto. Directly determines the output token count
output_formatstringallpng / jpeg / webp
output_compressionintall0–100, only for jpeg / webp
backgroundstringallopaque / transparent / auto
moderationstringallContent moderation level, passed through
  • response_format does not apply to the gpt-image family. The gateway strips the field before forwarding, without an error; images are always returned as b64_json — there is no url form.
  • Parameter values follow what can actually be delivered. The table describes model capability, not a gateway allowlist; size / quality / output_format / background are forwarded to the supplier the request is routed to. An unsupported value returns 400 with a reason, and nothing is charged.
  • Routing follows deliverable tiers. The gateway prefers suppliers that can deliver the declared size / quality to reduce the chance of a rejection; the supplier makes the final call.

Output tokens

Output tokens depend on the model, size and quality; take the actual values from usage in the response. quality: high is usually well above the default tier, and gpt-image-1.5 usually emits significantly more tokens than gpt-image-2 at the same tier. Prices differ between the two models, so re-check cost before switching.

3. Full example (Python, 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")

# Text to image
r = client.images.generate(model="gpt-image-2", prompt="An orange cat on a windowsill, film grain",
                           size="1536x1024", quality="high", output_format="png")
open("cat.png", "wb").write(base64.b64decode(r.data[0].b64_json))
print(r.usage.output_tokens_details.image_tokens)

# Image to image (mask editing)
with open("cat.png", "rb") as img, open("mask.png", "rb") as mask:
    e = client.images.edit(model="gpt-image-2", prompt="Replace the background with a neon night street",
                           image=[img], mask=mask, size="1024x1024", quality="medium")
open("cat-neon.png", "wb").write(base64.b64decode(e.data[0].b64_json))

4. Billing

  • Token-based, with three prices: text input (input), image input (image_input) and image output (image_output), each per million tokens. The image portion of the output is billed at the image_output price.
  • gpt-image-2 and gpt-image-1.5 each have their own price card, and their output token counts for the same tier may differ materially, so the cost of one request cannot be inferred from the other model.
  • A reservation is frozen at request time and settled from the returned usage: input_tokens_details.text_tokens → input, input_tokens_details.image_tokens → image_input, output_tokens_details.image_tokens → image_output.
  • Rejected requests (400) and failed generations are never billed; the reservation is released automatically.
  • Prices are those shown in the console's model list.

Common errors

SymptomCauseFix
400A size / quality value is unsupported (e.g. beyond the upstream's dimension/pixel limits); edits missing image[] or mask dimensions differ from the image; missing prompt; n is not an integerFix the parameter per the message or change tier
response_format: "url" sent but b64_json returnedThe gpt-image family does not support the field; the gateway strips it silentlyDecode data[].b64_json
429Rate limit hitBack off and retry; contact the platform for a higher quota
401Invalid API key or missing Authorization headerCheck the key