Skip to content

Image Generation

Generate images with any model available on ImageRouter. Supports both Text-to-Image and Image-to-Image generation. Requests can be encoded as application/json or multipart/form-data (optimal for file uploads).

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",
"image": "https://example.com/your_image.jpg"
}'

Both JSON and Form-Data encoding are accepted by the API. JSON is compatible with OpenAI’s GPT Image, Form-Data is compatible with GPT Image (edit) schema.

Show Form-Data formatted example
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 and the prompt are not saved in our system. The provider may still have them.

    API-generated images and prompts (url and b64_json) are kept for 30 days, then deleted automatically. Generations made on the ImageRouter.io site while signed in are kept until you delete them. Generations made on the site without an account are deleted after 30 days.

  • output_format optional Image format for the generated output.

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

    • File upload — multipart/form-data with image[] field(s) (up to 16 files)
    • URL string — "https://example.com/photo.jpg" (passed as JSON string or form field)
    • Data URI string — "data:image/png;base64,..." (passed as JSON string or form field)

    URL and data URI strings can be sent either as a single string or an array of strings (up to 16). This is OpenAI-compatible.

  • mask / mask[] optional Image editing mask (most models don’t need this). Accepts the same formats as image: file upload, URL string, or data URI string.

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
}