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

# Grok Imagine Editing

> Grok Imagine image editing fields, model constraints, and request examples.

Edit images with the xAI JSON request format. This endpoint does not use OpenAI multipart image uploads.

`POST https://api.mixroute.ai/v1/images/edits`

## Models

| Model ID                     | Capabilities and Limits                                                        |
| ---------------------------- | ------------------------------------------------------------------------------ |
| `grok-imagine-image-2.0`     | Generation/editing, quality selection, and up to five editing references.      |
| `grok-imagine-image-quality` | Earlier generation/editing model. Do not send the Image 2.0 quality parameter. |
| `grok-imagine-image`         | Earlier generation/editing model. Do not send the Image 2.0 quality parameter. |

## Request Parameters

| Field                                      | Type              | Required    | Description                                                                                                                                                 |
| ------------------------------------------ | ----------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `model`                                    | string            | Yes         | Complete Grok Imagine model ID.                                                                                                                             |
| `prompt`                                   | string            | Yes         | Text description of the requested image or edit.                                                                                                            |
| `image`                                    | object            | Conditional | Single source image, using `url` or `file_id`. Do not send it together with `images`.                                                                       |
| `images`                                   | object\[]         | Conditional | Multiple reference images, mutually exclusive with `image`. Image 2.0 supports up to five. Each item uses the same reference-object structure.              |
| `image.url / images[].url`                 | string            | Conditional | Public URL or Base64 data URI for a JPEG, PNG, or WebP image. Mutually exclusive with file\_id in the same object.                                          |
| `image.file_id / images[].file_id`         | string            | Conditional | Native xAI Files API ID of a fully uploaded image accessible to the route. Not a MixRoute task ID.                                                          |
| `n`                                        | integer           | No          | Number of images, 1-10; default 1.                                                                                                                          |
| `aspect_ratio`                             | string            | No          | Output aspect ratio; see the list below. Generation defaults to `auto`; editing normally follows the first input image unless a concrete ratio is provided. |
| `resolution`                               | string            | No          | `1k` (default) or `2k`, using lowercase k.                                                                                                                  |
| `quality`                                  | string            | No          | Grok Imagine Image 2.0 only: `low`, `medium`, or `auto` (default). Auto currently chooses low for generation and medium for editing.                        |
| `response_format`                          | string            | No          | `url` (default) or `b64_json`.                                                                                                                              |
| `user`                                     | string            | No          | Stable end-user identifier for abuse monitoring; avoid raw personal data.                                                                                   |
| `storage_options`                          | object            | No          | Optional native Files API storage configuration. Requires permissions in the upstream account used by the route.                                            |
| `storage_options.filename`                 | string            | Conditional | Required when storage\_options is supplied. Stored filename; its extension does not change the generated content type.                                      |
| `storage_options.expires_after`            | integer           | No          | Stored-file lifetime, 3600-2592000 seconds. Omit for no automatic expiry.                                                                                   |
| `storage_options.public_url`               | boolean \| object | No          | True requests a public URL; omit or false to avoid creating a persistent public URL. An object can configure its lifetime.                                  |
| `storage_options.public_url.expires_after` | integer           | No          | Public-URL lifetime, 3600-2592000 seconds. Defaults to the file lifetime and cannot exceed a configured file expiry.                                        |

## Aspect Ratios

`auto`, `1:1`, `3:4`, `4:3`, `9:16`, `16:9`, `2:3`, `3:2`, `9:19.5`, `19.5:9`, `9:20`, `20:9`, `1:2`, `2:1`, `21:9`, `5:2`

`21:9` and `5:2` are Image 2.0 additions. Use the other supported ratios with earlier models. Use `aspect_ratio` and `resolution`, not the GPT Image `size` field.

For editing, provide `image` or `images`. With multiple references, refer to them in order as `<IMAGE_0>`, `<IMAGE_1>`, and so on. Use direct JSON HTTP requests; the OpenAI SDK images.edit method sends multipart data and is not suitable for this xAI request.

## Examples

Use your MixRoute key in the `MIXROUTE_API_KEY` environment variable. Requests use `Authorization: Bearer ...`. Replace source-image placeholders with accessible images or local files before editing.

```bash theme={null}
curl --request POST "https://api.mixroute.ai/v1/images/edits" \
  --header "Authorization: Bearer $MIXROUTE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
  "model": "grok-imagine-image-2.0",
  "prompt": "Make the mug blue while preserving its shape, lighting, and background.",
  "image": {
    "url": "https://example.com/source.png"
  },
  "n": 1,
  "aspect_ratio": "1:1",
  "resolution": "1k",
  "quality": "low",
  "response_format": "url"
}'
```

### Python

```python theme={null}
import json
import os
import requests

payload = json.loads(r'''
{
  "model": "grok-imagine-image-2.0",
  "prompt": "Make the mug blue while preserving its shape, lighting, and background.",
  "image": {
    "url": "https://example.com/source.png"
  },
  "n": 1,
  "aspect_ratio": "1:1",
  "resolution": "1k",
  "quality": "low",
  "response_format": "url"
}
''')
response = requests.post(
    "https://api.mixroute.ai/v1/images/edits",
    headers={"Authorization": "Bearer " + os.environ["MIXROUTE_API_KEY"]},
    json=payload,
    timeout=180,
)
response.raise_for_status()
result = response.json()
for item in result["data"]:
    print(item.get("url") or item.get("b64_json"))
```

## Response

Read temporary image URLs from `data[].url`, or decode `data[].b64_json` without a data-URI prefix. `mime_type` identifies the encoding. When native storage is requested, `file_output` contains file information; a storage/public-URL error is distinct from generation failure.

[Grok image generation](/en/api-reference/endpoint/grok-imagine-image)
