在 OpenClaw 中使用 Flux Kontext。
Flux Kontext 由 Black Forest Labs 出品,支持文字引导的图像编辑和生成,并保持角色一致性。OpenClaw agent 通过 RunAPI 调用它,与聊天使用相同的 API key——发送 prompt,获取图像 URL。
Use RunAPI to generate an image with Flux Kontext Pro.
Requirements:
- Call the RunAPI text_to_image endpoint at https://runapi.ai/v1/text_to_image
- Set model to "flux-kontext-pro"
- Use the RUNAPI_API_KEY environment variable for authorization
- The response is async — poll the task status endpoint until the task completes, then retrieve the image URL
curl -X POST https://runapi.ai/v1/text_to_image \
-H "Authorization: Bearer $RUNAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "flux-kontext-pro",
"prompt": "a matte-black water bottle on a beige stone surface, soft side light, studio photography"
}'
{
"task_id": "tsk_abc123",
"status": "pending",
"model": "flux-kontext-pro"
}
三步在 OpenClaw 中使用 Flux Kontext
配置 RunAPI
设置 RUNAPI_API_KEY 环境变量。如果你已经在 OpenClaw 中将 RunAPI 配置为 provider 用于聊天,同一个 key 也适用于图像生成,无需额外配置。
export RUNAPI_API_KEY=runapi_xxx
调用 Flux Kontext
向 text_to_image 端点发送 POST 请求,将 model 设为 flux-kontext-pro,并附上描述所需图像的文字 prompt。如需上下文内编辑,可选填 image_url。
text_to_image
获取结果
端点返回任务 ID。轮询任务状态端点,直到状态变为 completed,然后从响应中获取生成的图像 URL。
task_id: tsk_abc123
Flux Kontext API 参数
| 参数 | 类型 | 说明 |
|---|---|---|
model |
string |
必填。flux-kontext-pro 或 flux-kontext-max。 |
prompt |
string |
用于生成或编辑的文字指令。 |
image_url |
string |
用于上下文内编辑的源图像 URL。 |
aspect_ratio |
string |
可选。输出宽高比。 |
OpenClaw 上的 Flux Kontext 是什么?
Flux Kontext 由 Black Forest Labs 出品,是一个连续图像编辑模型,用户称其在精准修改方面优于 ChatGPT 和 Gemini。用文字描述需要改动的部分,它只修改那部分,其余保持不变——换装时人脸不变,换背景时产品位置不变。OpenClaw agent 通过 RunAPI 的 text_to_image 端点调用它。
Flux Kontext 使用场景
保留主体的背景替换
在保持被摄对象完全相同位置的同时替换产品或肖像背景——无需遮罩,无需修复,只需一条文字指令。
服装与外观修改
在保留角色面部特征的前提下更换服装、发色或配饰,适用于时尚效果图和角色设计迭代。
标牌与标签文字替换
替换现有图像中标牌、产品标签或店面上的文字——在提示词中输入新文字,Flux Kontext 即可原位渲染。
Flux Kontext + OpenClaw 常见问题
可以。在 OpenClaw 中将 RunAPI 配置为 OpenAI 兼容 provider,然后以 flux-kontext-pro 为 model 调用 text_to_image 端点。用于聊天的同一个 RUNAPI_API_KEY 也可以处理图像生成。
不需要。同一个 RUNAPI_API_KEY 适用于所有 RunAPI 模型——LLM、图像、视频和音乐。一个 key,一个计费账户。
异步。API 立即返回任务 ID。轮询任务状态端点或使用 webhook 回调接收已完成的图像 URL。
Flux Kontext Pro 起价每张 2.5 美分。Flux Kontext Max 精度更高,价格也更高。查看 RunAPI 定价页面获取最新价格——按量计费,无需订阅。