Skip to content

非公式本サイトは非公式の日本語ドキュメントであり、Cloudflare 公式サイトではありません。最新情報はdevelopers.cloudflare.comをご確認ください。

Fal AI

最終更新 Markdown で表示Agent セットアップ

Fal AI は、単一の統一 API で 600 以上の本番向け生成メディアモデルにアクセスできます。オープンな画像、動画、音声、オーディオ生成モデルを世界最大規模でそろえており、1 行のコードで利用できます。

エンドポイント

https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/fal

URL の構成

Fal AI にリクエストを送るときは、いま使っている URL の https://fal.runhttps://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/fal に置き換えます。

前提条件

Fal AI にリクエストを送るときは、次を用意してください。

  • AI Gateway の Account ID。
  • AI Gateway のゲートウェイ名。
  • 有効な Fal AI API トークン。
  • 使う Fal AI モデルの名前。

デフォルトの同期 API

デフォルトでは、Fal AI エンドポイントへのリクエストは https://fal.run/<path> の同期 API に送られます。

cURL の例

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

別のターゲット URL に送りたい場合は、x-fal-target-url ヘッダーに Fal のターゲット URL 全体を指定します。

カスタムターゲット URL を使う cURL の例

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"
    ]
  }'

WebSocket API

Fal AI は WebSockets によるリアルタイム連携にも対応しています。WebSocket 接続と例は、Realtime WebSockets API のドキュメント を参照してください。

JavaScript SDK 連携

x-fal-target-url の形式は Fal SDK に準拠しているため、SDK の proxyUrl に AI Gateway を渡せます。

JavaScript SDK の例

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]);

役に立ちましたか?