Source: https://01router.com/zh/docs/models/recraft-v4/images Base URL: https://01router.com/api/v1 # Recraft V4 · OpenAI 兼容生图 POST /images/generations 兼容 OpenAI 图片接口,OpenAI SDK、LobeChat、Cherry Studio、Dify、n8n 都能直接调用这里的图片模型。size 会映射为最接近的 aspect_ratio,n 映射为 num_images,模型的其他参数可作为额外字段传入。最多等待约 110 秒,超时返回 504 和任务 id,可继续轮询。 `POST /api/v1/images/generations` 需要 Bearer API Key ## 输入参数 | Field | Type | Required | Description | Constraints | | --- | --- | --- | --- | --- | | model | string | yes | 模型目录中的 slug;项目密钥也可使用项目自定义的模型 slug。 | options: [ "recraft-v4" ] | | prompt | string | yes | 描述要生成的图片,必填且不能为空。 | | | provider | string | no | 可选供应商 slug。不传时自动路由;项目配置可能固定供应商。 | | | project | string | no | 可选项目 ID,使用该项目公开的模型目录和路由配置。 | | | size | string | no | 宽 x 高,例如 1024x1024,或 auto。必要时映射到最接近的受支持宽高比。 | | | n | integer | no | 正整数,默认 1。多图生成需要模型支持 num_images。 | default: 1; min: 1 | | response_format | string | no | url(默认)或 b64_json。Base64 转换失败或超过大小限制时,该条结果回退为 URL。 | default: "url"; options: [ "url", "b64_json" ] | | aspect_ratio | enum | no | | default: "1:1"; options: [ "1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3" ] | ## 输出字段 | Field | Type | Required | Description | Constraints | | --- | --- | --- | --- | --- | | created | integer | — | Unix 时间戳,单位为秒。 | | | data | array | — | 每项包含 url 或 b64_json,取决于 response_format 及转换是否成功。 | | | id | string | — | 创建任务返回的生成 ID。 | | | model | string | — | 模型目录中的 slug;项目密钥也可使用项目自定义的模型 slug。 | | | credits | number | — | 该任务扣除的积分,退款后为 0。 | | ## cURL ```bash curl 'https://01router.com/api/v1/images/generations' \ -H "Authorization: Bearer $API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "recraft-v4", "prompt": "A cinematic landscape at sunrise.", "aspect_ratio": "1:1" }' ``` ## 200 · application/json ```json { "created": 1792915200, "data": [ { "url": "https://example.com/result.png" } ], "id": "gen_example", "model": "recraft-v4", "credits": 10 } ``` ## 使用说明 - 轮询间隔至少 3 秒。同步生图接口返回 504 时,任务可能仍在进行,应使用 error.id 查询,避免重复创建。 - 调用 /generations 和 /quote 时,将以下参数放入 input;调用 /images/generations 时放在顶层;对话参数放在 /chat/completions 顶层。