INTEGRITY Dokumentace

Fal AI

Fal AI poskytuje přístup k více než 600 produkčně připraveným generativním mediálním modelům prostřednictvím jediného sjednoceného API. Služba nabízí největší světovou sbírku otevřených modelů pro generování obrázků, videa, hlasu a zvuku, ke kterým se dostanete jediným řádkem kódu.

Endpoint

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

Struktura URL

Při zasílání požadavků na Fal AI nahraďte https://fal.run v URL adrese, kterou aktuálně používáte s https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/fal.

Předpoklady

Při zasílání požadavků na Fal AI se ujistěte, že máte následující:

Výchozí synchronní API

Požadavky na endpoint Fal AI ve výchozím nastavení směřují na synchronní API na https://fal.run/<path>.

Příklad 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"
  }'

Vlastní cílové adresy URL

Pokud potřebujete přistupovat na jinou cílovou URL, můžete celou cílovou URL Fal zadat v x-fal-target-url hlavička.

Příklad cURL s vlastní cílovou URL adresou

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 také podporuje interakce v reálném čase prostřednictvím WebSockets. Příklady a informace o připojení přes WebSocket najdete v Dokumentace k Realtime WebSockets API.

Integrace SDK pro JavaScript

x-fal-target-url formát je v souladu s Fal SDKs, takže AI Gateway lze snadno předat jako proxyUrl v SDK.

Příklad SDK pro JavaScript

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