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

# 图片生成 API

## 接入前准备

先登录 LuluLab，在「我的 Key」获取 luk- 开头的 API Key，并在自己的服务端保存。所有示例都向 [https://customer.lululab.ai](https://customer.lululab.ai) 发起请求；Authorization 请求头直接填写原始 Key。 [获取 API Key](https://www.lululab.ai/keys)

生成任务是异步的：POST /tasks 返回任务 id，随后调用 GET /tasks/\{id} 获取状态与 output。可以先通过 POST /billing/estimates 预估积分。

适用于文生图和参考图生图。使用 ImageGenV2；prompt 是图片描述，referenceImages 可省略。模型、比例与分辨率需要采用该模型支持的组合。

### 什么时候使用

如果你已经写好了画面描述，直接提交图片任务；如果需要尽量保留商品外观，先上传商品照片，并把上传结果的 location 放进 referenceImages\[].url。生成完成后从任务的 output 读取图片结果。

### 主要请求字段

| 字段 / 类型 | 必填 | 可选值与说明 |
| - | - | - |
| `input.model` (`string`) | 是 | gpt-image-2-5-sunburst · gpt-image-2-5-flare · 图片模型 ID；下面的模型表列出支持的组合。 |
| `input.prompt` (`string`) | 是 | 1–20,000 characters · 描述主体、构图、场景与风格；前端限制最多 20,000 字符。 |
| `input.aspectRatio` (`string`) | 是 | 1:1 · 16:9 · 9:16 · 4:3 · 3:4 · 3:2 · 2:3 · 5:4 · 4:5 · 2:1 · 1:2 · 21:9 · 9:21 · 目标图片宽高比，取模型支持的值。 |
| `input.resolution` (`string`) | 是 | 1K · 2K · 4K · 目标清晰度，需与模型及比例组合兼容。 |
| `input.referenceImages` (`array<MediaReference>`) | 否 | 参考图数组；纯文字生图可省略。每项含 url 和 mimeType。 |

### 图片模型与枚举

当前网站创作页提供以下模型；二者均提供 1K、2K、4K，支持下面列出的比例。

`gpt-image-2-5-sunburst · gpt-image-2-5-flare`

分辨率：`1K · 2K · 4K`\
宽高比：`1:1 · 16:9 · 9:16 · 4:3 · 3:4 · 3:2 · 2:3 · 5:4 · 4:5 · 2:1 · 1:2 · 21:9 · 9:21`

```bash 图片生成请求 theme={null}
curl -X POST https://customer.lululab.ai/tasks \
  -H "Authorization: $LULULAB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "workflowId": "ImageGenV2",
    "input": {
      "model": "gpt-image-2-5-flare",
      "prompt": "Studio product photo of a ceramic cup on a clean table",
      "aspectRatio": "1:1",
      "resolution": "1K"
    },
    "attributes": { "saveGeneratedAssets": true, "creationSource": "api" }
  }'
```

> [!NOTE]
>
> 这段示例是纯文字生图。要做参考图生图，先按接入首页的上传步骤取得素材地址，再把 referenceImages 添加到 input。

* [上传参考素材](https://docs.lululab.ai/cn/uploads.md)
* [查询任务与错误](https://docs.lululab.ai/cn/task-results.md)
* [接口参考](https://docs.lululab.ai/cn/reference.md)


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