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

# 图像生成

> 使用 DALL-E 3、Stable Diffusion、Flux 等模型从文字提示生成图像。ARouter 通过单一统一端点路由图像生成请求。

ARouter 通过与 OpenAI 兼容的 `/v1/images/generations` 端点支持图像生成。

## 快速开始

```bash theme={null}
curl https://api.arouter.ai/v1/images/generations \
  -H "Authorization: Bearer lr_live_xxxx" \
  -H "Content-Type: application/json" \
  -d '{"model": "openai/dall-e-3", "prompt": "A futuristic city skyline at sunset, photorealistic", "n": 1, "size": "1024x1024"}'
```

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    from openai import OpenAI
    client = OpenAI(base_url="https://api.arouter.ai/v1", api_key="lr_live_xxxx")
    response = client.images.generate(
        model="openai/dall-e-3",
        prompt="A futuristic city skyline at sunset, photorealistic",
        n=1, size="1024x1024", quality="hd"
    )
    print(response.data[0].url)
    ```
  </Tab>

  <Tab title="Node.js">
    ```typescript theme={null}
    import OpenAI from "openai";
    const client = new OpenAI({ baseURL: "https://api.arouter.ai/v1", apiKey: "lr_live_xxxx" });
    const response = await client.images.generate({
      model: "openai/dall-e-3",
      prompt: "A futuristic city skyline at sunset, photorealistic",
      n: 1, size: "1024x1024", quality: "hd"
    });
    console.log(response.data[0].url);
    ```
  </Tab>
</Tabs>

## 请求参数

| 参数                | 类型        | 描述                                                     |
| ----------------- | --------- | ------------------------------------------------------ |
| `model`           | `string`  | 图像生成模型 ID                                              |
| `prompt`          | `string`  | 所需图像的文字描述。DALL-E 3 最多 4,000 个字符，DALL-E 2 最多 1,000 个字符。 |
| `n`               | `integer` | 生成图像数量（默认 `1`）。DALL-E 3 仅支持 `n=1`。                     |
| `size`            | `string`  | 图像尺寸（因模型而异）                                            |
| `quality`         | `string`  | `"standard"` 或 `"hd"`（仅 DALL-E 3，默认 `"standard"`）      |
| `style`           | `string`  | `"vivid"`（超现实）或 `"natural"`（仅 DALL-E 3）                |
| `response_format` | `string`  | `"url"`（默认）或 `"b64_json"`                              |

## 响应格式

```json theme={null}
{
  "created": 1234567890,
  "data": [
    {"url": "https://...", "revised_prompt": "A photorealistic futuristic city skyline at sunset..."}
  ]
}
```

## 图像尺寸

### DALL-E 3

| 尺寸          | 宽高比      |
| ----------- | -------- |
| `1024x1024` | 正方形（1:1） |
| `1792x1024` | 横向（16:9） |
| `1024x1792` | 纵向（9:16） |

## 支持的模型

| 模型                                   | 提供商          | 分辨率          | 风格控制       |
| ------------------------------------ | ------------ | ------------ | ---------- |
| `openai/dall-e-3`                    | OpenAI       | 最高 1792×1024 | `style` 参数 |
| `openai/dall-e-2`                    | OpenAI       | 最高 1024×1024 | —          |
| `stability/stable-diffusion-3-large` | Stability AI | 最高 1024×1024 | —          |
| `black-forest-labs/flux-1-pro`       | Replicate    | 灵活           | —          |

## 定价

| 模型                     | 尺寸                    | 费用      |
| ---------------------- | --------------------- | ------- |
| `openai/dall-e-3` 标准版  | 1024×1024             | \$0.040 |
| `openai/dall-e-3` 标准版  | 1024×1792 或 1792×1024 | \$0.080 |
| `openai/dall-e-3` HD 版 | 1024×1024             | \$0.080 |
| `openai/dall-e-3` HD 版 | 1024×1792 或 1792×1024 | \$0.120 |
| `openai/dall-e-2`      | 1024×1024             | \$0.020 |

<Note>
  ARouter 返回的图像 URL 在 1 小时后过期。请下载并保存您想保留的图像。
</Note>
