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

# 图片生成

> 异步图片生成、同步等待和图片编辑接口。

生产环境推荐使用 `/v1/images/generations` 创建异步图片任务。

```bash theme={null}
curl https://apiany.ai/v1/images/generations \
  -H "Authorization: Bearer $APIANY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nano-banana",
    "prompt": "A bright API dashboard rendered as a product hero image",
    "size": "1k"
  }'
```

接口会返回任务信息：

```json theme={null}
{
  "task_id": "task_123",
  "status": "processing",
  "poll_url": "/v1/tasks/task_123"
}
```

## GPT-Image 2 尺寸与质量

调用 `gpt-image-2` 时，推荐直接传入原生像素尺寸或 `auto`：

```bash theme={null}
curl https://apiany.ai/v1/images/generations \
  -H "Authorization: Bearer $APIANY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "为 AI API 平台生成一张横版产品发布视觉图",
    "size": "2048x1152",
    "quality": "high",
    "n": 1
  }'
```

GPT-Image 2 的最终输出使用 `auto` 或七个官方常用尺寸之一：`1024x1024`、`1536x1024`、`1024x1536`、`2048x2048`、`2048x1152`、`3840x2160`、`2160x3840`。APIAny 也接受任意正整数 `宽x高` 作为目标尺寸，并在保持方形、横图或竖图方向的前提下映射到最接近的常用尺寸。例如，`1280x720` 映射为 `1536x1024`，`1920x1080` 映射为 `2048x1152`，`1440x2560` 映射为 `2160x3840`。

`quality` 可选 `auto`、`low`、`medium`、`high`，默认是 `auto`。`n` 支持 1–10，并按实际生成图片数量逐张计费。比例简写（例如 `size: "4:3"`）仍可与兼容参数 `resolution: "1K"`、`"2K"` 或 `"4K"` 组合使用；APIAny 会先计算目标尺寸，再执行相同的最近官方常用尺寸映射。只传 `aspect_ratio`、`resolution` 或 `img_size` 的旧请求仍然兼容。新接入建议优先使用 `auto` 或七个官方常用尺寸，以获得可预期的输出与计费结果。

## 同步等待接口

`/v1/images/generations/sync` 会等待生成结果返回，或在达到最大等待时间后返回当前状态。

该接口适合兼容 OpenAI Images 风格或调试场景。生产系统建议使用异步接口。

## 图片编辑

`/v1/images/edits` 用于 OpenAI 风格图片编辑。只有支持参考图的模型可以调用该接口。
