| 
 | 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 | +## JavaScript SDK integration  | 
 | 65 | + | 
 | 66 | +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.  | 
 | 67 | + | 
 | 68 | +### JavaScript SDK example  | 
 | 69 | + | 
 | 70 | +```js  | 
 | 71 | +import { fal } from "@fal-ai/client";  | 
 | 72 | + | 
 | 73 | +fal.config({  | 
 | 74 | +  credentials: "{fal_ai_token}",  | 
 | 75 | +  proxyUrl: "https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/fal"  | 
 | 76 | +});  | 
 | 77 | + | 
 | 78 | +const result = await fal.subscribe("fal-ai/bytedance/seedream/v4/edit", {  | 
 | 79 | +  "input": {  | 
 | 80 | +    "prompt": "Dress the model in the clothes and hat. Add a cat to the scene and change the background to a Victorian era building.",  | 
 | 81 | +    "image_urls": [  | 
 | 82 | +      "https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_1.png",  | 
 | 83 | +      "https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_2.png",  | 
 | 84 | +      "https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_3.png",  | 
 | 85 | +      "https://storage.googleapis.com/falserverless/example_inputs/seedream4_edit_input_4.png"  | 
 | 86 | +    ]  | 
 | 87 | +  }  | 
 | 88 | +});  | 
 | 89 | + | 
 | 90 | +console.log(result.data.images[0]);  | 
 | 91 | +```  | 
0 commit comments