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

# 通过 Comfy Router 使用 AI Image Relight

> 通过 Comfy Router 调用 freepik/ai-image-relight：端点、请求结构和 Router 返回的响应。

`freepik/ai-image-relight` 的 API 参考，由 Comfy Router 从 Freepik 提供。

**输入：** 文本、图像 · **输出：** 图像

## 快速开始

在[你的 Comfy 工作区](https://platform.comfy.org/profile/api-keys?onboarding=router)中创建密钥，并将其导出为 `COMFY_API_KEY`。Python 和 TypeScript 代码片段使用 Comfy SDK（`pip install comfy-sdk` 和 `npm install @comfyorg/sdk`）；cURL 代码片段则是通过原始 HTTP 发出的同一个调用。

**模型 ID：** `freepik/ai-image-relight`

**端点：** `POST https://api.comfy.org/v2/models/freepik/ai-image-relight`

> [tab] 等待结果
>
> ```python Python theme={null}
> from comfy_sdk import Comfy
>
> # 从环境变量读取 COMFY_API_KEY。
> # SDK 会自动创建幂等键，并在自动重试时复用它。
> with Comfy() as client:
>     result = client.models.run(
>         "freepik/ai-image-relight",
>         {
>             "image": "https://img.magnific.com/free-photo/light-through-mountains_395237-33.jpg?semt=ais_hybrid&w=740&q=80",
>             "prompt": "warm golden-hour sunlight from the left",
>         },
>     )
>
> print(result)
> ```
>
> ```typescript TypeScript theme={null}
> import { comfy } from "@comfyorg/sdk";
>
> // 从环境变量读取 COMFY_API_KEY。
> // SDK 会自动创建幂等键，并在自动重试时复用它。
> const { data } = await comfy.models.run("freepik/ai-image-relight", {
>   image: "https://img.magnific.com/free-photo/light-through-mountains_395237-33.jpg?semt=ais_hybrid&w=740&q=80",
>   prompt: "warm golden-hour sunlight from the left",
> });
>
> console.log(data);
> ```
>
> ```bash cURL theme={null}
> curl https://api.comfy.org/v2/models/freepik/ai-image-relight \
>   -H "X-API-Key: $COMFY_API_KEY" \
>   -H "Idempotency-Key: $(uuidgen)" \
>   -H "Content-Type: application/json" \
>   -d "{\"image\": \"https://img.magnific.com/free-photo/light-through-mountains_395237-33.jpg?semt=ais_hybrid&w=740&q=80\", \"prompt\": \"warm golden-hour sunlight from the left\"}"
> ```

> [tab] 排队并稍后收集
>
> 相同的请求体，发送到 `POST https://api.comfy.org/v2/models/freepik/ai-image-relight/requests`。运行请求一经受理，Router 就会立即返回 `201` 和一个 `request_id`；结果就绪后即可收集，无论是从当前进程还是另一个进程收集。[队列投递](https://docs.comfy.org/zh/development/comfy-router/queue.md) 介绍了状态、取消和结果收集。
>
> ```python Python theme={null}
> import asyncio
> from comfy_sdk import AsyncComfy
>
> # 从环境变量读取 COMFY_API_KEY。
> # 每次 submit() 调用都会生成自己的 Idempotency-Key，并在自动重试时复用它。
> async def main():
>     async with AsyncComfy() as client:
>         handle = await client.models.submit(
>             "freepik/ai-image-relight",
>             {
>                 "image": "https://img.magnific.com/free-photo/light-through-mountains_395237-33.jpg?semt=ais_hybrid&w=740&q=80",
>                 "prompt": "warm golden-hour sunlight from the left",
>             },
>         )
>         print("request_id:", handle.request_id)  # 配合模型 ID，这就是另一个进程所需的全部信息
>
>         # 轮询直到请求完成，并等待服务器指定的 Retry-After 时间。
>         async for update in handle.iter_events():
>             print(update.status, update.queue_position)
>
>         # 提供商自己的响应负载，即 models.run() 返回的同一个值。
>         # 失败或已取消的请求会在此处抛出类型化的 Router 错误。
>         result = await handle.get()
>
>     print(result)
>
> asyncio.run(main())
> ```
>
> ```typescript TypeScript theme={null}
> import { comfy } from "@comfyorg/sdk";
>
> // 从环境变量读取 COMFY_API_KEY。
> // 每次 submit() 调用都会生成自己的 Idempotency-Key，并在自动重试时复用它。
> const handle = await comfy.models.submit("freepik/ai-image-relight", {
>   image: "https://img.magnific.com/free-photo/light-through-mountains_395237-33.jpg?semt=ais_hybrid&w=740&q=80",
>   prompt: "warm golden-hour sunlight from the left",
> });
> console.log("requestId:", handle.requestId); // 配合模型 ID，这就是另一个进程所需的全部信息
>
> // 轮询直到请求完成，并等待服务器指定的 Retry-After 时间。
> for await (const update of handle.events()) {
>   console.log(update.status, update.queuePosition);
> }
>
> // 与 models.run() 返回的结果相同。失败或已取消的请求会在此处被拒绝。
> const result = await handle.get();
>
> console.log(result.data);
> ```
>
> ```bash cURL theme={null}
> # 1. 提交。Router 返回 201，并带有 request_id、status_url、response_url 和 cancel_url。
> curl https://api.comfy.org/v2/models/freepik/ai-image-relight/requests \
>   -H "X-API-Key: $COMFY_API_KEY" \
>   -H "Idempotency-Key: $(uuidgen)" \
>   -H "Content-Type: application/json" \
>   -d "{\"image\": \"https://img.magnific.com/free-photo/light-through-mountains_395237-33.jpg?semt=ais_hybrid&w=740&q=80\", \"prompt\": \"warm golden-hour sunlight from the left\"}"
>
> # 2. 轮询直到状态为 COMPLETED，每次响应都会指明需要等待的 Retry-After 秒数。
> REQUEST_ID="<request_id from the 201 body>"
> curl -i https://api.comfy.org/v2/models/freepik/ai-image-relight/requests/$REQUEST_ID/status \
>   -H "X-API-Key: $COMFY_API_KEY"
>
> # 3. 收集。返回 200 和模型的原始输出；仍在运行时返回 202 和状态响应体。
> curl https://api.comfy.org/v2/models/freepik/ai-image-relight/requests/$REQUEST_ID \
>   -H "X-API-Key: $COMFY_API_KEY"
> ```

## Schema

### 输入

**advanced\_settings** `object`

**advanced\_settings.blacks** `integer` (default: 50)

调整图像中黑色的程度。

范围：`0` 到 `100`

**advanced\_settings.brightness** `integer` (default: 50)

调整图像中亮度的程度。

范围：`0` 到 `100`

**advanced\_settings.contrast** `integer` (default: 50)

调整图像中对比度的程度。

范围：`0` 到 `100`

**advanced\_settings.engine** `string` (default: "automatic")

用于重打光的引擎预设：

* balanced：全面均衡的通用选项
* cool：更明亮，色调偏冷
* real：旨在提升照片质感（实验性）
* illusio：针对插画和绘图优化
* fairy：适合奇幻主题图像
* colorful\_anime：理想用于动漫、卡通和鲜艳色彩
* hard\_transform：显著改变原始图像
* softy：效果略微柔和，适合平面设计

  可能的值：`automatic`, `balanced`, `cool`, `real`, `illusio`, `fairy`, `colorful_anime`, `hard_transform`, `softy`

**advanced\_settings.fixed\_generation** `boolean` (default: false)

启用后，使用相同的设置将始终生成相同的图像。

**advanced\_settings.saturation** `integer` (default: 50)

调整图像中饱和度的程度。

范围：`0` 到 `100`

**advanced\_settings.transfer\_light\_a** `string` (default: "automatic")

调整光照传递的强度。

可能的值：`automatic`, `low`, `medium`, `normal`, `high`, `high_on_faces`

**advanced\_settings.transfer\_light\_b** `string` (default: "automatic")

同样会改变光照传递强度。可与 transfer\_light\_a 组合使用，以获得多样的效果。

可能的值：`automatic`, `composition`, `straight`, `smooth_in`, `smooth_out`, `smooth_both`, `reverse_both`, `soft_in`, `soft_out`, `soft_mid`, `strong_mid`, `style_shift`, `strong_shift`

**advanced\_settings.whites** `integer` (default: 50)

调整图像中白色的程度。

范围：`0` 到 `100`

**change\_background** `boolean` (default: true)

启用后，会根据提示词和/或参考图像更改背景。适用于产品展示和肖像。

**image** `string` *required*

需要进行重打光的图像的 Base64 或 URL

**interpolate\_from\_original** `boolean` (default: false)

启用后，会通过光照传递强度滑块让最终图像从原始图像进行插值。

**light\_transfer\_strength** `integer` (default: 100)

光照传递的强度级别。0% 最接近原始图像，100% 为最大传递。

范围：`0` 到 `100`

**preserve\_details** `boolean` (default: true)

保留原始图像的纹理和小细节。适合产品摄影、文字等。

**prompt** `string`

你可以使用描述性提示词引导生成过程并影响光照传递。
重要：你可以通过在括号中使用 1 到 1.4 之间的数字来强调提示词中光照的特定方面，例如 "(dark scene:1.3)"。

**style** `string` (default: "standard")

重打光操作的风格预设。

可能的值：`standard`, `darker_but_realistic`, `clean`, `smooth`, `brighter`, `contrasted_n_hdr`, `just_composition`

**transfer\_light\_from\_lightmap** `string`

用于光照传递的光照贴图的 Base64 或 URL。与 'transfer\_light\_from\_reference\_image' 不兼容

**transfer\_light\_from\_reference\_image** `string`

用于光照传递的参考图像的 Base64 或 URL。与 'transfer\_light\_from\_lightmap' 不兼容

**webhook\_url** `string (uri)`

可选的回调 URL，每当任务状态发生变化时会接收异步通知。

格式：`uri`

根据 Router 在 `GET /v2/models/freepik/ai-image-relight/openapi.json` 提供的 schema 生成，Router 在请求到达提供商之前校验调用时所依据的也是同一份文档。

### 输出

**data** `object` *required*

**data.generated** `string (uri)[]` *required*

已完成的生成结果的图像 URL。在 Router 返回的文档中始终存在且非空；该列表本身就是结果。这些链接由 Freepik 提供，并会过期。

**data.status** `string` *required*

可能的值：`COMPLETED`

**data.task\_id** `string (uuid)`

格式：`uuid`

## 示例

### 输入

```json theme={null}
{
  "image": "https://img.magnific.com/free-photo/light-through-mountains_395237-33.jpg?semt=ais_hybrid&w=740&q=80",
  "prompt": "warm golden-hour sunlight from the left"
}
```

### 输出

```json theme={null}
{
  "data": {
    "generated": [
      "https://example.invalid/freepik/ai-image-relight/relit.png"
    ],
    "status": "COMPLETED",
    "task_id": "046b6c7f-0b8a-43b9-b35d-6489e6daee91"
  }
}
```

## 发布前须知

SDK 会生成 `Idempotency-Key` 并在自动重试中复用它。手动重试时，请复用原始 key。Router 最长可保持连接 10 分钟。

请求失败时，Router 会发送 `X-Comfy-Error-Type` 响应头说明原因。`422` 表示 Router 在调用提供商之前就拒绝了输入，`413` 表示请求体超出了 Router 可接受的大小。已生成的资源请及时下载，因为[结果 URL 会过期](https://docs.comfy.org/zh/development/comfy-router/reference.md#结果资产)。

上文任何字段描述中提到的尺寸限制，都是提供商对该字段自身的限定，引自提供商的规范。Router 会对整个请求体另行设置上限，base64 编码的媒体内容也计入其中：参见[请求体大小](https://docs.comfy.org/zh/development/comfy-router/limitations.md)。

本页记录的是通过 Comfy Router 调用的某一个合作伙伴模型。同一个 `comfy-sdk` / `@comfyorg/sdk` 包还提供第二个客户端，用于在 Comfy Cloud 上运行完整的 ComfyUI 工作流图：`Comfy(api_key=...)` / `new Comfy({ apiKey })`，并带有 `client.workflows`、`client.assets` 和 `client.jobs`。请参阅 [Comfy SDKs](https://docs.comfy.org/zh/development/api-development/sdks.md)。

> [card] [请求头](https://docs.comfy.org/zh/development/comfy-router/headers.md)
>
> 身份验证、幂等性、请求 ID、错误分类、重试节奏、消费限额。

> [card] [使用 Router API](https://docs.comfy.org/zh/development/comfy-router/api.md)
>
> 模型发现、验证错误、重试与计费。

> [card] [限制](https://docs.comfy.org/zh/development/comfy-router/limitations.md)
>
> Router 目前不支持的功能，以及替代方案。


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