> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pipellm.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 生成图像变体

> 基于源图生成变体。

> [!WARNING]
>
> 上游只有 `dall-e-2` 实现了这个接口，GPT 图像模型不支持。想用 GPT 图像模型做变体，请把源图发到 [`POST /v1/images/edits`](https://docs.pipellm.ai/zh/api-reference/image/edits)，并用提示词描述你想要的变化。

不需要提示词，直接基于源图生成新图像。始终使用 `multipart/form-data`。

**image** `file` *required*

源图。必须是小于 4 MB 的正方形 PNG。

**model** `string` (default: dall-e-2)

只有 `dall-e-2` 实现了变体功能。

**n** `integer` (default: 1)

变体数量，1–10。

**size** `string` (default: 1024x1024)

`256x256`、`512x512` 或 `1024x1024`。

**response\_format** `string` (default: url)

`url` 或 `b64_json`。URL 在生成约 60 分钟后失效，请及时下载。

**user** `string`

稳定的终端用户标识。

```bash cURL theme={"dark"}
curl https://api.pipellm.ai/v1/images/variations \
  -H "Authorization: Bearer $PIPELLM_API_KEY" \
  -F model="dall-e-2" \
  -F image="@logo.png" \
  -F n=2 \
  -F size="1024x1024"
```

```python Python theme={"dark"}
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["PIPELLM_API_KEY"],
    base_url="https://api.pipellm.ai/v1",
)

result = client.images.create_variation(
    model="dall-e-2",
    image=open("logo.png", "rb"),
    n=2,
    size="1024x1024",
)
print([item.url for item in result.data])
```

```json theme={"dark"}
{
  "created": 1726400000,
  "data": [
    { "url": "https://..." },
    { "url": "https://..." }
  ]
}
```

**created** `integer`

生成时间的 Unix 时间戳。

**data** `array`

每个变体一项，按 `response_format` 返回 `url` 或 `b64_json`。

## 错误

错误信封与 [错误处理](https://docs.pipellm.ai/zh/api-reference/errors.md) 一致。源图非正方形或体积超限返回 `400`；模型不支持变体时，上游错误原样返回。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.