ModelGo Unified Image API Integration Guide & Examples

MethodPathPurpose
POST/v1/modelgo/imagesText-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

bash
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:

json
{
  "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 }
}
FieldDescription
idThe request ID (gw_ + UUID), generated by the gateway
parametersThe 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[].urlA 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_atWhen the link stops being downloadable (Unix seconds)
usage.image_countThe 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 returns 404 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:

json
{ "index": 0, "b64_json": "iVBORw0KGgo...", "content_type": "image/png", "width": 1024, "height": 1024 }

Reference-image generation

bash
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": "..."}}. The url is an http(s) URL that can be downloaded directly from the public internet, or a data: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_value on input_references[i].image_url.url (i is its position in the array).

Request fields

FieldTypeDescription
modelstringRequired. Logical model name
promptstringRequired. What to draw; with reference images, how to use them. See the model limits for the maximum length
input_referencesarrayReference images; see Reference-image generation
nintegerNumber of images
sizestringOutput size (width x height), such as 1024x1024
resolutionstringResolution tier, for models that take a tier instead of a size
aspect_ratiostringAspect ratio, such as 1:1, 16:9
qualitystringQuality tier
output_formatstringImage format, such as png, jpeg
output_compressionintegerOutput compression
backgroundstringBackground handling, such as transparency
seedintegerRandom seed
negative_promptstringWhat the image should avoid
watermarkboolAdd a watermark
response_formatstringurl (default; a ModelGo-hosted link) or b64_json (base64 in the result); available for every model
extensionsobjectModel-specific parameters the model declares
userstringAccepted 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

ParameterSupportedDefault
prompt1–4000 characters (Unicode characters)—
input_referencesUp to 2 images—
n1–41
size1024x1024, 1536x1024, 1024x15361024x1024
qualitylow, medium, highChosen by the model when omitted
output_formatpng, jpegpng
response_formaturl, b64_jsonurl

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:

json
{
  "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.

codeMeaning
unknown_parameterThe field is not part of the unified protocol
unsupported_parameterThe platform or this model does not accept the parameter, including stream
unsupported_valueThe 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_combinationThe model does not allow this combination
unsupported_extensionextensions contains a parameter the model does not declare
invalid_request_structureWrong 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:

HTTPMeaning
400 model_protocol_not_offeredThe model does not offer the unified API
401 / 402 / 403 / 429Authentication, balance or budget, policy, or rate limit; see Errors and rate limits
409 idempotency_conflictThe same Idempotency-Key was sent with a different request body; see Idempotent retries
503No channel can currently serve every parameter the model offers; retry later
502 / 504The 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_count reports 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.