---
title: GPT Image 图片生成
description: GPT Image 模型、尺寸、数量、质量和返回格式，以及 cURL、Python、JavaScript 示例。
api: "POST /v1/images/generations"
---

根据提示词生成图片，支持 URL 和 Base64 返回方式。API Key 需绑定具有图片权限的分组；异步调用见[图片任务](/api/image-tasks)。

<RequestExample>
```bash cURL · URL 结果
curl https://sub.vcnovb.cn/v1/images/generations \
  -H "Authorization: Bearer $VC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "白色背景上的橙色玻璃水杯，柔和侧光，产品摄影",
    "n": 1,
    "size": "1024x1024",
    "response_format": "url"
  }'
```
```bash cURL · Base64 结果
curl https://sub.vcnovb.cn/v1/images/generations \
  -H "Authorization: Bearer $VC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-image-2","prompt":"山间木屋，清晨薄雾，水彩风格","n":1,"size":"1536x1024","response_format":"b64_json"}'
```
```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": "gpt-image-2",
        "prompt": "白色背景上的橙色玻璃水杯，柔和侧光，产品摄影",
        "n": 1, "size": "1024x1024", "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: "gpt-image-2",
    prompt: "白色背景上的橙色玻璃水杯，柔和侧光，产品摄影",
    n: 1, size: "1024x1024", 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/result.png"}]}
```
```json Base64
{"created":1794614400,"data":[{"b64_json":"BASE64_IMAGE_DATA"}]}
```
```json 参数错误
{"error":{"type":"invalid_request_error","message":"n must be greater than 0"}}
```
</ResponseExample>

## 模型选择

| 模型 | 说明 |
| --- | --- |
| `gpt-image-2` | 本页示例使用的模型 |
| `gpt-image-1`、`gpt-image-1.5` | 选择包含对应型号的分组，参数按模型说明填写 |
| `gpt-image-2.5`、`gpt-image-2.6` 及其可用型号 | 通过[模型列表](/api/models)获取完整模型 ID |

## 请求参数

<ParamField body="model" type="string" required>当前 Key 可用的 GPT Image 模型 ID。</ParamField>
<ParamField body="prompt" type="string" required>生成提示词。建议写明主体、材质、背景、构图和文字要求。</ParamField>
<ParamField body="n" type="integer" default="1">生成数量，必须为大于 0 的整数，默认 `1`。数量上限见模型说明。</ParamField>
<ParamField body="size" type="string">输出像素尺寸，格式为 `宽x高`，例如 `1024x1024`、`1536x1024`、`1024x1536`。</ParamField>
<ParamField body="response_format" type="string">返回格式：`url` 为图片地址，`b64_json` 为 Base64 图片数据。</ParamField>
<ParamField body="quality" type="string">图片质量，省略时使用模型默认值。可选值见对应模型说明。</ParamField>
<ParamField body="background" type="string">背景控制，仅在支持该选项的模型上使用。</ParamField>
<ParamField body="output_format" type="string">图片文件格式，适用于支持格式选择的模型；`response_format` 用于选择 URL 或 Base64 返回方式。</ParamField>
<ParamField body="output_compression" type="integer">图片压缩程度，适用于支持压缩的模型和输出格式。</ParamField>

## 尺寸与参考图

| 场景 | 示例尺寸 |
| --- | --- |
| 方图 | `1024x1024` |
| 横图 | `1536x1024` |
| 竖图 | `1024x1536` |

其他尺寸和清晰度档位见对应模型说明。模型名称带清晰度后缀时，使用匹配的尺寸。

## 返回结果

| 字段 | 说明 |
| --- | --- |
| `created` | 生成时间，Unix 时间戳 |
| `data[].url` | 图片下载地址 |
| `data[].b64_json` | Base64 图片数据，解码后保存为文件 |

结果 URL 请及时下载保存。需要参考图时使用[图片编辑接口](/models/image/edit)。
