Skip to content

Commit b2f6a0b

Browse files
author
Rishit Bansal
committed
[AI Gateway] Add documentation for Fal AI
1 parent 763ce06 commit b2f6a0b

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
```

src/content/docs/ai-gateway/usage/websockets-api/realtime-api.mdx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Some AI providers support real-time, low-latency interactions over WebSockets. A
1313
- [Google AI Studio](https://ai.google.dev/gemini-api/docs/multimodal-live)
1414
- [Cartesia](https://docs.cartesia.ai/api-reference/tts/tts)
1515
- [ElevenLabs](https://elevenlabs.io/docs/conversational-ai/api-reference/conversational-ai/websocket)
16+
- [Fal AI](https://docs.fal.ai/model-apis/model-endpoints/websockets)
1617

1718
## Authentication
1819

@@ -21,6 +22,10 @@ For real-time WebSockets, authentication can be done using:
2122
- Headers (for non-browser environments)
2223
- `sec-websocket-protocol` (for browsers)
2324

25+
:::note
26+
Provider specific API Keys can also be alternatively configured on AI Gateway using our [BYOK](/ai-gateway/configuration/bring-your-own-keys) feature. You must still include the `cf-aig-authorization` header in the websocket request.
27+
:::
28+
2429
## Examples
2530

2631
### OpenAI
@@ -131,3 +136,30 @@ ws.send(
131136
}),
132137
);
133138
```
139+
140+
### Fal AI
141+
142+
Fal AI supports WebSocket connections for real-time model interactions through their HTTP over WebSocket API.
143+
144+
```javascript
145+
const ws = new WebSocket(
146+
"wss://gateway.ai.cloudflare.com/v1/<account_id>/<gateway>/fal/fal-ai/fast-lcm-diffusion",
147+
["fal-api-key.<fal_api_key>", "cf-aig-authorization.<cloudflare_token>"],
148+
);
149+
150+
ws.on("open", function open() {
151+
console.log("Connected to server.");
152+
});
153+
154+
ws.on("message", function incoming(message) {
155+
console.log(message.data);
156+
});
157+
158+
ws.send(
159+
JSON.stringify({
160+
prompt: "generate an image of a cat flying an aeroplane",
161+
}),
162+
);
163+
```
164+
165+
For more information on Fal AI's WebSocket API, see their [HTTP over WebSocket documentation](https://docs.fal.ai/model-apis/model-endpoints/websockets).

src/content/release-notes/ai-gateway.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ link: "/ai-gateway/changelog/"
33
productName: AI Gateway
44
productLink: "/ai-gateway/"
55
entries:
6+
- publish_date: "2025-09-22"
7+
title: Fal AI provider
8+
description: |-
9+
Added [Fal AI](/ai-gateway/usage/providers/fal/) as a new provider with support for 600+ generative media models. Fal AI integration includes:
10+
- Standard REST API support for image, video, voice, and audio generation models
11+
- WebSocket support for real-time model interactions
12+
- Custom target URL routing with the `x-fal-target-url` header
13+
- SDK integration through proxy URL configuration
614
- publish_date: "2025-08-25"
715
title: Dynamic routing
816
description: |-

0 commit comments

Comments
 (0)