Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

fal.md

551 lines19.3 KB

1---
2title: fal.ai
3id: fal-adapter
4description: "Generate images and videos with 600+ models on fal.ai using TanStack AI — Nano Banana Pro, FLUX, and more via the @tanstack/ai-fal adapter."
5keywords:
6 - tanstack ai
7 - fal.ai
8 - fal
9 - image generation
10 - video generation
11 - flux
12 - nano banana
13 - adapter
14---
15​
16The fal.ai adapter provides access to 600+ models on the fal.ai platform for image, video, live, audio, speech, and transcription. Unlike text-focused adapters, the fal adapter is **media-focused**. It supports `generateImage()`, `generateVideo()`, `generateLiveVideo()`, `generateAudio()`, `generateSpeech()`, and `generateTranscription()`. It does not support `chat()` or tools.
17​
18For a full working example, see the [fal.ai example app](https://github.com/TanStack/ai/tree/main/examples/ts-react-media).
19​
20## Installation
21​
22<!-- ::start:tabs variant="package-manager" mode="install" -->
23​
24react: @tanstack/ai-fal
25vue: @tanstack/ai-fal
26solid: @tanstack/ai-fal
27svelte: @tanstack/ai-fal
28preact: @tanstack/ai-fal
29angular: @tanstack/ai-fal
30vanilla: @tanstack/ai-fal
31octane: @tanstack/ai-fal
32​
33<!-- ::end:tabs -->
34​
35## Type Safety with String Literals
36​
37The fal adapter provides full type safety when you pass the model ID as a **string literal**. This gives you autocomplete for `size` and `modelOptions` specific to that model. Always use string literals — not variables — when creating adapters:
38​
39```typescript
40import { falImage } from "@tanstack/ai-fal";
41​
42// Good — full type safety and autocomplete
43const adapter = falImage("fal-ai/z-image/turbo");
44```
45​
46```typescript
47import { falImage } from "@tanstack/ai-fal";
48​
49// Bad — no type inference for model-specific options
50const modelId = "fal-ai/z-image/turbo";
51const adapter = falImage(modelId);
52```
53​
54You can also pass any string for new models that fal.ai hasn't provided types for yet — you just won't get type safety on those endpoints.
55​
56## Basic Usage
57​
58```typescript
59import { generateImage } from "@tanstack/ai";
60import { falImage } from "@tanstack/ai-fal";
61​
62const result = await generateImage({
63 adapter: falImage("fal-ai/flux/dev"),
64 prompt: "A futuristic cityscape at sunset",
65 numberOfImages: 1,
66});
67​
68console.log(result.images);
69```
70​
71## Basic Usage - Custom API Key
72​
73```typescript
74import { generateImage } from "@tanstack/ai";
75import { falImage } from "@tanstack/ai-fal";
76​
77const adapter = falImage("fal-ai/flux/dev", {
78 apiKey: process.env.FAL_KEY!,
79});
80​
81const result = await generateImage({
82 adapter,
83 prompt: "A futuristic cityscape at sunset",
84 numberOfImages: 1,
85});
86```
87​
88## Configuration
89​
90```typescript
91import { falImage, type FalClientConfig } from "@tanstack/ai-fal";
92​
93// Direct API key
94const adapter = falImage("fal-ai/flux/dev", {
95 apiKey: "your-api-key",
96});
97​
98// Using a proxy URL (for client-side usage)
99const proxiedAdapter = falImage("fal-ai/flux/dev", {
100 apiKey: "your-api-key",
101 proxyUrl: "https://your-server.com/api/fal/proxy",
102});
103```
104​
105## Example: Image Generation
106​
107From the [fal.ai example app](https://github.com/TanStack/ai/tree/main/examples/ts-react-media):
108​
109```typescript
110import { generateImage } from "@tanstack/ai";
111import { falImage } from "@tanstack/ai-fal";
112​
113// Use string literals for the model to get full type safety
114const result = await generateImage({
115 adapter: falImage("fal-ai/nano-banana-pro"),
116 prompt: "A futuristic cityscape at sunset",
117 numberOfImages: 1,
118 size: "16:9_4K",
119 modelOptions: {
120 output_format: "jpeg",
121 },
122});
123```
124​
125## Example: Image with Model Options
126​
127Each fal.ai model has its own type-safe options. The adapter uses fal.ai's types to provide autocomplete and type checking for model-specific parameters. There are 1000s of combinations. If you provide the proper model endpoint id as as string literal, you will then only be able to provide `size` and `modelOptions` that the model supports.
128​
129_IMPORTANT_: It is possible to pass strings and new endpoint ids that Fal has not provided types for. You just won't get type safety on those endpoints. You'll find this happens for very new models.
130​
131```typescript
132import { generateImage } from "@tanstack/ai";
133import { falImage } from "@tanstack/ai-fal";
134​
135// Model-specific options are type-safe
136const result = await generateImage({
137 adapter: falImage("fal-ai/z-image/turbo"),
138 prompt: "A serene mountain landscape",
139 numberOfImages: 1,
140 size: "landscape_16_9",
141 modelOptions: {
142 acceleration: "high",
143 enable_prompt_expansion: true,
144 },
145});
146```
147​
148## Image Size Options
149​
150The fal adapter supports a flexible `size` parameter that maps either to `image_size` or to `aspect_ratio` and `resolution` parameters:
151​
152| | `size` | Maps To |
153|--------|---------|---------|
154| named | `"landscape_16_9"` | `image_size: "landscape_16_9"` |
155| width x height (OpenAI) | `"1536x1024"` | | `image_size: "1536x1024"` |
156| aspect ratio & resolution | `"16:9_4K"` | `aspect_ratio: "16:9"`, `resolution: "4K"` |
157| aspect ratio only | `"16:9"` | `aspect_ratio: "16:9"` |
158​
159```typescript ignore
160// Aspect ratio only
161size: "16:9"
162​
163// Aspect ratio with resolution
164size: "16:9_4K"
165​
166// Named size (model-specific)
167size: "landscape_16_9"
168```
169​
170## Video Generation (Experimental)
171​
172> **Note:** Video generation is an experimental feature and may change in future releases.
173​
174Video generation uses a queue-based workflow: submit a job, poll for status, then retrieve the video URL when complete.
175​
176```typescript
177import { generateVideo, getVideoJobStatus } from "@tanstack/ai";
178import { falVideo } from "@tanstack/ai-fal";
179```
180​
181## Example: Text-to-Video
182​
183From the [fal.ai example app](https://github.com/TanStack/ai/tree/main/examples/ts-react-media):
184​
185```typescript
186import { generateVideo, getVideoJobStatus } from "@tanstack/ai";
187import { falVideo } from "@tanstack/ai-fal";
188​
189// 1. Submit the video generation job
190const adapter = falVideo("fal-ai/kling-video/v2.6/pro/text-to-video");
191​
192const job = await generateVideo({
193 adapter,
194 prompt: "A timelapse of a flower blooming",
195 size: "16:9",
196 duration: "5",
197});
198​
199// 2. Poll for status
200const status = await getVideoJobStatus({
201 adapter,
202 jobId: job.jobId,
203});
204​
205console.log(status.status); // "pending" | "processing" | "completed"
206```
207​
208## Example: Image-to-Video
209​
210```typescript
211import { generateVideo } from "@tanstack/ai";
212import { falVideo } from "@tanstack/ai-fal";
213​
214const job = await generateVideo({
215 adapter: falVideo("fal-ai/kling-video/v2.6/pro/image-to-video"),
216 prompt: "Animate this scene with gentle wind",
217 duration: "5",
218 modelOptions: {
219 start_image_url: "https://example.com/image.jpg",
220 generate_audio: true,
221 },
222});
223```
224​
225`duration` is typed per model from `@fal-ai/client`'s `EndpointTypeMap`. Popular models also implement `availableDurations()` / `snapDuration()` for UI sliders:
226​
227| Model | `duration` type | `availableDurations()` |
228| --- | --- | --- |
229| `fal-ai/kling-video/v1.6/{standard,pro}/text-to-video`, `fal-ai/kling-video/v2.6/pro/{text,image}-to-video` | `'5' \| '10'` | discrete |
230| `fal-ai/kling-video/v3/pro/{text,image}-to-video` | `'3'` … `'15'` | discrete |
231| `fal-ai/pika/v2.2/text-to-video` | `'5' \| '10'` | discrete |
232| `fal-ai/ltx-2.3/{text,image}-to-video` (+ `/fast`) | `'6' \| '8' \| '10'` | discrete |
233| `fal-ai/luma-dream-machine/ray-2` | `'5s' \| '9s'` | discrete |
234| `fal-ai/veo3.1`, `fal-ai/veo3.1/fast` (+ `/image-to-video`), `fal-ai/veo3` (+ `/image-to-video`) | `'4s' \| '6s' \| '8s'` | discrete |
235| `fal-ai/wan-25-preview/text-to-video` | `'2'` … `'15'` | discrete |
236| `fal-ai/minimax/video-01` | not accepted | `{ kind: 'none' }` |
237| `fal-ai/hunyuan-video-v1.5/text-to-video` | not accepted (`num_frames`) | `{ kind: 'none' }` |
238​
239```typescript
240import { generateVideo } from "@tanstack/ai";
241import { falVideo } from "@tanstack/ai-fal";
242​
243const adapter = falVideo("fal-ai/veo3.1");
244adapter.availableDurations(); // { kind: 'discrete', values: ['4s', '6s', '8s'] }
245adapter.snapDuration(7); // '6s'
246​
247await generateVideo({
248 adapter,
249 prompt: "A timelapse of a city skyline at dusk",
250 duration: adapter.snapDuration(7),
251});
252```
253​
254Uncurated models still type `duration` from the SDK when the endpoint declares the field, but `availableDurations()` returns `{ kind: 'none' }` until they are added to the runtime map.
255​
256## Text-to-Speech
257​
258Text-to-speech uses `falSpeech()` with the `generateSpeech()` activity. The adapter fetches the generated audio from fal's CDN and returns it as base64-encoded data to match the `TTSResult` contract.
259​
260```typescript
261import { generateSpeech } from "@tanstack/ai";
262import { falSpeech } from "@tanstack/ai-fal";
263​
264const result = await generateSpeech({
265 adapter: falSpeech("fal-ai/kokoro/american-english"),
266 text: "Hello from fal!",
267 voice: "af_heart",
268 speed: 1.0,
269});
270​
271// result.audio is a base64-encoded string
272console.log(result.format); // e.g. "wav"
273console.log(result.contentType); // e.g. "audio/wav"
274```
275​
276### Google Gemini 3.1 Flash TTS
277​
278Google's newest TTS model (`fal-ai/gemini-3.1-flash-tts`) supports 80+ languages and introduces **granular audio tags** for expressive control — you can embed speaker tags and style cues directly in the text.
279​
280```typescript
281import { generateSpeech } from "@tanstack/ai";
282import { falSpeech } from "@tanstack/ai-fal";
283​
284const result = await generateSpeech({
285 adapter: falSpeech("fal-ai/gemini-3.1-flash-tts"),
286 text: "[warm, enthusiastic] Welcome to TanStack AI! [pause] Let's build something great.",
287 voice: "Kore",
288});
289```
290​
291> **Note:** This model is newer than `@fal-ai/client@1.9.1`'s type map, so `modelOptions` won't autocomplete. The call still works — the fal adapter accepts any model ID as a string. Type-safe autocomplete will land when fal's SDK types catch up.
292​
293### ElevenLabs v3
294​
295```typescript
296import { generateSpeech } from "@tanstack/ai";
297import { falSpeech } from "@tanstack/ai-fal";
298​
299const result = await generateSpeech({
300 adapter: falSpeech("fal-ai/elevenlabs/tts/eleven-v3"),
301 text: "Welcome to TanStack AI.",
302 modelOptions: {
303 voice: "Rachel",
304 stability: 0.5,
305 },
306});
307```
308​
309## Transcription
310​
311Speech-to-text uses `falTranscription()` with the `generateTranscription()` activity. The `audio` input accepts a URL string, `Blob`, `File`, or `ArrayBuffer` — `ArrayBuffer` is automatically wrapped in a `Blob` for upload.
312​
313```typescript
314import { generateTranscription } from "@tanstack/ai";
315import { falTranscription } from "@tanstack/ai-fal";
316​
317const result = await generateTranscription({
318 adapter: falTranscription("fal-ai/whisper"),
319 audio: "https://example.com/recording.mp3",
320 language: "en",
321});
322​
323console.log(result.text);
324console.log(result.language);
325​
326// When the model returns word/segment timestamps, they're mapped to result.segments
327for (const segment of result.segments ?? []) {
328 console.log(`[${segment.start}s → ${segment.end}s] ${segment.text}`);
330```
331​
332## Audio Generation (Music & Sound Effects)
333​
334Music and sound-effect generation uses `falAudio()` with the `generateAudio()` activity. Unlike TTS, the result is returned as a URL in `result.audio.url` (you can fetch it yourself if you need raw bytes).
335​
336```typescript
337import { generateAudio } from "@tanstack/ai";
338import { falAudio } from "@tanstack/ai-fal";
339​
340// Music generation with MiniMax Music 2.6 (latest)
341const music = await generateAudio({
342 adapter: falAudio("fal-ai/minimax-music/v2.6"),
343 prompt: "City Pop, 80s retro, groovy synth bass, warm female vocal, 104 BPM, nostalgic urban night",
344});
345​
346console.log(music.audio.url);
347```
348​
349```typescript
350import { generateAudio } from "@tanstack/ai";
351import { falAudio } from "@tanstack/ai-fal";
352​
353// DiffRhythm with explicit lyrics
354const lyrical = await generateAudio({
355 adapter: falAudio("fal-ai/diffrhythm"),
356 prompt: "An upbeat electronic track with synths",
357 modelOptions: {
358 lyrics: "[verse]\nHello world\n[chorus]\nLa la la",
359 },
360});
361```
362​
363```typescript
364import { generateAudio } from "@tanstack/ai";
365import { falAudio } from "@tanstack/ai-fal";
366​
367// Sound effects
368const sfx = await generateAudio({
369 adapter: falAudio("fal-ai/elevenlabs/sound-effects/v2"),
370 prompt: "Thunderclap with rain",
371 duration: 5,
372});
373```
374​
375## Popular Models
376​
377### Image Models
378​
379| Model | Description |
380|-------|-------------|
381| `fal-ai/nano-banana-pro` | Fast, high-quality image generation (4K) |
382| `fal-ai/flux-2/klein/9b` | Enhanced realism, crisp text generation |
383| `fal-ai/z-image/turbo` | Super fast 6B parameter model |
384| `xai/grok-imagine-image` | xAI highly aesthetic images with prompt enhancement |
385​
386### Video Models
387​
388| Model | Mode | Description |
389|-------|------|-------------|
390| `fal-ai/kling-video/v2.6/pro/text-to-video` | Text-to-Video | High-quality text-to-video |
391| `fal-ai/kling-video/v2.6/pro/image-to-video` | Image-to-Video | Animate images with Kling |
392| `fal-ai/veo3.1` | Text-to-Video | Google Veo text-to-video |
393| `fal-ai/veo3.1/image-to-video` | Image-to-Video | Google Veo image-to-video |
394| `xai/grok-imagine-video/text-to-video` | Text-to-Video | xAI video from text |
395| `xai/grok-imagine-video/image-to-video` | Image-to-Video | xAI animate images to video |
396| `fal-ai/ltx-2/text-to-video/fast` | Text-to-Video | Fast text-to-video |
397| `fal-ai/ltx-2/image-to-video/fast` | Image-to-Video | Fast image-to-video animation |
398​
399### Live Models
400​
401| Model | Mode | Description |
402|-------|------|-------------|
403| `minimax/h3-max/director` | Live | Steerable live stream. Use `falLiveVideo()` with `generateLiveVideo()`. |
404​
405### Text-to-Speech Models
406​
407| Model | Description |
408|-------|-------------|
409| `fal-ai/gemini-3.1-flash-tts` | **New** — Google's flagship TTS with 80+ languages and expressive audio tags |
410| `fal-ai/elevenlabs/tts/eleven-v3` | ElevenLabs v3 expressive multi-voice TTS |
411| `fal-ai/elevenlabs/tts/turbo-v2.5` | Low-latency ElevenLabs TTS |
412| `fal-ai/minimax/speech-2.6-hd` | MiniMax HD speech synthesis |
413| `fal-ai/minimax/speech-2.6-turbo` | MiniMax low-latency variant |
414| `fal-ai/kokoro/american-english` | Kokoro multilingual TTS — also `british-english`, `french`, `spanish`, `italian`, `japanese`, `mandarin-chinese`, `hindi`, `brazilian-portuguese` |
415| `fal-ai/inworld-tts` | Inworld TTS-1.5 Max |
416| `fal-ai/chatterbox/text-to-speech/multilingual` | Chatterbox multilingual TTS |
417| `fal-ai/dia-tts` | Dia expressive dialogue TTS |
418| `fal-ai/orpheus-tts` | Orpheus open-source TTS |
419| `fal-ai/f5-tts` | F5-TTS voice cloning |
420| `fal-ai/vibevoice/7b` | VibeVoice 7B conversational TTS |
421​
422### Transcription Models
423​
424| Model | Description |
425|-------|-------------|
426| `fal-ai/whisper` | OpenAI Whisper on fal infra |
427| `fal-ai/wizper` | Faster-whisper variant with word-level timestamps |
428| `fal-ai/speech-to-text/turbo` | Turbo STT with diarization |
429| `fal-ai/elevenlabs/speech-to-text` | ElevenLabs STT |
430​
431### Audio / Music Models
432​
433| Model | Mode | Description |
434|-------|------|-------------|
435| `fal-ai/minimax-music/v2.6` | Music | **New** — MiniMax Music 2.6, full vocal + instrumental compositions from a prompt |
436| `fal-ai/minimax-music/v2.5` | Music | MiniMax Music 2.5 |
437| `fal-ai/minimax-music/v2` | Music | MiniMax Music v2 — supports `lyrics_prompt` |
438| `fal-ai/diffrhythm` | Music | DiffRhythm — prompt + lyrics |
439| `fal-ai/lyria2` | Music | Google Lyria 2 high-fidelity music |
440| `fal-ai/stable-audio-25/text-to-audio` | Music / Audio | Stability AI Stable Audio 2.5 |
441| `fal-ai/mmaudio-v2/text-to-audio` | Audio | MMAudio v2 text-to-audio |
442| `fal-ai/elevenlabs/sound-effects/v2` | SFX | ElevenLabs sound-effect generation |
443| `fal-ai/beatoven/sound-effect-generation` | SFX | Beatoven professional sound effects |
444| `fal-ai/thinksound` | Audio | Thinksound reasoning-based audio generation |
445​
446> **Very new models** (e.g. `gemini-3.1-flash-tts`, `minimax-music/v2.6`, `beatoven/sound-effect-generation`) may not yet appear in `@fal-ai/client`'s type map — they still work as plain string model IDs, you just won't get autocomplete for their `modelOptions`.
447​
448## Environment Variables
449​
450Create an API key at [fal.ai](https://fal.ai) and set it in your environment:
451​
452```bash
453FAL_KEY=your-fal-api-key
454```
455​
456## API Reference
457​
458### `falImage(model, config?)`
459​
460Creates a fal.ai image adapter using the `FAL_KEY` environment variable or an explicit config.
461​
462**Parameters:**
463​
464- `model` - The fal.ai model ID (e.g., `"fal-ai/flux/dev"`)
465- `config.apiKey?` - Your fal.ai API key (falls back to `FAL_KEY` env var)
466- `config.proxyUrl?` - Proxy URL for client-side usage
467​
468**Returns:** A `FalImageAdapter` instance for use with `generateImage()`.
469​
470### `falVideo(model, config?)`
471​
472Creates a fal.ai video adapter using the `FAL_KEY` environment variable or an explicit config.
473​
474**Parameters:**
475​
476- `model` - The fal.ai model ID (e.g., `"fal-ai/kling-video/v2.6/pro/text-to-video"`)
477- `config.apiKey?` - Your fal.ai API key (falls back to `FAL_KEY` env var)
478- `config.proxyUrl?` - Proxy URL for client-side usage
479​
480**Returns:** A `FalVideoAdapter` instance for use with `generateVideo()` and `getVideoJobStatus()`.
481​
482### `falLiveVideo(model, config?)`
483​
484Creates a fal.ai live-video adapter for H3 Max Director. `generateLiveVideo()` returns the WMA app id on `result.model` (`fal-ai/minimax-h3-max-director`). Open that id with `wma(live.model)` through a server proxy that attaches `FAL_KEY`. Do not send `live.token` as `Key` credentials. Call `allowedFalLiveVideoProxyTarget()` in the proxy so it forwards only WMA `/ice`, `/session`, `/session/heartbeat`, and Director `/ice`.
485​
486**Parameters:**
487​
488- `model` - `"minimax/h3-max/director"`
489- `config.apiKey?` - Your fal.ai API key (falls back to `FAL_KEY` env var)
490​
491**Returns:** A `FalLiveVideoAdapter` instance for use with `generateLiveVideo()`.
492​
493See [Live Generation](../media/live-generation) for the browser connect step.
494​
495### `falSpeech(model, config?)`
496​
497Creates a fal.ai text-to-speech adapter.
498​
499**Parameters:**
500​
501- `model` - The fal.ai TTS model ID (e.g., `"fal-ai/kokoro/american-english"`)
502- `config.apiKey?` - Your fal.ai API key (falls back to `FAL_KEY` env var)
503- `config.proxyUrl?` - Proxy URL for client-side usage
504​
505**Returns:** A `FalSpeechAdapter` instance for use with `generateSpeech()`. The adapter fetches the generated audio URL from fal and returns it as base64 in `result.audio`.
506​
507### `falTranscription(model, config?)`
508​
509Creates a fal.ai transcription (speech-to-text) adapter.
510​
511**Parameters:**
512​
513- `model` - The fal.ai STT model ID (e.g., `"fal-ai/whisper"`)
514- `config.apiKey?` - Your fal.ai API key (falls back to `FAL_KEY` env var)
515- `config.proxyUrl?` - Proxy URL for client-side usage
516​
517**Returns:** A `FalTranscriptionAdapter` instance for use with `generateTranscription()`.
518​
519### `falAudio(model, config?)`
520​
521Creates a fal.ai audio generation adapter (music and sound effects).
522​
523**Parameters:**
524​
525- `model` - The fal.ai audio model ID (e.g., `"fal-ai/diffrhythm"`, `"fal-ai/minimax-music/v2"`)
526- `config.apiKey?` - Your fal.ai API key (falls back to `FAL_KEY` env var)
527- `config.proxyUrl?` - Proxy URL for client-side usage
528​
529**Returns:** A `FalAudioAdapter` instance for use with `generateAudio()`. The result contains a URL at `result.audio.url`.
530​
531### `getFalApiKeyFromEnv()`
532​
533Reads the `FAL_KEY` environment variable. Throws if not set.
534​
535**Returns:** The API key string.
536​
537### `configureFalClient(config?)`
538​
539Configures the underlying `@fal-ai/client`. Called automatically by adapter constructors. Uses `proxyUrl` if provided, otherwise sets credentials from the API key.
540​
541## Limitations
542​
543- **No text/chat support** — Use OpenAI, Anthropic, Gemini, or another text adapter for `chat()`
544- **No tools support** — Tool definitions are not applicable to media generation
545- **No summarization** — Use a text adapter for `summarize()`
546- **Video is experimental** — The video generation API may change in future releases
547​
548## Next Steps
549​
550- [Getting Started](../getting-started/quick-start) - Learn the basics
551- [Other Adapters](./openai) - Explore other providers