Fal AI ↗ は、単一の統一 API で 600 以上の本番向け生成メディアモデルにアクセスできます。オープンな画像、動画、音声、オーディオ生成モデルを世界最大規模でそろえており、1 行のコードで利用できます。
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/falFal AI にリクエストを送るときは、いま使っている URL の https://fal.run を https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/fal に置き換えます。
Fal AI にリクエストを送るときは、次を用意してください。
- AI Gateway の Account ID。
- AI Gateway のゲートウェイ名。
- 有効な Fal AI API トークン。
- 使う Fal AI モデルの名前。
デフォルトでは、Fal AI エンドポイントへのリクエストは https://fal.run/<path> の同期 API に送られます。
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 は WebSockets によるリアルタイム連携にも対応しています。WebSocket 接続と例は、Realtime WebSockets API のドキュメント を参照してください。
x-fal-target-url の形式は Fal SDK に準拠しているため、SDK の proxyUrl に AI Gateway を渡せます。
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]);