Skip to main content
The AI Router exposes three OpenAI-compatible endpoints for image generation, editing, and variations. All endpoints support the same fallbacks, caching, load balancing, and retry features available for chat completions.
For the full and up-to-date list of supported image models, see Image models on the Supported Models page.

Image generation

Generate images from a text prompt using POST /v2/router/images/generations.
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.ORQ_API_KEY,
  baseURL: "https://my.orq.ai/v2/router",
});

const response = await client.images.generate({
  model: "openai/gpt-image-1",
  prompt: "A futuristic city skyline at sunset, photorealistic",
  n: 1,
  size: "1024x1024",
});

console.log(response.data[0].b64_json?.slice(0, 40));

Parameters

ParameterDescription
modelModel ID
promptText description of the desired image
nNumber of images to generate
sizeImage dimensions (see Supported Models for per-model sizes)
response_formaturl or b64_json. DALL-E 2/3 only — gpt-image-1 always returns b64_json
qualityImage quality level. Values vary by model
stylevivid or natural. DALL-E 3 only
backgroundtransparent, opaque, or auto. gpt-image-1 only
output_formatpng, jpeg, or webp. gpt-image-1 only
output_compressionCompression level 0-100%. gpt-image-1 only
moderationauto or low. gpt-image-1 only

Response format

Set response_format to url to receive a hosted image link, or b64_json to receive the image as a base64-encoded string inline in the response. Supported sizes and response formats vary by model. See Image models.
{
  "created": 1234567890,
  "data": [
    {
      "b64_json": "iVBORw0KGgo..."
    }
  ]
}

Image editing

Modify an existing image using a prompt and an optional mask with POST /v2/router/images/edits.
import fs from "fs";
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.ORQ_API_KEY,
  baseURL: "https://my.orq.ai/v2/router",
});

const response = await client.images.edit({
  model: "openai/gpt-image-1",
  image: fs.createReadStream("original.png"),
  prompt: "Add a sunset sky behind the buildings",
  size: "1024x1024",
});

console.log(response.data[0].b64_json?.slice(0, 40));

Parameters

ParameterDescription
modelModel ID
imagePNG, WEBP, or JPEG file to edit. Some models accept an array of images
promptText description of the desired edit
maskOptional PNG mask where transparent areas indicate where to edit
sizeOutput image dimensions
response_formaturl or b64_json. gpt-image-1 always returns b64_json
qualityImage quality level. Values vary by model

Image variations

Generate variations of an existing image with POST /v2/router/images/variations. See Image models for which models support variations.
import fs from "fs";
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.ORQ_API_KEY,
  baseURL: "https://my.orq.ai/v2/router",
});

const response = await client.images.createVariation({
  model: "openai/dall-e-2",
  image: fs.createReadStream("original.png"),
  size: "1024x1024",
  response_format: "url",
});

response.data.forEach((img) => console.log(img.url));

Parameters

ParameterDescription
modelModel ID
imagePNG image to create a variation of
nNumber of variations to generate (1-10)
sizeOutput image dimensions
response_formaturl or b64_json

Fallbacks and reliability

Image endpoints support the same fallbacks and retry parameters as chat completions:
TypeScript
const response = await client.images.generate({
  model: "openai/gpt-image-1",
  prompt: "A mountain lake at dawn",
  size: "1024x1024",
  // @ts-ignore - orq.ai extension
  fallbacks: ["openai/dall-e-3", "openai/dall-e-2"],
});