# 创建图像

根据文本提示词生成一张或多张图像。

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

## 接口

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

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

[相关接入说明](https://www.unifyllm.com/zh/docs/gemini-image/)

## 参数

| 参数 | 位置 | 类型 | 必填 | 说明 | 可选值 | 示例 |
| --- | --- | --- | --- | --- | --- | --- |
| model | body | enum<string> | 是 | 图像生成模型。1K/2K 输出使用 gpt-image-2-c，4K 输出使用 gpt-image-2-4k-c。 | gpt-image-2-c, gpt-image-2-4k-c | gpt-image-2-c |
| prompt | body | string | 是 | 描述期望输出内容的文本提示词。 |  |  |
| size | body | enum<string> | 否 | 输出尺寸。可使用下方预设值，也可自定义 WxH。自定义尺寸的最大边不得超过 3840px，两边都必须是 16 的倍数，长短边比例不得超过 3:1，总像素数须在 655,360～8,294,400 之间。 | 1024x1024, 1536x1024, 2048x1536, 1024x1536, 1536x2048, 1440x2160, 2048x2048, 2880x2880, 3200x2560, 2560x3200, 3264x2448, 2448x3264, 3504x2336, 2336x3504, 3840x2160, 2160x3840, 3696x1584, auto | auto |

## 生成图像

```json
{
  "model": "gpt-image-2-c",
  "prompt": "会飞的小白兔，科幻风格",
  "size": "1024x1536"
}
```

### 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": "gpt-image-2-c",
  "prompt": "会飞的小白兔，科幻风格",
  "size": "1024x1536"
}'
```

### 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": "gpt-image-2-c",
    "prompt": "会飞的小白兔，科幻风格",
    "size": "1024x1536"
  }),
});

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\": \"gpt-image-2-c\",\n  \"prompt\": \"会飞的小白兔，科幻风格\",\n  \"size\": \"1024x1536\"\n}")
)
response.raise_for_status()
print(response.json())
```

## 响应示例

### 默认 — HTTP 200

```json
{"created":1785223107,"data":[{"url":"https://image.ezworkapi.top/origin-img?u=aHR0cHM6Ly9vc3M1LmN4a2VkdS5zaG9wL2ltYWdlcy8yMDI2LzA3LzI4LzE3ODUyMjMxMDdfMGNiMTE4MzMzMmMxMGM2Mzg3Mzk3N2QyMjJlMjY5ZjQucG5n&sig=df731cbb207003b14ed3d71c1fdf25369f66f1b1ea66a90f24d7a2dd5bac3eb0"}],"model":"gpt-image-2-c"}
```
