ModelGo Unified Image API Integration Guide & Examples
| Method | Path | Purpose |
|---|---|---|
POST | /v1/modelgo/images | Text-to-image and reference-image generation; the images come back synchronously |
The Unified Image API uses a shared set of parameter names. ModelGo translates them for each channel. Add input_references to generate an image from references. The API returns the result synchronously.
Choose a model that lists modelgo_images in the Model Catalog for the site you are calling. The models below illustrate the request and response format. A model that does not offer the protocol returns 400 model_protocol_not_offered. If the catalog lists no eligible models, use an existing entrypoint such as OpenAI Images.
1. Generate images
curl https://api.modelgo.ai/v1/modelgo/images \
-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 look",
"size": "1536x1024",
"quality": "high"
}'A success returns 200 and the image result:
{
"id": "gw_0c5d2e8a-7f41-4b6e-9a3d-58e1f2c47b90",
"object": "image.generation",
"created": 1795395612,
"model": "gpt-image-2",
"parameters": { "n": 1, "output_format": "png", "quality": "high", "size": "1536x1024" },
"data": [
{
"index": 0,
"url": "https://api.modelgo.ai/v1/videos/gw_0c5d2e8a-7f41-4b6e-9a3d-58e1f2c47b90/content",
"content_type": "image/png",
"width": 1536,
"height": 1024,
"expires_at": 1795654812
}
],
"usage": { "image_count": 1 }
}| Field | Description |
|---|---|
id | The request ID (gw_ + UUID), generated by the gateway |
parameters | The parameters used, defaults included (the prompt and reference images are not repeated) |
data[] | The delivered images in index order: url or b64_json, content_type, width, height, expires_at |
data[].url | A ModelGo-hosted download link: …/content for the first image and …/content?index=N for the others, where N is the image's index |
data[].expires_at | When the link stops being downloadable (Unix seconds) |
usage.image_count | The number of images delivered |
- The result never contains a supplier's image links or a supplier's usage fields.
- The link needs no API key: the link itself is the credential, so do not share it publicly or write it to logs. Download and store the image before
expires_at; afterwards the link returns404 content_not_available.
With "response_format": "b64_json" the images come inline in the result: each data[] item carries b64_json instead of url and has no expires_at:
{ "index": 0, "b64_json": "iVBORw0KGgo...", "content_type": "image/png", "width": 1024, "height": 1024 }Reference-image generation
curl https://api.modelgo.ai/v1/modelgo/images \
-H "Authorization: Bearer $MODELGO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "Use this image as the reference: switch the background to a neon night scene and keep the cat in the same pose",
"input_references": [
{ "type": "image_url", "image_url": { "url": "data:image/png;base64,<BASE64_IMAGE>" } }
]
}'- Each item is
{"type": "image_url", "image_url": {"url": "..."}}. Theurlis anhttp(s)URL that can be downloaded directly from the public internet, or adata:image/...;base64,...data URI; a data URI counts toward the request body, which is limited to 10 MiB. - How many reference images each model takes is listed under Model limits.
- Reference images are fetched before anything is charged; one that cannot be fetched is refused with
400 unsupported_valueoninput_references[i].image_url.url(iis its position in the array).
Request fields
| Field | Type | Description |
|---|---|---|
model | string | Required. Logical model name |
prompt | string | Required. What to draw; with reference images, how to use them. See the model limits for the maximum length |
input_references | array | Reference images; see Reference-image generation |
n | integer | Number of images |
size | string | Output size (width x height), such as 1024x1024 |
resolution | string | Resolution tier, for models that take a tier instead of a size |
aspect_ratio | string | Aspect ratio, such as 1:1, 16:9 |
quality | string | Quality tier |
output_format | string | Image format, such as png, jpeg |
output_compression | integer | Output compression |
background | string | Background handling, such as transparency |
seed | integer | Random seed |
negative_prompt | string | What the image should avoid |
watermark | bool | Add a watermark |
response_format | string | url (default; a ModelGo-hosted link) or b64_json (base64 in the result); available for every model |
extensions | object | Model-specific parameters the model declares |
user | string | Accepted and ignored; never forwarded to a channel |
stream is refused (unsupported_parameter), and any other top-level field not listed here is refused (unknown_parameter). JSON null counts as absent.
Each model accepts only the parameters it declares. A model declares which parameters it accepts, their allowed values and defaults, and which combinations are allowed. Requests are checked against the model before anything is reserved or any channel is called, and all problems are returned at once; for a value outside a list, the allowed values come back in allowed (see Errors). Parameters you leave out take the model's defaults, and the values actually used are returned in the result's parameters.
2. Model limits
These limits apply when the model offers the unified protocol.
gpt-image: gpt-image-2, gpt-image-2.5-sunburst
| Parameter | Supported | Default |
|---|---|---|
prompt | 1–4000 characters (Unicode characters) | — |
input_references | Up to 2 images | — |
n | 1–4 | 1 |
size | 1024x1024, 1536x1024, 1024x1536 | 1024x1024 |
quality | low, medium, high | Chosen by the model when omitted |
output_format | png, jpeg | png |
response_format | url, b64_json | url |
resolution, aspect_ratio, output_compression, background, seed, negative_prompt, watermark, and extensions are not supported. Both models have the same limits.
3. Idempotent retries
Requests you may retry can carry an Idempotency-Key. Under the same API key, the same key with the same request body replays the same result for 24 hours without calling the channel again or charging again; the same key with a different body returns 409 idempotency_conflict. A failed request does not use up the key, so you can retry with the same key.
Only responses up to 8 MiB are kept for replay: the url form always is, but a large b64_json response (several large images, for example) is not, and a retry with the same key generates and charges again. Use url when you need safe retries.
4. Errors
Request problems are returned together, before anything is reserved or any channel is called. For example, gpt-image-2 with a seed and an unsupported size:
{
"error": {
"details": [
{ "param": "seed", "code": "unsupported_parameter", "reason": "model does not support this parameter" },
{ "param": "size", "code": "unsupported_value", "reason": "value is outside the guaranteed enum", "allowed": ["1024x1024", "1536x1024", "1024x1536"] }
],
"message": "Parameter 'seed': model does not support this parameter",
"type": "invalid_request_error",
"param": "seed",
"code": "unsupported_parameter",
"metadata": {
"app_error_id": 4001,
"error_class": "client_unsupported_parameter",
"request_id": "gw_ed3b2120-82ae-4f56-8325-fe1d4f9b2296"
}
},
"trace_id": "660b0c1c4d562a977ff1806de999f1e2"
}error.param and error.code describe the first problem; error.details lists all of them.
code | Meaning |
|---|---|
unknown_parameter | The field is not part of the unified protocol |
unsupported_parameter | The platform or this model does not accept the parameter, including stream |
unsupported_value | The value is outside the model's list or range (including prompt too long, too many reference images, or a reference image that cannot be fetched); list problems include allowed |
invalid_parameter_combination | The model does not allow this combination |
unsupported_extension | extensions contains a parameter the model does not declare |
invalid_request_structure | Wrong type or structure, such as model or prompt missing, or a malformed reference (not an image_url item, or a url that is neither an http(s) URL nor an image data URI) |
A reference image that cannot be fetched is reported on input_references[i].image_url.url with unsupported_value, and nothing is reserved either.
Other responses:
| HTTP | Meaning |
|---|---|
400 model_protocol_not_offered | The model does not offer the unified API |
401 / 402 / 403 / 429 | Authentication, balance or budget, policy, or rate limit; see Errors and rate limits |
409 idempotency_conflict | The same Idempotency-Key was sent with a different request body; see Idempotent retries |
503 | No channel can currently serve every parameter the model offers; retry later |
502 / 504 | The channel failed or timed out, or the result could not be stored; you are not charged |
5. Billing
- Billing uses the model's own image price, metered the same way as on the model's other image endpoints. See "Model list" in the console for the unit price.
- Only images actually delivered are billed;
usage.image_countreports how many were delivered. - The estimated cost is reserved when the request arrives and charged once on success.
- Refused requests, failed generations, timeouts, and results that could not be stored are not charged; idempotent replays are not charged again.