Skip to main content

Image Analysis & Generation

The RouteLLM API provides full image support — both analyzing images as input (vision) and generating images as output — all via the same unified /v1/chat/completions endpoint.

Image Analysis​

Send images alongside text to any vision-capable model for description, classification, OCR, comparison, and more. Images can be provided as an HTTPS URL or base64-encoded data.

Supported Input Formats​

  • PNG, JPEG, WebP, GIF
  • Images are automatically resized and processed by the API
  • Multiple images can be included in a single message

Providing Images as Input​

{
"model": "route-llm",
"messages": [
{
"role": "user",
"content": [
{ "type": "text", "text": "Describe the image" },
{
"type": "image_url",
"image_url": {
"url": "https://example.com/image.jpg"
}
}
]
}
]
}

Note: Base64 images must use the data URI format: data:image/<format>;base64,<base64_string>


Image Generation​

The RouteLLM API supports image generation from text prompts using a wide range of state-of-the-art image generation models. Image generation uses the same unified chat completions endpoint as text generation, with additional modalities and image_config parameters.

Supported Models​

ModelDescription
flux_kontextContext-aware image generation
flux_kontext_editContext-aware image editing
flux_pro_ultraHighest quality FLUX generation
flux_proProfessional image generation
flux_pro_cannyEdge-guided image generation
flux_pro_depthDepth-guided image generation
flux2_proHigh-quality, photorealistic image generation
flux2Image generation

Request Parameters​

Image generation uses the same /v1/chat/completions endpoint as text generation.

model (string, required)​

The ID of the model to use. Can be any supported image generation model or a Gemini/OpenAI multimodal LLM.

messages (array, required)​

The conversation messages. The user's message should contain the image generation prompt.

{
"role": "user",
"content": "A beautiful sunset over mountains"
}

modalities (array, required for image generation)​

Must be set to ["image"] to generate images.

"modalities": ["image"]

image_config (object, optional)​

Configuration for image generation. Parameters vary by model.

Common Parameters​

The following parameters are supported by most image generation models:

ParameterTypeRequiredDescriptionValid ValuesDefault
promptstringYesDescribe the scene or action to generateAny text—
num_imagesintegerNoNumber of images to generate1–41
rewrite_promptbooleanNoAutomatically improve the prompt for better resultstrue, falsetrue

Note: num_images is not supported by flux_kontext_edit, gpt_image15_edit, imagine_art, magnific, and midjourney.

Model-Specific Parameters​

Model ID: flux_pro

ParameterTypeRequiredDescriptionValid ValuesDefault
sizestringNoResolution of the generated image1440x1440, 1440x1024, 1024x1440, 1440x768, 768x1440, 1024x1024, 1024x768, 768x1024, 768x576, 576x768, 640x640, 768x448, 448x768, 640x480, 480x6401440x1440
seednumberNoSeed for reproducible resultsAny integer—

Response Schema​

Image generation responses follow the same unified chat completion format. When modalities includes "image", the response contains image URLs in the images field of the message.

{
"created": 1677858242,
"model": "gemini-2.5-pro",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "",
"images": [
{
"type": "image_url",
"image_url": {
"url": "https://example.com/generated-image-1.png"
}
},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/generated-image-2.png"
}
}
]
},
"finish_reason": "stop"
}
],
"usage": {
"compute_points_used": 150
}
}

Code Examples​

1. Basic Image Generation​

from openai import OpenAI

client = OpenAI(
base_url="<your base url>",
api_key="<your_api_key>",
)

response = client.chat.completions.create(
model="gemini-2.5-pro",
messages=[
{
"role": "user",
"content": "A beautiful sunset over mountains"
}
],
modalities=["image"],
image_config={
"num_images": 1
}
)

for image in response.choices[0].message.images:
if image['type'] == "image_url":
print(f"Generated image: {image['image_url']['url']}")

2. Multiple Images​

from openai import OpenAI

client = OpenAI(
base_url="<your base url>",
api_key="<your_api_key>",
)

response = client.chat.completions.create(
model="flux2_pro", # use GET /v1/models for exact model IDs
messages=[
{
"role": "user",
"content": "A futuristic cityscape at night with neon lights and flying cars"
}
],
modalities=["image"],
image_config={
"num_images": 3,
"aspect_ratio": "1:1"
}
)

image_urls = [
item['image_url']['url']
for item in response.choices[0].message.images
if item['type'] == "image_url"
]
for idx, url in enumerate(image_urls, 1):
print(f"Image {idx}: {url}")

3. Portrait Orientation​

from openai import OpenAI

client = OpenAI(
base_url="<your base url>",
api_key="<your_api_key>",
)

response = client.chat.completions.create(
model="flux2_pro",
messages=[
{
"role": "user",
"content": "A full-body portrait of a fashion model in elegant evening wear"
}
],
modalities=["image"],
image_config={
"num_images": 1,
"aspect_ratio": "2:3"
}
)

for image in response.choices[0].message.images:
if image['type'] == "image_url":
print(f"Portrait image: {image['image_url']['url']}")

4. OpenAI Model with Quality Control​

from openai import OpenAI

client = OpenAI(
base_url="<your base url>",
api_key="<your_api_key>",
)

response = client.chat.completions.create(
model="gpt-5.1",
messages=[
{
"role": "user",
"content": "A whimsical illustration of a magical forest with glowing mushrooms"
}
],
modalities=["image"],
image_config={
"num_images": 1,
"aspect_ratio": "1:1",
"quality": "high"
}
)

for image in response.choices[0].message.images:
if image['type'] == "image_url":
print(f"Image URL: {image['image_url']['url']}")

5. Gemini Model with Image Size and Resolution​

from openai import OpenAI

client = OpenAI(
base_url="<your base url>",
api_key="<your_api_key>",
)

response = client.chat.completions.create(
model="nano_banana2",
messages=[
{
"role": "user",
"content": "A professional headshot of a business executive"
}
],
modalities=["image"],
image_config={
"num_images": 1,
"aspect_ratio": "2:3",
"resolution": "2K"
}
)

for image in response.choices[0].message.images:
if image['type'] == "image_url":
print(f"Image URL: {image['image_url']['url']}")