@ai-sdk/fal 2.0.10 → 2.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/docs/10-fal.mdx +320 -0
- package/package.json +6 -2
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -764,7 +764,7 @@ var falSpeechResponseSchema = import_v45.z.object({
|
|
|
764
764
|
});
|
|
765
765
|
|
|
766
766
|
// src/version.ts
|
|
767
|
-
var VERSION = true ? "2.0.
|
|
767
|
+
var VERSION = true ? "2.0.11" : "0.0.0-test";
|
|
768
768
|
|
|
769
769
|
// src/fal-provider.ts
|
|
770
770
|
var defaultBaseURL = "https://fal.run";
|
package/dist/index.mjs
CHANGED
package/docs/10-fal.mdx
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Fal
|
|
3
|
+
description: Learn how to use Fal AI models with the AI SDK.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Fal Provider
|
|
7
|
+
|
|
8
|
+
[Fal AI](https://fal.ai/) provides a generative media platform for developers with lightning-fast inference capabilities. Their platform offers optimized performance for running diffusion models, with speeds up to 4x faster than alternatives.
|
|
9
|
+
|
|
10
|
+
## Setup
|
|
11
|
+
|
|
12
|
+
The Fal provider is available via the `@ai-sdk/fal` module. You can install it with
|
|
13
|
+
|
|
14
|
+
<Tabs items={['pnpm', 'npm', 'yarn', 'bun']}>
|
|
15
|
+
<Tab>
|
|
16
|
+
<Snippet text="pnpm add @ai-sdk/fal" dark />
|
|
17
|
+
</Tab>
|
|
18
|
+
<Tab>
|
|
19
|
+
<Snippet text="npm install @ai-sdk/fal" dark />
|
|
20
|
+
</Tab>
|
|
21
|
+
<Tab>
|
|
22
|
+
<Snippet text="yarn add @ai-sdk/fal" dark />
|
|
23
|
+
</Tab>
|
|
24
|
+
|
|
25
|
+
<Tab>
|
|
26
|
+
<Snippet text="bun add @ai-sdk/fal" dark />
|
|
27
|
+
</Tab>
|
|
28
|
+
</Tabs>
|
|
29
|
+
|
|
30
|
+
## Provider Instance
|
|
31
|
+
|
|
32
|
+
You can import the default provider instance `fal` from `@ai-sdk/fal`:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { fal } from '@ai-sdk/fal';
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
If you need a customized setup, you can import `createFal` and create a provider instance with your settings:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { createFal } from '@ai-sdk/fal';
|
|
42
|
+
|
|
43
|
+
const fal = createFal({
|
|
44
|
+
apiKey: 'your-api-key', // optional, defaults to FAL_API_KEY environment variable, falling back to FAL_KEY
|
|
45
|
+
baseURL: 'custom-url', // optional
|
|
46
|
+
headers: {
|
|
47
|
+
/* custom headers */
|
|
48
|
+
}, // optional
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
You can use the following optional settings to customize the Fal provider instance:
|
|
53
|
+
|
|
54
|
+
- **baseURL** _string_
|
|
55
|
+
|
|
56
|
+
Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
57
|
+
The default prefix is `https://fal.run`.
|
|
58
|
+
|
|
59
|
+
- **apiKey** _string_
|
|
60
|
+
|
|
61
|
+
API key that is being sent using the `Authorization` header.
|
|
62
|
+
It defaults to the `FAL_API_KEY` environment variable, falling back to `FAL_KEY`.
|
|
63
|
+
|
|
64
|
+
- **headers** _Record<string,string>_
|
|
65
|
+
|
|
66
|
+
Custom headers to include in the requests.
|
|
67
|
+
|
|
68
|
+
- **fetch** _(input: RequestInfo, init?: RequestInit) => Promise<Response>_
|
|
69
|
+
|
|
70
|
+
Custom [fetch](https://developer.mozilla.org/en-US/docs/Web/API/fetch) implementation.
|
|
71
|
+
You can use it as a middleware to intercept requests,
|
|
72
|
+
or to provide a custom fetch implementation for e.g. testing.
|
|
73
|
+
|
|
74
|
+
## Image Models
|
|
75
|
+
|
|
76
|
+
You can create Fal image models using the `.image()` factory method.
|
|
77
|
+
For more on image generation with the AI SDK see [generateImage()](/docs/reference/ai-sdk-core/generate-image).
|
|
78
|
+
|
|
79
|
+
### Basic Usage
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import { fal } from '@ai-sdk/fal';
|
|
83
|
+
import { generateImage } from 'ai';
|
|
84
|
+
import fs from 'fs';
|
|
85
|
+
|
|
86
|
+
const { image, providerMetadata } = await generateImage({
|
|
87
|
+
model: fal.image('fal-ai/flux/dev'),
|
|
88
|
+
prompt: 'A serene mountain landscape at sunset',
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const filename = `image-${Date.now()}.png`;
|
|
92
|
+
fs.writeFileSync(filename, image.uint8Array);
|
|
93
|
+
console.log(`Image saved to ${filename}`);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Fal image models may return additional information for the images and the request.
|
|
97
|
+
|
|
98
|
+
Here are some examples of properties that may be set for each image
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
providerMetadata.fal.images[0].nsfw; // boolean, image is not safe for work
|
|
102
|
+
providerMetadata.fal.images[0].width; // number, image width
|
|
103
|
+
providerMetadata.fal.images[0].height; // number, image height
|
|
104
|
+
providerMetadata.fal.images[0].content_type; // string, mime type of the image
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Model Capabilities
|
|
108
|
+
|
|
109
|
+
Fal offers many models optimized for different use cases. Here are a few popular examples. For a full list of models, see the [Fal AI Search Page](https://fal.ai/explore/search).
|
|
110
|
+
|
|
111
|
+
| Model | Description |
|
|
112
|
+
| ---------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
|
|
113
|
+
| `fal-ai/flux/dev` | FLUX.1 [dev] model for high-quality image generation |
|
|
114
|
+
| `fal-ai/flux-pro/kontext` | FLUX.1 Kontext [pro] handles both text and reference images as inputs, enabling targeted edits and complex transformations |
|
|
115
|
+
| `fal-ai/flux-pro/kontext/max` | FLUX.1 Kontext [max] with improved prompt adherence and typography generation |
|
|
116
|
+
| `fal-ai/flux-lora` | Super fast endpoint for FLUX.1 with LoRA support |
|
|
117
|
+
| `fal-ai/ideogram/character` | Generate consistent character appearances across multiple images. Maintain facial features, proportions, and distinctive traits |
|
|
118
|
+
| `fal-ai/qwen-image` | Qwen-Image foundation model with significant advances in complex text rendering and precise image editing |
|
|
119
|
+
| `fal-ai/omnigen-v2` | Unified image generation model for Image Editing, Personalized Image Generation, Virtual Try-On, Multi Person Generation and more |
|
|
120
|
+
| `fal-ai/bytedance/dreamina/v3.1/text-to-image` | Dreamina showcases superior picture effects with improvements in aesthetics, precise and diverse styles, and rich details |
|
|
121
|
+
| `fal-ai/recraft/v3/text-to-image` | SOTA in image generation with vector art and brand style capabilities |
|
|
122
|
+
| `fal-ai/wan/v2.2-a14b/text-to-image` | High-resolution, photorealistic images with fine-grained detail |
|
|
123
|
+
|
|
124
|
+
Fal models support the following aspect ratios:
|
|
125
|
+
|
|
126
|
+
- 1:1 (square HD)
|
|
127
|
+
- 16:9 (landscape)
|
|
128
|
+
- 9:16 (portrait)
|
|
129
|
+
- 4:3 (landscape)
|
|
130
|
+
- 3:4 (portrait)
|
|
131
|
+
- 16:10 (1280x800)
|
|
132
|
+
- 10:16 (800x1280)
|
|
133
|
+
- 21:9 (2560x1080)
|
|
134
|
+
- 9:21 (1080x2560)
|
|
135
|
+
|
|
136
|
+
Key features of Fal models include:
|
|
137
|
+
|
|
138
|
+
- Up to 4x faster inference speeds compared to alternatives
|
|
139
|
+
- Optimized by the Fal Inference Engine™
|
|
140
|
+
- Support for real-time infrastructure
|
|
141
|
+
- Cost-effective scaling with pay-per-use pricing
|
|
142
|
+
- LoRA training capabilities for model personalization
|
|
143
|
+
|
|
144
|
+
#### Modify Image
|
|
145
|
+
|
|
146
|
+
Transform existing images using text prompts.
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
await generateImage({
|
|
150
|
+
model: fal.image('fal-ai/flux-pro/kontext/max'),
|
|
151
|
+
prompt: {
|
|
152
|
+
text: 'Put a donut next to the flour.',
|
|
153
|
+
images: [
|
|
154
|
+
'https://v3.fal.media/files/rabbit/rmgBxhwGYb2d3pl3x9sKf_output.png',
|
|
155
|
+
],
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Images can also be passed as base64-encoded string, a `Uint8Array`, an `ArrayBuffer`, or a `Buffer`.
|
|
161
|
+
A mask can be passed as well
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
await generateImage({
|
|
165
|
+
model: fal.image('fal-ai/flux-pro/kontext/max'),
|
|
166
|
+
prompt: {
|
|
167
|
+
text: 'Put a donut next to the flour.',
|
|
168
|
+
images: [imageBuffer],
|
|
169
|
+
mask: maskBuffer,
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Provider Options
|
|
175
|
+
|
|
176
|
+
Fal image models support flexible provider options through the `providerOptions.fal` object. You can pass any parameters supported by the specific Fal model's API. Common options include:
|
|
177
|
+
|
|
178
|
+
- **imageUrl** - Reference image URL for image-to-image generation
|
|
179
|
+
- **strength** - Controls how much the output differs from the input image
|
|
180
|
+
- **guidanceScale** - Controls adherence to the prompt (range: 1-20)
|
|
181
|
+
- **numInferenceSteps** - Number of denoising steps (range: 1-50)
|
|
182
|
+
- **enableSafetyChecker** - Enable/disable safety filtering
|
|
183
|
+
- **outputFormat** - Output format: 'jpeg' or 'png'
|
|
184
|
+
- **syncMode** - Wait for completion before returning response
|
|
185
|
+
- **acceleration** - Speed of generation: 'none', 'regular', or 'high'
|
|
186
|
+
- **safetyTolerance** - Content safety filtering level (1-6, where 1 is strictest)
|
|
187
|
+
|
|
188
|
+
<Note type="warning">
|
|
189
|
+
**Deprecation Notice**: snake_case parameter names (e.g., `image_url`,
|
|
190
|
+
`guidance_scale`) are deprecated and will be removed in `@ai-sdk/fal` v2.0.
|
|
191
|
+
Please use camelCase names (e.g., `imageUrl`, `guidanceScale`) instead.
|
|
192
|
+
</Note>
|
|
193
|
+
|
|
194
|
+
Refer to the [Fal AI model documentation](https://fal.ai/models) for model-specific parameters.
|
|
195
|
+
|
|
196
|
+
### Advanced Features
|
|
197
|
+
|
|
198
|
+
Fal's platform offers several advanced capabilities:
|
|
199
|
+
|
|
200
|
+
- **Private Model Inference**: Run your own diffusion transformer models with up to 50% faster inference
|
|
201
|
+
- **LoRA Training**: Train and personalize models in under 5 minutes
|
|
202
|
+
- **Real-time Infrastructure**: Enable new user experiences with fast inference times
|
|
203
|
+
- **Scalable Architecture**: Scale to thousands of GPUs when needed
|
|
204
|
+
|
|
205
|
+
For more details about Fal's capabilities and features, visit the [Fal AI documentation](https://fal.ai/docs).
|
|
206
|
+
|
|
207
|
+
## Transcription Models
|
|
208
|
+
|
|
209
|
+
You can create models that call the [Fal transcription API](https://docs.fal.ai/guides/convert-speech-to-text)
|
|
210
|
+
using the `.transcription()` factory method.
|
|
211
|
+
|
|
212
|
+
The first argument is the model id without the `fal-ai/` prefix e.g. `wizper`.
|
|
213
|
+
|
|
214
|
+
```ts
|
|
215
|
+
const model = fal.transcription('wizper');
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
You can also pass additional provider-specific options using the `providerOptions` argument. For example, supplying the `batchSize` option will increase the number of audio chunks processed in parallel.
|
|
219
|
+
|
|
220
|
+
```ts highlight="6"
|
|
221
|
+
import { experimental_transcribe as transcribe } from 'ai';
|
|
222
|
+
import { fal } from '@ai-sdk/fal';
|
|
223
|
+
import { readFile } from 'fs/promises';
|
|
224
|
+
|
|
225
|
+
const result = await transcribe({
|
|
226
|
+
model: fal.transcription('wizper'),
|
|
227
|
+
audio: await readFile('audio.mp3'),
|
|
228
|
+
providerOptions: { fal: { batchSize: 10 } },
|
|
229
|
+
});
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
The following provider options are available:
|
|
233
|
+
|
|
234
|
+
- **language** _string_
|
|
235
|
+
Language of the audio file. If set to null, the language will be automatically detected.
|
|
236
|
+
Accepts ISO language codes like 'en', 'fr', 'zh', etc.
|
|
237
|
+
Optional.
|
|
238
|
+
|
|
239
|
+
- **diarize** _boolean_
|
|
240
|
+
Whether to diarize the audio file (identify different speakers).
|
|
241
|
+
Defaults to true.
|
|
242
|
+
Optional.
|
|
243
|
+
|
|
244
|
+
- **chunkLevel** _string_
|
|
245
|
+
Level of the chunks to return. Either 'segment' or 'word'.
|
|
246
|
+
Default value: "segment"
|
|
247
|
+
Optional.
|
|
248
|
+
|
|
249
|
+
- **version** _string_
|
|
250
|
+
Version of the model to use. All models are Whisper large variants.
|
|
251
|
+
Default value: "3"
|
|
252
|
+
Optional.
|
|
253
|
+
|
|
254
|
+
- **batchSize** _number_
|
|
255
|
+
Batch size for processing.
|
|
256
|
+
Default value: 64
|
|
257
|
+
Optional.
|
|
258
|
+
|
|
259
|
+
- **numSpeakers** _number_
|
|
260
|
+
Number of speakers in the audio file. If not provided, the number of speakers will be automatically detected.
|
|
261
|
+
Optional.
|
|
262
|
+
|
|
263
|
+
### Model Capabilities
|
|
264
|
+
|
|
265
|
+
| Model | Transcription | Duration | Segments | Language |
|
|
266
|
+
| --------- | ------------------- | ------------------- | ------------------- | ------------------- |
|
|
267
|
+
| `whisper` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
268
|
+
| `wizper` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
269
|
+
|
|
270
|
+
## Speech Models
|
|
271
|
+
|
|
272
|
+
You can create models that call Fal text-to-speech endpoints using the `.speech()` factory method.
|
|
273
|
+
|
|
274
|
+
### Basic Usage
|
|
275
|
+
|
|
276
|
+
```ts
|
|
277
|
+
import { experimental_generateSpeech as generateSpeech } from 'ai';
|
|
278
|
+
import { fal } from '@ai-sdk/fal';
|
|
279
|
+
|
|
280
|
+
const result = await generateSpeech({
|
|
281
|
+
model: fal.speech('fal-ai/minimax/speech-02-hd'),
|
|
282
|
+
text: 'Hello from the AI SDK!',
|
|
283
|
+
});
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Model Capabilities
|
|
287
|
+
|
|
288
|
+
| Model | Description |
|
|
289
|
+
| ----------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
290
|
+
| `fal-ai/minimax/voice-clone` | Clone a voice from a sample audio and generate speech from text prompts |
|
|
291
|
+
| `fal-ai/minimax/voice-design` | Design a personalized voice from a text description and generate speech from text prompts |
|
|
292
|
+
| `fal-ai/dia-tts/voice-clone` | Clone dialog voices from a sample audio and generate dialogs from text prompts |
|
|
293
|
+
| `fal-ai/minimax/speech-02-hd` | Generate speech from text prompts and different voices |
|
|
294
|
+
| `fal-ai/minimax/speech-02-turbo` | Generate fast speech from text prompts and different voices |
|
|
295
|
+
| `fal-ai/dia-tts` | Directly generates realistic dialogue from transcripts with audio conditioning for emotion control. Produces natural nonverbals like laughter and throat clearing |
|
|
296
|
+
| `resemble-ai/chatterboxhd/text-to-speech` | Generate expressive, natural speech with Resemble AI's Chatterbox. Features unique emotion control, instant voice cloning from short audio, and built-in watermarking |
|
|
297
|
+
|
|
298
|
+
### Provider Options
|
|
299
|
+
|
|
300
|
+
Pass provider-specific options via `providerOptions.fal` depending on the model:
|
|
301
|
+
|
|
302
|
+
- **voice_setting** _object_
|
|
303
|
+
|
|
304
|
+
- `voice_id` (string): predefined voice ID
|
|
305
|
+
- `speed` (number): 0.5–2.0
|
|
306
|
+
- `vol` (number): 0–10
|
|
307
|
+
- `pitch` (number): -12–12
|
|
308
|
+
- `emotion` (enum): happy | sad | angry | fearful | disgusted | surprised | neutral
|
|
309
|
+
- `english_normalization` (boolean)
|
|
310
|
+
|
|
311
|
+
- **audio_setting** _object_
|
|
312
|
+
Audio configuration settings specific to the model.
|
|
313
|
+
|
|
314
|
+
- **language_boost** _enum_
|
|
315
|
+
Chinese | Chinese,Yue | English | Arabic | Russian | Spanish | French | Portuguese | German | Turkish | Dutch | Ukrainian | Vietnamese | Indonesian | Japanese | Italian | Korean | Thai | Polish | Romanian | Greek | Czech | Finnish | Hindi | auto
|
|
316
|
+
|
|
317
|
+
- **pronunciation_dict** _object_
|
|
318
|
+
Custom pronunciation dictionary for specific words.
|
|
319
|
+
|
|
320
|
+
Model-specific parameters (e.g., `audio_url`, `prompt`, `preview_text`, `ref_audio_url`, `ref_text`) can be passed directly under `providerOptions.fal` and will be forwarded to the Fal API.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/fal",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.11",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -8,10 +8,14 @@
|
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist/**/*",
|
|
11
|
+
"docs/**/*",
|
|
11
12
|
"src",
|
|
12
13
|
"CHANGELOG.md",
|
|
13
14
|
"README.md"
|
|
14
15
|
],
|
|
16
|
+
"directories": {
|
|
17
|
+
"doc": "./docs"
|
|
18
|
+
},
|
|
15
19
|
"exports": {
|
|
16
20
|
"./package.json": "./package.json",
|
|
17
21
|
".": {
|
|
@@ -55,7 +59,7 @@
|
|
|
55
59
|
"scripts": {
|
|
56
60
|
"build": "pnpm clean && tsup --tsconfig tsconfig.build.json",
|
|
57
61
|
"build:watch": "pnpm clean && tsup --watch",
|
|
58
|
-
"clean": "del-cli dist *.tsbuildinfo",
|
|
62
|
+
"clean": "del-cli dist docs *.tsbuildinfo",
|
|
59
63
|
"lint": "eslint \"./**/*.ts*\"",
|
|
60
64
|
"type-check": "tsc --build",
|
|
61
65
|
"prettier-check": "prettier --check \"./**/*.ts*\"",
|