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

# 图像生成

> 兼容 OpenAI 的图像生成接口。同步模式——响应会一直保持连接，直到图像生成完毕。

## Endpoint

```
POST https://vibetoken.cn/v1/images/generations
```

兼容 OpenAI 的 [Image Generation API](https://platform.openai.com/docs/api-reference/images)。连接会一直保持打开，直到上游模型返回结果（通常为 5–30 秒）。

## Request Headers

| Header          | Value                       |
| --------------- | --------------------------- |
| `Authorization` | `Bearer sk-rb-xxxxxxxxxxxx` |
| `Content-Type`  | `application/json`          |

## Request Body

<ParamField body="model" type="string" required>
  图像模型 ID。例如 `google/imagen-4`、`blackforestlabs/flux-2-pro`、`ideogram/ideogram-3-0`。
</ParamField>

<ParamField body="prompt" type="string" required>
  待生成图像的文本描述。
</ParamField>

<ParamField body="n" type="integer">
  要生成的图像数量。默认为 `1`。
</ParamField>

<ParamField body="aspect_ratio" type="string">
  例如 `1:1`、`16:9`、`9:16`、`4:3`、`3:4`。取决于具体模型——并非所有模型都支持此参数。
</ParamField>

<ParamField body="resolution" type="string">
  例如 `1K`、`2K`、`4K`。取决于具体模型。
</ParamField>

<ParamField body="quality" type="string">
  例如 `hd`、`standard`。取决于具体模型。
</ParamField>

<ParamField body="style" type="string">
  例如 `natural`、`vivid`。取决于具体模型。
</ParamField>

<ParamField body="negative_prompt" type="string">
  希望从图像中排除的内容。取决于具体模型。
</ParamField>

<ParamField body="image_urls" type="array">
  图生图 / 编辑 / 放大 / 重构图 / 混合（remix）类模型必需。每一项可以是公开的 HTTPS URL，**也可以**是内联的 base64 `data:` URI（例如 `data:image/png;base64,…`）——内联图像会在生成前被自动解码并托管，因此无需针对特定 provider 做任何特殊处理。对于超过几 MB 的内容，建议通过 `POST /v1/uploads` 上传，并传入返回的 URL。
</ParamField>

## Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://vibetoken.cn/v1/images/generations \
    -H "Authorization: Bearer sk-rb-xxxxxxxxxxxx" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "bytedance/seedream-4.0",
      "prompt": "A red apple on a white table",
      "aspect_ratio": "1:1",
      "resolution": "1K"
    }'
  ```

  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="sk-rb-xxxxxxxxxxxx",
      base_url="https://vibetoken.cn/v1",
  )

  img = client.images.generate(
      model="google/imagen-4",
      prompt="A red apple on a white table",
      extra_body={"aspect_ratio": "1:1", "resolution": "1K"},
  )
  print(img.data[0].url)
  ```
</CodeGroup>

## Response

```json theme={null}
{
  "created": 1776245700,
  "data": [
    { "url": "https://media.vibetoken.cn/media/<user>/<gen>/0.png" }
  ]
}
```

当配置了 R2 存储后，VibeToken 会将上游 URL 重新托管到自己的 CDN 上，从而使链接不会过期。

## Image-to-image

对于图生图 / 编辑类模型（例如 `blackforestlabs/flux-2-pro-i2i`、`ideogram/ideogram-character-edit`），需提供 `image_urls`：

```json theme={null}
{
  "model": "blackforestlabs/flux-2-pro-i2i",
  "prompt": "Make it watercolor",
  "image_urls": ["https://example.com/source.jpg"]
}
```
