Fal AI ↗ 通过单一统一 API 提供对 600 多个生产就绪的生成式媒体模型的访问。该服务拥有全球最大的开放图像、视频、语音和音频生成模型集合,均可一行代码调用。
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/fal向 Fal AI 发送请求时,将当前使用的 URL 中的 https://fal.run 替换为 https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/fal。
向 Fal AI 发送请求时,请确保具备以下条件:
- 你的 AI Gateway Account ID。
- 你的 AI Gateway gateway 名称。
- 有效的 Fal AI API 令牌。
- 要使用的 Fal AI 模型名称。
默认情况下,发往 Fal AI 端点的请求会命中同步 API:https://fal.run/<path>。
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/fal/fal-ai/fast-sdxl \
--header 'Authorization: Key {fal_ai_token}' \
--header 'Content-Type: application/json' \
--data '{
"prompt": "Make an image of a cat flying an aeroplane"
}'如果需要访问不同的目标 URL,可以在 x-fal-target-url 标头中提供完整的 Fal 目标 URL。
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/fal \
--header 'Authorization: Bearer {fal_ai_token}' \
--header 'x-fal-target-url: https://queue.fal.run/fal-ai/bytedance/seedream/v4/edit' \
--header 'Content-Type: application/json' \
--data '{
"prompt": "Dress the model in the clothes and hat. Add a cat to the scene and change the background to a Victorian era building.",
"image_urls": [
"https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_1.png",
"https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_2.png",
"https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_3.png",
"https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_4.png"
]
}'Fal AI 也通过 WebSocket 支持实时交互。有关 WebSocket 连接和示例,请参阅 Realtime WebSockets API 文档。
x-fal-target-url 格式与 Fal SDK 兼容,因此可以轻松地将 AI Gateway 作为 SDK 中的 proxyUrl 传入。
import { fal } from "@fal-ai/client";
fal.config({
credentials: "{fal_ai_token}", // OR pass a cloudflare api token if using BYOK on AI Gateway
proxyUrl: "https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/fal"
});
const result = await fal.subscribe("fal-ai/bytedance/seedream/v4/edit", {
"input": {
"prompt": "Dress the model in the clothes and hat. Add a cat to the scene and change the background to a Victorian era building.",
"image_urls": [
"https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_1.png",
"https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_2.png",
"https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_3.png",
"https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_4.png"
]
}
});
console.log(result.data.images[0]);