# Edit Grok Image

Edit one or more reference images with a Grok image model.

- Source: https://www.unifyllm.com/docs/api-reference/edit-grok-image/
- Language: en

## Endpoint

```http
POST https://api.unifyllm.top/v1/images/edits
```

Use the authentication and headers shown in the request examples. Content-Type: application/json

## Parameters

| Field | Location | Type | Required | Description | Allowed values | Example |
| --- | --- | --- | --- | --- | --- | --- |
| prompt | body | string | yes | Text instruction describing the requested output. |  |  |
| aspect_ratio | body | string | no | Aspect ratio of the generated media. | 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, auto | auto |
| image | body | object | no | Input image used for editing or generation. |  |  |
| images | body | array | no | Input images used for multi-reference editing. |  |  |
| model | body | string | yes | Model identifier used for this request. |  |  |
| n | body | integer | no | Number of results to generate. |  |  |
| resolution | body | string | no | Resolution of the generated media. | 1k, 2k |  |
| response_format | body | string | no | Format used to return generated media. | url, b64_json | url |

## Standard Example

```json
{
  "model": "grok-imagine-image-quality",
  "prompt": "Render this as a pencil sketch with detailed shading",
  "image": {
    "url": "https://docs.x.ai/assets/api-examples/images/style-realistic.png",
    "type": "image_url"
  }
}
```

### cURL

```bash
curl --request POST \
  --url 'https://api.unifyllm.top/v1/images/edits' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "grok-imagine-image-quality",
  "prompt": "Render this as a pencil sketch with detailed shading",
  "image": {
    "url": "https://docs.x.ai/assets/api-examples/images/style-realistic.png",
    "type": "image_url"
  }
}'
```

### JavaScript

```javascript
const response = await fetch("https://api.unifyllm.top/v1/images/edits", {
  method: "POST",
  headers: {
    "Authorization": "Bearer <YOUR_API_KEY>",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "model": "grok-imagine-image-quality",
    "prompt": "Render this as a pencil sketch with detailed shading",
    "image": {
      "url": "https://docs.x.ai/assets/api-examples/images/style-realistic.png",
      "type": "image_url"
    }
  }),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import json
import requests

response = requests.post(
    "https://api.unifyllm.top/v1/images/edits",
    headers={"Authorization": "Bearer <YOUR_API_KEY>"},
    json=json.loads("{\n  \"model\": \"grok-imagine-image-quality\",\n  \"prompt\": \"Render this as a pencil sketch with detailed shading\",\n  \"image\": {\n    \"url\": \"https://docs.x.ai/assets/api-examples/images/style-realistic.png\",\n    \"type\": \"image_url\"\n  }\n}")
)
response.raise_for_status()
print(response.json())
```

## Response examples

### Example 1 — HTTP 200

```json
{
  "data": [
    {
      "url": "https://imgen.x.ai/xai-imgen/xai-tmp-imgen-82f06097-a9ad-4db4-9c8d-8197c74eebd1.jpeg",
      "mime_type": "image/jpeg",
      "revised_prompt": ""
    }
  ],
  "usage": {
    "cost_in_usd_ticks": 220000000
  }
}
```
