fal is a generative media platform. It hosts image, video, and audio models behind one API and focuses on fast inference, so apps can generate media while the user waits.
How does the integration work?
The Generate with fal.ai function template turns a text prompt into an image. It sends the prompt to fal's fal-ai/fast-sdxl model and returns the URL of the generated image, which fal hosts. Your API key stays in the function, so your app can call the function directly without exposing it.
| Route | Purpose |
|---|---|
GET / | Serves a demo form for trying prompts |
POST / | Generates an image from the prompt in the JSON body and returns {"ok": true, "src": "<IMAGE_URL>"} |
Prerequisites
- A fal account with billing set up. fal charges for each request.
How to implement
To implement the fal.ai integration, there are several steps you must complete:
Step 1: Create a fal API key
Open the API keys page in the fal dashboard and click Create Key. Give it a name and copy the key. fal shows it only once.
Step 2: Create the Appwrite Function
For this step, you must create an account on Appwrite Cloud or self-host Appwrite if you haven't already. If you self-host Appwrite, enable a Node.js runtime in _APP_FUNCTIONS_RUNTIMES and follow the Functions configuration guide so function domains work.
In the Appwrite Console, go to Functions, open the Templates tab, search for Generate with fal.ai, and click Create from template. Under Template variables, set FAL_API_KEY to your fal key.
Choose Connect your repository to clone the template into a Git repository you can edit later, for example to try another fal model, or Connect later to deploy it right away. Then click Create and deploy.
Step 3: Generate an image
Copy the function's domain from the Domains tab and open it in your browser to use the demo form, or send a prompt:
curl -X POST https://<FUNCTION_DOMAIN> \ -H "Content-Type: application/json" \ -d '{"prompt": "city nightscape neon cyberpunk photorealistic"}'The response contains the image URL:
{ "ok": true, "src": "https://fal.media/files/..."}To keep generated images, download them from that URL and upload them to Appwrite Storage in your own code.
The template allows anyone to execute the function, so anyone who finds its domain can generate images with your fal key. Before you use it in a public app, replace Any in the function's execute access with narrower roles, such as Users, and call the function with an Appwrite SDK instead of its domain.
Read more about fal and Appwrite Functions
If you would like to learn more about fal and Appwrite Functions, we have some resources that you should visit:
