Skip to content

Image Generation

Generate images with any model available on ImageRouter.

EndpointForm-Data encoded endpointJSON encoded endpoint
Text-to-Image
Image-to-Image
CompatibilityGPT Image (edit)GPT Image

If you plan to generate images from both text and image, this kind of mixed usage is supported by the Form-Data encoded endpoint. This simplifies the integration to just one endpoint for both Text-to-Image and Image-to-Image generation. I’d only use the JSON endpoint, if Form-Data is not an option.

Both APIs are compatible with OpenAI GPT-Image API, but some OpenAI parameters may be ignored by some models.

Supports both Text-to-Image and Image-to-Image generation. Requests are encoded as multipart/form-data.

Terminal window
curl 'https://api.imagerouter.io/v1/openai/images/edits' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-F 'prompt=YOUR_PROMPT' \
-F 'model=openai/gpt-image-1' \
-F 'quality=auto' \
-F 'size=auto' \
-F 'response_format=url' \
-F 'output_format=webp' \
-F 'image[]=@your_image1.webp' \
-F 'image[]=@your_image2.webp' \
-F 'mask[]=@your_mask.webp'

note: /v1/openai/images/generations and /v1/openai/images/edits are the exact same, available at 2 URLs for compatibility reasons.

  • model required Image model to use for generation.

  • prompt optional Text input for generating images. Many models require prompt, but not all.

  • quality optional Models supporting this parameter have “quality” feature label here

    • auto [default] - Usually points to “medium”, but some models (eg. gpt-image-1) automatically adjust quality based on your prompt.
    • low
    • medium
    • high
  • size optional Accepted values are different for each model. Some models and providers completely ignore size.

    • auto [default] - Uses the default recommended size for each model. Some models (eg. gpt-image-1) automatically adjust size based on your prompt.
    • WIDTHxHEIGHT (eg 1024x1024)
  • response_format optional

    • url [default] - Returns the image URL hosted on ImageRouter’s servers. The image is saved in your logs. and is publicly accessible with the URL if you share it.
    • b64_json - Returns the image as base64-encoded JSON data. The image is saved in your logs. and is publicly accessible with the URL if you share it.
    • b64_ephemeral - Same as b64_json but the image is not saved in our system. The provider may still have it.
  • output_format optional Image format for the generated output.

    • webp [default]
    • jpeg
    • png
  • image[] optional Input file for Image-to-Image generation. (Supported models have “edit” label here.)

  • mask[] optional Image editing mask (most models don’t need this).

The OpenAI compatible response makes sure you can use ImageRouter anywhere GPT-Image is already implemented.

{
"created": 1769286389027, // timestamp
"data":[
{
"url": "https://storage.imagerouter.io/fffb4426-efbd-4bcc-87d5-47e6936bf0bb.webp"
// or "b64_json": "...", if you select a different response_format
}
],
"latency": 6942,
"cost": 0.004
}

This endpoint exists for compatibility reasons (so ImageRouter can be used with the OpenAI SDK). File uploads are not possible with application/json encoding, so Image-to-Image generation is not supported for this endpoint.

Terminal window
curl 'https://api.imagerouter.io/v1/openai/images/generations' \
-H 'Authorization: Bearer YOUR_API_KEY' \
--json '{
"prompt": "YOUR_PROMPT",
"model": "test/test",
"quality": "auto",
"size": "auto",
"response_format": "url",
"output_format": "webp"
}'

Please contact me if you miss anything.