# 编辑 Grok 图像

使用 Grok 图像模型编辑一张或多张参考图像。

- 原文: https://www.unifyllm.com/zh/docs/api-reference/edit-grok-image/
- 语言: zh-CN

## 接口

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

认证与请求头以本页调用示例为准。 Content-Type: application/json

## 参数

| 参数 | 位置 | 类型 | 必填 | 说明 | 可选值 | 示例 |
| --- | --- | --- | --- | --- | --- | --- |
| prompt | body | string | 是 | 描述期望输出内容的文本提示词。 |  |  |
| aspect_ratio | body | string | 否 | 生成媒体的宽高比。 | 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 | 否 | 用于编辑或生成的输入图像。 |  |  |
| images | body | array | 否 | 用于多参考图编辑的输入图像列表。 |  |  |
| model | body | string | 是 | 本次请求使用的模型标识符。 |  |  |
| n | body | integer | 否 | 需要生成的结果数量。 |  |  |
| resolution | body | string | 否 | 生成媒体的分辨率。 | 1k, 2k |  |
| response_format | body | string | 否 | 生成媒体的返回格式。 | url, b64_json | url |

## 普通示例

```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())
```

## 响应示例

### 示例 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
  }
}
```
