---
title: Grok Image 图片生成
description: Grok Image 的模型、比例、1K / 2K 分辨率、返回格式和参考图编辑。
api: "POST /v1/images/generations"
---

使用 `grok-imagine-image` 或 `grok-imagine-image-2.0` 生成和编辑图片。API Key 需绑定具有图片权限的 Grok 分组。

<RequestExample>
```bash 生成图片
curl https://sub.vcnovb.cn/v1/images/generations \
  -H "Authorization: Bearer $VC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-imagine-image-2.0",
    "prompt": "未来城市的空中花园，建筑摄影，清晨阳光",
    "n": 1,
    "aspect_ratio": "16:9",
    "resolution": "1k",
    "response_format": "url"
  }'
```
```bash 参考图编辑
curl https://sub.vcnovb.cn/v1/images/edits \
  -H "Authorization: Bearer $VC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-imagine-image-2.0",
    "prompt": "将白天改为蓝调夜景，保留建筑轮廓",
    "image": {"url": "https://example.com/city.png"},
    "n": 1,
    "response_format": "url"
  }'
```
```python Python
import os
import requests

response = requests.post(
    "https://sub.vcnovb.cn/v1/images/generations",
    headers={"Authorization": f"Bearer {os.environ['VC_API_KEY']}"},
    json={
        "model": "grok-imagine-image-2.0",
        "prompt": "未来城市的空中花园，建筑摄影，清晨阳光",
        "n": 1, "aspect_ratio": "16:9", "resolution": "1k",
        "response_format": "url",
    },
    timeout=180,
)
response.raise_for_status()
print(response.json())
```
```javascript JavaScript
const response = await fetch("https://sub.vcnovb.cn/v1/images/generations", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.VC_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "grok-imagine-image-2.0",
    prompt: "未来城市的空中花园，建筑摄影，清晨阳光",
    n: 1, aspect_ratio: "16:9", resolution: "1k", response_format: "url",
  }),
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());
```
</RequestExample>

<ResponseExample>
```json URL
{"created":1794614400,"data":[{"url":"https://example.com/grok-image.png"}]}
```
```json Base64
{"created":1794614400,"data":[{"b64_json":"BASE64_IMAGE_DATA"}]}
```
</ResponseExample>

## 请求参数

<ParamField body="model" type="string" required>模型 ID，示例使用 `grok-imagine-image-2.0`。可用型号见[模型列表](/api/models)。</ParamField>
<ParamField body="prompt" type="string" required>画面描述；编辑时说明需要保留与修改的部分。</ParamField>
<ParamField body="n" type="integer" default="1">生成数量，默认 `1`。数量上限见对应模型说明。</ParamField>
<ParamField body="aspect_ratio" type="string">常见比例：`1:1`、`16:9`、`9:16`、`4:3`、`3:4`、`3:2`、`2:3`、`2:1`、`1:2`。</ParamField>
<ParamField body="resolution" type="string">图片分辨率，取值为 `1k` 或 `2k`，不区分大小写。</ParamField>
<ParamField body="response_format" type="string">`url` 或 `b64_json`，按返回字段读取结果。</ParamField>
<ParamField body="image" type="object">仅编辑请求：使用 `{"url":"https://example.com/image.png"}`，发送到 `/v1/images/edits`。</ParamField>
<ParamField body="images" type="array<object>">多张编辑来源图，最多 3 张；所选模型有更低上限时按模型限制提交。</ParamField>

## 比例与分辨率

使用 `aspect_ratio` 设置画面比例，使用 `resolution` 选择 1K 或 2K。例如，`"aspect_ratio": "16:9"` 与 `"resolution": "1k"` 组合表示横版 1K 图片。

## 返回结果

| 字段 | 说明 |
| --- | --- |
| `data[].url` | 图片下载地址 |
| `data[].b64_json` | Base64 图片数据，解码后保存为文件 |

结果链接请及时下载保存。编辑请求发送至 `/v1/images/edits`，并携带参考图和编辑提示词。
