> ## 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 Edits

This API endpoint allows you to edit images using AI models. You can provide one or more base64-encoded images along with a text prompt describing the desired edit.

<Info>
  The Image Edits API supports both single and multiple image editing, with optional mask support for targeted edits.
</Info>

<Warning>
  Images stored via URL are only available for 1 hour after generation. Make sure to download and save important images locally.
</Warning>

## Create Image Edit

To edit an image, use the following endpoint:

`POST /v1/images/edits`

### Request Body

<ParamField body="images" type="array of string" required>
  Base64-encoded images (PNG format, \< 4MB each)
</ParamField>

<ParamField body="mask" type="string">
  Base64-encoded mask image (PNG format, \< 4MB) for targeted edits
</ParamField>

<ParamField body="prompt" type="string" required>
  Text description of the desired edit
</ParamField>

<ParamField body="model" type="string">
  Model to use for image editing
</ParamField>

<ParamField body="n" type="integer">
  Number of images to generate (1-10, default: 1)
</ParamField>

<ParamField body="size" type="string">
  Image size (options: "256x256", "512x512", "1024x1024")
</ParamField>

<ParamField body="response_format" type="string">
  Response format (options: "url" or "b64\_json", default: "url")
</ParamField>

<ParamField body="strength" type="number">
  Transformation strength (0.0-1.0)
</ParamField>

<ParamField body="guidance_scale" type="number">
  Guidance scale for the edit (0.0-20.0)
</ParamField>

<ParamField body="num_inference_steps" type="integer">
  Number of inference steps (1-100)
</ParamField>

<ParamField body="seed" type="integer">
  Random seed for reproducible results
</ParamField>

<ParamField body="kontext_max_mode" type="string">
  Kontext max mode configuration
</ParamField>

<RequestExample>
  ```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")
  )

  # Read and encode image
  with open("input.png", "rb") as image_file:
      encoded_image = base64.b64encode(image_file.read()).decode('utf-8')

  response = client.images.edit(
      images=[encoded_image],
      prompt="Add a sunset in the background",
      size="1024x1024",
      n=1
  )

  print(response.data[0].url)
  ```

  ```javascript Node.js theme={null}
  const axios = require('axios')
  const fs = require('fs')

  const apiKey = 'your_routeway_api_key'
  const url = 'https://api.routeway.ai/v1/images/edits'

  // Read and encode image
  const imageBuffer = fs.readFileSync('input.png')
  const encodedImage = imageBuffer.toString('base64')

  const data = {
  	images: [encodedImage],
  	prompt: 'Add a sunset in the background',
  	size: '1024x1024',
  	n: 1
  }

  const headers = {
  	'Content-Type': 'application/json',
  	Authorization: `Bearer ${apiKey}`,
  }

  axios
  	.post(url, data, { headers })
  	.then(response => {
  		console.log(response.data)
  	})
  	.catch(error => {
  		console.error('Error:', error)
  	})
  ```

  ```bash cURL theme={null}
  # First encode your image to base64
  ENCODED_IMAGE=$(base64 -i input.png)

  curl https://api.routeway.ai/v1/images/edits \
    -H "Authorization: Bearer $Routeway_API_KEY" \
    -H "Content-Type: application/json" \
    -d "{
      \"images\": [\"$ENCODED_IMAGE\"],
      \"prompt\": \"Add a sunset in the background\",
      \"size\": \"1024x1024\",
      \"n\": 1
    }"
  ```
</RequestExample>

### Response

The response includes the edited image(s) with either a URL or base64-encoded data, depending on the `response_format` parameter.

```json theme={null}
{
  "created": 1234567890,
  "data": [
    {
      "url": "https://example.com/image.png",
      "revised_prompt": "Add a sunset in the background"
    }
  ]
}
```

When `response_format` is set to `b64_json`, the response will include base64-encoded image data instead of a URL:

```json theme={null}
{
  "created": 1234567890,
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUgAA...",
      "revised_prompt": "Add a sunset in the background"
    }
  ]
}
```

### Error Response

```json theme={null}
{
  "error": {
    "message": "Invalid image format",
    "type": "invalid_request_error",
    "code": 400
  }
}
```
