|
| 1 | +--- |
| 2 | +title: Fal AI |
| 3 | +pcx_content_type: get-started |
| 4 | +--- |
| 5 | + |
| 6 | +[Fal AI](https://fal.ai/) provides access to 600+ production-ready generative media models through a single, unified API. The service offers the world's largest collection of open image, video, voice, and audio generation models, all accessible with one line of code. |
| 7 | + |
| 8 | +## Endpoint |
| 9 | + |
| 10 | +```txt |
| 11 | +https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/fal |
| 12 | +``` |
| 13 | + |
| 14 | +## URL structure |
| 15 | + |
| 16 | +When making requests to Fal AI, replace `https://fal.run` in the URL you're currently using with `https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/fal`. |
| 17 | + |
| 18 | +## Prerequisites |
| 19 | + |
| 20 | +When making requests to Fal AI, ensure you have the following: |
| 21 | + |
| 22 | +- Your AI Gateway Account ID. |
| 23 | +- Your AI Gateway gateway name. |
| 24 | +- An active Fal AI API token. |
| 25 | +- The name of the Fal AI model you want to use. |
| 26 | + |
| 27 | +## Default synchronous API |
| 28 | + |
| 29 | +By default, requests to the Fal AI endpoint will hit the synchronous API at `https://fal.run/<path>`. |
| 30 | + |
| 31 | +### cURL example |
| 32 | + |
| 33 | +```bash |
| 34 | +curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/fal/fal-ai/fast-sdxl \ |
| 35 | + --header 'Authorization: Key {fal_ai_token}' \ |
| 36 | + --header 'Content-Type: application/json' \ |
| 37 | + --data '{ |
| 38 | + "prompt": "Make an image of a cat flying an aeroplane" |
| 39 | + }' |
| 40 | +``` |
| 41 | + |
| 42 | +## Custom target URLs |
| 43 | + |
| 44 | +If you need to hit a different target URL, you can supply the entire Fal target URL in the `x-fal-target-url` header. |
| 45 | + |
| 46 | +### cURL example with custom target URL |
| 47 | + |
| 48 | +```bash |
| 49 | +curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/fal \ |
| 50 | + --header 'Authorization: Bearer {fal_ai_token}' \ |
| 51 | + --header 'x-fal-target-url: https://queue.fal.run/fal-ai/bytedance/seedream/v4/edit' \ |
| 52 | + --header 'Content-Type: application/json' \ |
| 53 | + --data '{ |
| 54 | + "prompt": "Dress the model in the clothes and hat. Add a cat to the scene and change the background to a Victorian era building.", |
| 55 | + "image_urls": [ |
| 56 | + "https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_1.png", |
| 57 | + "https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_2.png", |
| 58 | + "https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_3.png", |
| 59 | + "https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_4.png" |
| 60 | + ] |
| 61 | + }' |
| 62 | +``` |
| 63 | + |
| 64 | +## WebSocket API |
| 65 | + |
| 66 | +Fal AI also supports real-time interactions through WebSockets. For WebSocket connections and examples, see the [Realtime WebSockets API documentation](/ai-gateway/usage/websockets-api/realtime-api/#fal-ai). |
| 67 | + |
| 68 | +## JavaScript SDK integration |
| 69 | + |
| 70 | +The `x-fal-target-url` format is compliant with the Fal SDKs, so AI Gateway can be easily passed as a `proxyUrl` in the SDKs. |
| 71 | + |
| 72 | +### JavaScript SDK example |
| 73 | + |
| 74 | +```js |
| 75 | +import { fal } from "@fal-ai/client"; |
| 76 | + |
| 77 | +fal.config({ |
| 78 | + credentials: "{fal_ai_token}", // OR pass a cloudflare api token if using BYOK on AI Gateway |
| 79 | + proxyUrl: "https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/fal" |
| 80 | +}); |
| 81 | + |
| 82 | +const result = await fal.subscribe("fal-ai/bytedance/seedream/v4/edit", { |
| 83 | + "input": { |
| 84 | + "prompt": "Dress the model in the clothes and hat. Add a cat to the scene and change the background to a Victorian era building.", |
| 85 | + "image_urls": [ |
| 86 | + "https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_1.png", |
| 87 | + "https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_2.png", |
| 88 | + "https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_3.png", |
| 89 | + "https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_4.png" |
| 90 | + ] |
| 91 | + } |
| 92 | +}); |
| 93 | + |
| 94 | +console.log(result.data.images[0]); |
| 95 | +``` |
0 commit comments