GPT Image
| Endpoint | Capability | Body | Required fields |
|---|---|---|---|
POST /v1/images/generations | Text to image | JSON | model, prompt |
POST /v1/images/edits | Image to image / mask editing (multiple references) | multipart/form-data | model, 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_urlathttps://api.modelgo.ai/v1and use your ModelGo API key asapi_key.
1. Create an image
Text to image
POST https://api.modelgo.ai/v1/images/generations
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)
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,qualityandnmust appear once, as plain form fields (not file parts); otherwise the request gets a 400. maskis optional: a PNG with the same dimensions as the firstimage[]; transparent areas are repainted.
Response
{
"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:
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
| Field | Type | Applies to | Description |
|---|---|---|---|
model | string | all | gpt-image-2 / gpt-image-1.5 |
prompt | string | all | Required. Describes the image; for edits, describes the change to make |
image[] | file | edits | Required. One or more reference images (png / jpeg / webp) |
mask | file | edits | Optional. PNG mask with the same dimensions as the image; transparent areas are repainted |
input_fidelity | string | edits | How closely to follow the reference image, low / high |
n | int | all | Number of images, default 1 |
size | string | all | Default 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 |
quality | string | all | low / medium / high / auto, default auto. Directly determines the output token count |
output_format | string | all | png / jpeg / webp |
output_compression | int | all | 0–100, only for jpeg / webp |
background | string | all | opaque / transparent / auto |
moderation | string | all | Content moderation level, passed through |
response_formatdoes not apply to the gpt-image family. The gateway strips the field before forwarding, without an error; images are always returned asb64_json— there is nourlform.- Parameter values follow what can actually be delivered. The table describes model capability, not a gateway allowlist;
size/quality/output_format/backgroundare forwarded to the supplier the request is routed to. An unsupported value returns400with a reason, and nothing is charged. - Routing follows deliverable tiers. The gateway prefers suppliers that can deliver the declared
size/qualityto 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)
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 theimage_outputprice. - 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
| Symptom | Cause | Fix |
|---|---|---|
400 | A 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 integer | Fix the parameter per the message or change tier |
response_format: "url" sent but b64_json returned | The gpt-image family does not support the field; the gateway strips it silently | Decode data[].b64_json |
429 | Rate limit hit | Back off and retry; contact the platform for a higher quota |
401 | Invalid API key or missing Authorization header | Check the key |