> ## Documentation Index
> Fetch the complete documentation index at: https://docs.routeway.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Image Generation & Editing

> Generate, edit, and inpaint images using /v1/images/generations and /v1/images/edits.

Routeway provides OpenAI-compatible endpoints for text-to-image generation and image editing. You can access top image models (including **Flux 1.1 Pro**, **Flux 2 Turbo**, **Flux Kontext Max**, **Recraft V3**, and **Stable Diffusion 3.5**) using standard OpenAI SDKs.

```http theme={null}
POST https://api.routeway.ai/v1/images/generations
POST https://api.routeway.ai/v1/images/edits
```

***

## Text to Image Generation

The `/v1/images/generations` endpoint converts text prompts into high-resolution images.

> [tab] Python
>
> ```python theme={null}
> import os
> from openai import OpenAI
>
> client = OpenAI(
>     base_url="https://api.routeway.ai/v1",
>     api_key=os.getenv("ROUTEWAY_API_KEY")
> )
>
> response = client.images.generate(
>     model="flux-1-schnell",
>     prompt="A serene Japanese garden at dawn, soft mist, cherry blossoms, photorealistic",
>     size="1024x1024",
>     n=1,
> )
>
> print("Image URL:", response.data[0].url)
> ```

> [tab] Node.js
>
> ```javascript theme={null}
> import OpenAI from "openai";
>
> const client = new OpenAI({
>   baseURL: "https://api.routeway.ai/v1",
>   apiKey: process.env.ROUTEWAY_API_KEY,
> });
>
> const response = await client.images.generate({
>   model: "flux-1-schnell",
>   prompt: "A serene Japanese garden at dawn, soft mist, cherry blossoms, photorealistic",
>   size: "1024x1024",
>   n: 1,
> });
>
> console.log("Image URL:", response.data[0].url);
> ```

> [tab] cURL
>
> ```bash theme={null}
> curl https://api.routeway.ai/v1/images/generations \
>   -H "Authorization: Bearer $ROUTEWAY_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "model": "flux-1-schnell",
>     "prompt": "A serene Japanese garden at dawn, soft mist, cherry blossoms, photorealistic",
>     "size": "1024x1024",
>     "n": 1
>   }'
> ```

***

## Image Editing & Inpainting

The `/v1/images/edits` endpoint allows you to modify an existing image by supplying a text prompt and an optional mask.

### Basic Image Edit

> [tab] Python
>
> ```python theme={null}
> import os
> import base64
> from openai import OpenAI
>
> client = OpenAI(
>     base_url="https://api.routeway.ai/v1",
>     api_key=os.getenv("ROUTEWAY_API_KEY")
> )
>
> with open("original.png", "rb") as f:
>     encoded_image = base64.b64encode(f.read()).decode("utf-8")
>
> response = client.images.edit(
>     model="flux-kontext-max",
>     image=encoded_image,
>     prompt="Replace the cloudy background with a vibrant sunset over mountains",
>     size="1024x1024",
> )
>
> print("Edited Image URL:", response.data[0].url)
> ```

> [tab] Node.js
>
> ```javascript theme={null}
> import OpenAI from "openai";
> import fs from "fs";
>
> const client = new OpenAI({
>   baseURL: "https://api.routeway.ai/v1",
>   apiKey: process.env.ROUTEWAY_API_KEY,
> });
>
> const encodedImage = fs.readFileSync("original.png").toString("base64");
>
> const response = await client.images.edit({
>   model: "flux-kontext-max",
>   image: encodedImage,
>   prompt: "Replace the cloudy background with a vibrant sunset over mountains",
>   size: "1024x1024",
> });
>
> console.log("Edited Image URL:", response.data[0].url);
> ```

***

## Parameters

### Generation Parameters (`/v1/images/generations`)

| Parameter | Type | Default | Description |
| - | - | - | - |
| `model` | string | **required** | Image model ID (e.g. `"flux-1-schnell"`, `"flux-2-turbo"`). |
| `prompt` | string | **required** | Text description of the desired image. |
| `size` | string | `"1024x1024"` | Resolution (`"1024x1024"`, `"1024x1792"`, `"1792x1024"`, etc.). |
| `quality` | string | `"standard"` | `"standard"` or `"hd"` (model dependent). |
| `response_format` | string | `"url"` | `"url"` (hosted image link) or `"b64_json"` (base64 data string). |
| `n` | integer | `1` | Number of images to generate. |

### Editing Parameters (`/v1/images/edits`)

| Parameter | Type | Description | |
| - | - | - | - |
| `image` | string | **required** | Base64 string or file buffer of original image. |
| `prompt` | string | **required** | Description of desired changes. |
| `mask` | string | Optional base64 alpha-mask image specifying regions to edit. | |
| `strength` | number | Optional transformation strength (`0.0` to `1.0`). | |

***

## Server Tools Integration

You can also trigger image generation directly inside conversation turns using Server Tools:

```python theme={null}
response = client.chat.completions.create(
    model="qwen3.8-max-preview@flux-2-turbo",
    messages=[{"role": "user", "content": "Draw a sunset over cyberpunk Tokyo."}]
)
```

See [Server Tools](https://docs.routeway.ai/features/server-tools.md) for more details.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.