> ## 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`](/zh/api-reference/image/edits)，并用提示词描述你想要的变化。
</Warning>

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

<ParamField body="image" type="file" required>
  源图。必须是小于 4 MB 的正方形 PNG。
</ParamField>

<ParamField body="model" type="string" default="dall-e-2">
  只有 `dall-e-2` 实现了变体功能。
</ParamField>

<ParamField body="n" type="integer" default="1">
  变体数量，1–10。
</ParamField>

<ParamField body="size" type="string" default="1024x1024">
  `256x256`、`512x512` 或 `1024x1024`。
</ParamField>

<ParamField body="response_format" type="string" default="url">
  `url` 或 `b64_json`。URL 在生成约 60 分钟后失效，请及时下载。
</ParamField>

<ParamField body="user" type="string">
  稳定的终端用户标识。
</ParamField>

<RequestExample>
  ```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])
  ```
</RequestExample>

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

<ResponseField name="created" type="integer">
  生成时间的 Unix 时间戳。
</ResponseField>

<ResponseField name="data" type="array">
  每个变体一项，按 `response_format` 返回 `url` 或 `b64_json`。
</ResponseField>

## 错误

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


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