# 文生图

> Images：按提示词生成图片，返回图片地址或 base64。
> 分组：模型接入
> 更新时间：2026-10-12
> 原文：https://www.chenra.com/docs/model-image

## 文生图（Images）

按提示词生成图片。返回 url（图片地址）或 b64_json（base64），取决于上游与 response_format。

支持的模型在「模型清单」里标有能力「文生图」，例如 wanx2.1-t2i-turbo、cogview-3-flash。

## 文生图

`POST /images/generations`

OpenAI 兼容的文生图接口；n / size / quality / response_format 会按上游能力转发。

### 请求参数

| 参数 | 类型 | 必填 | 说明 | 默认值 |
| --- | --- | --- | --- | --- |
| model | string | 是 | 文生图模型标识 |  |
| prompt | string | 是 | 图片描述 |  |
| n | integer | 否 | 生成张数 | 1 |
| size | string | 否 | 尺寸，如 1024x1024（部分厂商用 1024*1024） |  |
| response_format | string | 否 | url 或 b64_json | url |

### 请求示例

```bash
curl https://api.chenra.com/api/relay/v1/images/generations \
  -H "Authorization: Bearer sk-你的密钥" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "wanx2.1-t2i-turbo",
    "prompt": "一只坐在窗台上的橘猫，水彩风格",
    "size": "1024*1024",
    "n": 1
  }'
```

### 响应示例

```json
{
  "created": 1760000000,
  "model": "wanx2.1-t2i-turbo",
  "data": [
    { "url": "https://cdn.example.com/generated/xxxx.png" }
  ]
}
```

### 错误码

| 错误码 | 说明 |
| --- | --- |
| 400 | 缺少 prompt 参数 |
| 502 | 上游未返回图片 |
