This documentation page is also available as an interactive notebook. You can launch the notebook in
Kaggle or Colab, or download it for use with an IDE or local Jupyter installation, by clicking one of the
above links.
Pixeltable’s fal.ai integration enables you to access fal.ai’s fast
inference models via the fal.ai API.
Prerequisites
Important notes
- fal.ai usage may incur costs based on your fal.ai plan.
- Be mindful of sensitive data and consider security measures when
integrating with external services.
First you’ll need to install required libraries and enter a fal.ai API
key.
Now let’s create a Pixeltable directory to hold the tables for our demo.
Connected to Pixeltable database at: postgresql+psycopg://postgres:@/pixeltable?host=/Users/pjlb/.pixeltable/pgdata
Created directory ‘fal_demo’.
<pixeltable.catalog.dir.Dir at 0x13c533650>
Text-to-image generation with FLUX Schnell
Let’s start by using fal.ai’s FLUX Schnell model, which is optimized for
fast image generation. We’ll create a table to store prompts and
generated images.
Created table ‘images’.
Added 0 column values with 0 errors in 0.01 s
No rows affected.
Now let’s insert some prompts and see the results:
Inserted 3 rows with 0 errors in 1.77 s (1.70 rows/s)
3 rows inserted.
Let’s examine the structure of the response:
We can see that fal.ai returns a JSON response with an images array.
Each image has a url field. Let’s extract and display the images:
Added 3 column values with 0 errors in 0.04 s (85.38 rows/s)
Advanced image generation with Fast SDXL
fal.ai also offers Fast SDXL, which provides more control over image
generation parameters. Let’s create a new table to explore these
capabilities.
Created table ‘sdxl_images’.
Added 0 column values with 0 errors in 0.01 s
Added 0 column values with 0 errors in 0.01 s
No rows affected.
Inserted 2 rows with 0 errors in 5.23 s (0.38 rows/s)
2 rows inserted.
Generating multiple images per prompt
You can also generate multiple variations of the same prompt in a single
request:
Created table ‘multi_images’.
Added 0 column values with 0 errors in 0.01 s
Added 0 column values with 0 errors in 0.01 s
Added 0 column values with 0 errors in 0.01 s
Added 0 column values with 0 errors in 0.01 s
No rows affected.
Inserted 1 row with 0 errors in 1.14 s (0.88 rows/s)
1 row inserted.
Using Higher Quality Models
For higher quality generation, you can use models like fal-ai/flux/dev
which produce better results but take more time:
Created table ‘flux_dev’.
Added 0 column values with 0 errors in 0.01 s
Added 0 column values with 0 errors in 0.01 s
No rows affected.
Inserted 1 row with 0 errors in 1.74 s (0.58 rows/s)
1 row inserted.
Exploring Available Models
fal.ai offers a wide variety of models. Here are some popular ones you
can try:
Image Generation Models
fal-ai/flux/schnell - Fast FLUX model for quick image generation
fal-ai/flux/dev - Higher quality FLUX model (slower)
fal-ai/fast-sdxl - Fast Stable Diffusion XL
fal-ai/stable-diffusion-v3-medium - Stable Diffusion 3 Medium
Other Models
fal-ai/fast-lightning-sdxl - Ultra-fast SDXL variant
fal-ai/recraft-v3 - Recraft V3 for design-focused generation
To use a different model, simply change the app parameter in your
fal.run() call.
Working with Batch Processing
Pixeltable’s computed columns make it easy to process multiple images in
batch. Let’s create a larger dataset:
Created table ‘batch’.
Added 0 column values with 0 errors in 0.02 s
Added 0 column values with 0 errors in 0.01 s
Added 0 column values with 0 errors in 0.01 s
No rows affected.
Inserted 5 rows with 0 errors in 1.69 s (2.96 rows/s)
5 rows inserted.
Tips and Best Practices
-
Rate Limiting: fal.ai has rate limits. Pixeltable respects these
limits by default. You can configure custom rate limits in your
Pixeltable config.
-
Model Selection:
- Use
flux/schnell for fast prototyping and when speed is critical
- Use
flux/dev when you need higher quality and can afford longer
generation times
- Use
fast-sdxl for a good balance of speed and quality
-
Prompt Engineering: Good prompts lead to better results. Be
specific and descriptive.
-
Negative Prompts: Use negative prompts to exclude unwanted
elements from your images.
-
Caching: Pixeltable automatically caches results, so re-running
the same prompt won’t incur additional costs.
Learn more
If you have any questions, don’t hesitate to reach out on our Discord
community!