fal-rs
A Rust client for the fal.ai API, providing easy access to state-of-the-art AI models for image generation, audio processing, and more.
Features
- Type-safe API: Strongly typed interfaces for all fal.ai endpoints, generated and kept up-to-date straight from the API itself
- Compile Time Efficient: FAL API Endpoint modules are code generated from the API with granular features, so you only build the set of endpoints you actually use!
- Async/Await Support: Built on top of
reqwestfor efficient async operations - Queue System: Built-in support for fal.ai's queue system for long-running operations
- Image Processing: Optional image processing capabilities with the
imagefeature
Installation
Add this to your Cargo.toml:
[]
= "0.2"
Usage
Using public model endpoints
By default, endpoints are disabled. The FAL API has hundreds of endpoints, and are growing in number by the day. In order to prevent compile time and binary size bloat, this crate supports somewhat fine-grained crate features for enabling endpoints, as you need them. To use pre-built, fully-typed endpoint functions to call the API, you can enable them by enabling the corresponding feature for that group of endpoints. For example, for the fal-ai/flux/dev endpoint, I can enable it like this:
# In Cargo.toml
= { = "0.2", = ["endpoints_fal-ai_flux"] }
Note: The features go a maximum of two "levels", so you can enable fal-ai/flux, which enables all endpoints under fal-ai/flux, or fal-ai, or all endpoints in the API.
or, I can enable all endpoints under the fal-ai owner:
# In Cargo.toml
= { = "0.2", = ["endpoints_fal-ai"] }
or if I'm really crazy, I can just enable all endpoints in the API:
# In Cargo.toml
= { = "0.2", = ["endpoints"] }
Once enabled, the endpoint can be called like this:
use *;
use flux;
async
Using the Queue System
For long-running operations, you can use the FAL Queue API:
use *;
use flux;
use StreamExt;
async
The #[endpoint] macro
You can easily create a custom endpoint function using the provided endpoint proc macro. This should only be necessary if you are using a private model endpoint, or you really just want control over your types. Otherwise, you should be able to find the endpoint you want to use in the pre-built endpoints module!
# in Cargo.toml
[]
= { = "0.1", = false, = ["image"] }
use *;
use Deserialize;
// This endpoint function can now be used to call the fal endpoint:
async
Features
The crate comes with several optional features:
image(enabled by default): Provides image processing helpers using theimagecrateendpoints_*: Include pre-generated endpoint modules for fal.ai services. See "Using public model endpoints" above for details.
Generating Endpoint Modules
The generate package in this repository is used to automatically generate endpoint modules based on the fal.ai API specification. This ensures that the client always has up-to-date type definitions and endpoint implementations.
To generate endpoint modules:
- Clone the repository
- Run the generate package:
This will update the endpoint modules in the fal/src/endpoints directory with the latest API definitions, using the model registry from the FAL API.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contributing
We welcome contributions! Please feel free to submit a Pull Request.