# 创建 Grok 图像

使用 Grok 图像模型生成图像。

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

## 接口

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

认证与请求头以本页调用示例为准。 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 |
| model | body | string | 是 | 本次请求使用的模型标识符。 |  |  |
| n | body | integer | 否 | 需要生成的结果数量。 |  |  |
| resolution | body | string | 否 | 生成媒体的分辨率。 | 1k, 2k |  |
| response_format | body | string | 否 | 生成媒体的返回格式。 | url, b64_json | url |

## 示例 1

```json
{
  "model": "grok-imagine-image-quality",
  "prompt": "A collage of London landmarks in a stenciled street‑art style"
}
```

### cURL

```bash
curl --request POST \
  --url 'https://api.unifyllm.top/v1/images/generations' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "grok-imagine-image-quality",
  "prompt": "A collage of London landmarks in a stenciled street‑art style"
}'
```

### JavaScript

```javascript
const response = await fetch("https://api.unifyllm.top/v1/images/generations", {
  method: "POST",
  headers: {
    "Authorization": "Bearer <YOUR_API_KEY>",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "model": "grok-imagine-image-quality",
    "prompt": "A collage of London landmarks in a stenciled street‑art style"
  }),
});

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

### Python

```python
import json
import requests

response = requests.post(
    "https://api.unifyllm.top/v1/images/generations",
    headers={"Authorization": "Bearer <YOUR_API_KEY>"},
    json=json.loads("{\n  \"model\": \"grok-imagine-image-quality\",\n  \"prompt\": \"A collage of London landmarks in a stenciled street‑art style\"\n}")
)
response.raise_for_status()
print(response.json())
```

## 响应示例

### 示例 1 — HTTP 200

```json
{
  "data": [
    {
      "url": "https://imgen.x.ai/xai-imgen/xai-tmp-imgen-a73bae6f-5a65-4bec-9ffb-8220caa3fa61.jpeg",
      "mime_type": "image/jpeg",
      "revised_prompt": ""
    }
  ],
  "usage": {
    "cost_in_usd_ticks": 200000000
  }
}
```
