fal.ai Integration
Generate and edit images via fal.ai's queue-based API.
Setup
Add your API key to TOOLS.md:
CODEBLOCK0
Get a key at: https://fal.ai/dashboard/keys
The script checks (in order): FAL_KEY env var → INLINECODE2
Supported Models
fal-ai/nano-banana-pro (Text → Image)
Google's Gemini 3 Pro for text-to-image generation.
CODEBLOCK1
fal-ai/nano-banana-pro/edit (Image → Image)
Gemini 3 Pro for image editing. Slower (~20s) but handles complex edits well.
CODEBLOCK2
fal-ai/flux/dev/image-to-image (Image → Image)
FLUX.1 dev model. Faster (~2-3s) for style transfers.
CODEBLOCK3
fal-ai/kling-video/o3/pro/video-to-video/edit (Video → Video)
Kling O3 Pro for video transformation with AI effects.
Limits:
- - Formats: .mp4, .mov only
- Duration: 3-10 seconds
- Resolution: 720-2160px
- Max file size: 200MB
- Max elements: 4 total (elements + reference images combined)
CODEBLOCK4
Prompt references:
- -
@Video1 — the input video - INLINECODE4 ,
@Image2 — reference images for style/appearance - INLINECODE6 ,
@Element2 — elements (characters/objects) to inject
Input Validation
The skill validates inputs before submission. For multi-input models, ensure all required fields are provided:
CODEBLOCK5
Before submitting, verify:
- - ✅ All
required fields are present and non-empty - ✅ File fields (
image_url, video_url, etc.) are URLs or base64 data URIs - ✅ Arrays (
image_urls) have at least one item - ✅ Video files are within limits (200MB, 720-2160p)
Example validation output:
CODEBLOCK6
Usage
CLI Commands
CODEBLOCK7
Python Usage
CODEBLOCK8
Queue System
fal.ai uses async queues. Requests go through stages:
- -
IN_QUEUE → waiting - INLINECODE13 → generating
- INLINECODE14 → done, fetch result
- INLINECODE15 → error occurred
Pending requests are saved to ~/. openclaw/workspace/fal-pending.json and survive restarts.
Polling Strategy
Manual: Run python3 scripts/fal_client.py poll periodically.
Heartbeat: Add to HEARTBEAT.md:
CODEBLOCK9
Cron: Schedule polling every few minutes for background jobs.
Adding New Models
- 1. Find the model on fal.ai and check its
/api page - Add entry to
references/models.json with input/output schema - Test with a simple request
Note: Queue URLs use base model path (e.g., fal-ai/flux not fal-ai/flux/dev/image-to-image). The script handles this automatically.
Files
CODEBLOCK10
Troubleshooting
"No FALKEY found" → Add key to TOOLS.md or set FALKEY env var
405 Method Not Allowed → URL routing issue, ensure using base model path for status/result
Request stuck → Check fal-pending.json, may need manual cleanup
fal.ai 集成
通过 fal.ai 基于队列的 API 生成和编辑图像。
设置
将你的 API 密钥添加到 TOOLS.md:
markdown
fal.ai
FAL_KEY: your-key-here
在以下地址获取密钥:https://fal.ai/dashboard/keys
脚本按以下顺序检查:FAL_KEY 环境变量 → TOOLS.md
支持的模型
fal-ai/nano-banana-pro(文本 → 图像)
谷歌 Gemini 3 Pro 用于文本到图像生成。
python
input_data = {
prompt: 月球上的猫宇航员, # 必填
aspect_ratio: 1:1, # auto|21:9|16:9|3:2|4:3|5:4|1:1|4:5|3:4|2:3|9:16
resolution: 1K, # 1K|2K|4K
output_format: png, # jpeg|png|webp
safety_tolerance: 4 # 1(严格)到 6(宽松)
}
fal-ai/nano-banana-pro/edit(图像 → 图像)
Gemini 3 Pro 用于图像编辑。速度较慢(约 20 秒),但能很好地处理复杂编辑。
python
input_data = {
prompt: 转换为动漫风格, # 必填
imageurls: [imagedata_uri], # 必填 - URL 或 base64 数据 URI 数组
aspect_ratio: auto,
resolution: 1K,
output_format: png
}
fal-ai/flux/dev/image-to-image(图像 → 图像)
FLUX.1 dev 模型。风格迁移速度更快(约 2-3 秒)。
python
input_data = {
prompt: 动漫风格肖像, # 必填
imageurl: imagedata_uri, # 必填 - 单个 URL 或 base64 数据 URI
strength: 0.85, # 0-1,值越大变化越大
numinferencesteps: 40,
guidance_scale: 7.5,
output_format: png
}
fal-ai/kling-video/o3/pro/video-to-video/edit(视频 → 视频)
Kling O3 Pro 用于带 AI 特效的视频转换。
限制:
- - 格式:仅 .mp4、.mov
- 时长:3-10 秒
- 分辨率:720-2160px
- 最大文件大小:200MB
- 最大元素数:总共 4 个(元素 + 参考图像合计)
python
input_data = {
# 必填
prompt: 将环境改为完全被 @Image1 覆盖的雪地。用 @Element1 替换动物,
video_url: https://example.com/video.mp4, # .mp4/.mov,3-10秒,720-2160px,最大200MB
# 可选
image_urls: [ # 风格/外观参考
https://example.com/snow_ref.jpg # 在提示词中用作 @Image1、@Image2
],
keep_audio: True, # 保留原始音频(默认:true)
elements: [ # 要注入的角色/物体
{
referenceimageurls: [ # 元素的参考图像
https://example.com/element_ref1.png
],
frontalimageurl: https://example.com/element_front.png # 正面视图(效果更好)
}
], # 在提示词中用作 @Element1、@Element2
shot_type: customize # 多镜头类型(默认:customize)
}
提示词引用:
- - @Video1 — 输入视频
- @Image1、@Image2 — 风格/外观的参考图像
- @Element1、@Element2 — 要注入的元素(角色/物体)
输入验证
该技能在提交前验证输入。对于多输入模型,确保提供所有必填字段:
bash
检查模型需要什么
python3 scripts/fal_client.py model-info fal-ai/kling-video/o3/standard/video-to-video/edit
列出所有模型及其要求
python3 scripts/fal_client.py models
提交前,请验证:
- - ✅ 所有 required 字段都存在且非空
- ✅ 文件字段(imageurl、videourl 等)是 URL 或 base64 数据 URI
- ✅ 数组(image_urls)至少有一个项目
- ✅ 视频文件在限制范围内(200MB,720-2160p)
验证输出示例:
⚠️ 注意:在提示词中将参考视频引用为 @Video1
⚠️ 注意:最多 4 个元素(视频 + 图像合计)
❌ 验证失败:
- 缺少必填字段:video_url
使用方法
CLI 命令
bash
检查 API 密钥
python3 scripts/fal_client.py check-key
提交请求
python3 scripts/fal_client.py submit fal-ai/nano-banana-pro {prompt: 山上的日落}
检查状态
python3 scripts/fal
client.py status fal-ai/nano-banana-pro id>
获取结果
python3 scripts/falclient.py result fal-ai/nano-banana-pro id>
轮询所有待处理请求
python3 scripts/fal_client.py poll
列出待处理请求
python3 scripts/fal_client.py list
将本地图像转换为 base64 数据 URI
python3 scripts/fal_client.py to-data-uri /path/to/image.jpg
将本地视频转换为 base64 数据 URI(带验证)
python3 scripts/fal_client.py video-to-uri /path/to/video.mp4
Python 使用
python
import sys
sys.path.insert(0, scripts)
from falclient import submit, checkstatus, getresult, imagetodatauri, poll_pending
文本到图像
result = submit(fal-ai/nano-banana-pro, {
prompt: 未来城市夜景
})
print(result[request_id])
图像到图像(使用本地文件)
imguri = imagetodatauri(/path/to/photo.jpg)
result = submit(fal-ai/nano-banana-pro/edit, {
prompt: 转换为水彩画风格,
imageurls: [imguri]
})
轮询直到完成
completed = poll_pending()
for req in completed:
if result in req:
print(req[result][images][0][url])
队列系统
fal.ai 使用异步队列。请求经历以下阶段:
PROGRESS → 生成中COMPLETED → 完成,获取结果FAILED → 发生错误
待处理请求保存到 ~/.openclaw/workspace/fal-pending.json,重启后仍然存在。
轮询策略
手动: 定期运行 python3 scripts/fal_client.py poll。
心跳: 添加到 HEARTBEAT.md:
markdown
定时任务: 每隔几分钟安排轮询以处理后台任务。
添加新模型
- 1. 在 fal.ai 上找到模型并查看其 /api 页面
- 将条目添加到 references/models.json,包含输入/输出模式
- 用简单请求进行测试
注意: 队列 URL 使用基础模型路径(例如 fal-ai/flux 而不是 fal-ai/flux/dev/image-to-image)。脚本会自动处理。
文件
skills/fal-ai/
├── SKILL.md ← 本文件
├── scripts/
│ └── fal_client.py ← CLI + Python 库
└── references/
└── models.json ← 模型模式
故障排除
未找到 FALKEY → 将密钥添加到 TOOLS.md 或设置 FAL
KEY 环境变量
405 方法不允许 → URL 路由问题,确保使用基础模型路径进行状态/结果查询
请求卡住 → 检查 fal-pending.json,可能需要手动清理