Client Library for JavaScript / TypeScript
Introduction
The client for JavaScript / TypeScript provides a seamless interface to interact with fal.
Installation
First, add the client as a dependency in your project:
Features
1. Call an endpoint
Endpoints requests are managed by a queue system. This allows fal to provide a reliable and scalable service.
The subscribe
method allows you to submit a request to the queue and wait for the result.
2. Queue Management
You can manage the queue using the following methods:
Submit a Request
Submit a request to the queue using the queue.submit
method.
This is useful when you want to submit a request to the queue and retrieve the result later. You can save the request_id
and use it to retrieve the result later.
Check Request Status
Retrieve the status of a specific request in the queue:
Retrieve Request Result
Get the result of a specific request from the queue:
3. File Uploads
Some endpoints require files as input. However, since the endpoints run asynchronously, processed by the queue, you will need to provide URLs to the files instead of the actual file content.
Luckily, the client library provides a way to upload files to the server and get a URL to use in the request.
4. Streaming
Some endpoints support streaming:
5. Realtime Communication
For the endpoints that support real-time inference via WebSockets, you can use the realtime client that abstracts the WebSocket connection, re-connection, serialization, and provides a simple interface to interact with the endpoint:
6. Run
The endpoints can also be called directly instead of using the queue system.
API Reference
For a complete list of available methods and their parameters, please refer to JavaScript / TypeScript API Reference documentation.
Examples
Check out some of the examples below to see real-world use cases of the client library:
- See
fal.realtime
in action with SDXL Lightning: https://github.com/fal-ai/sdxl-lightning-demo-app
Support
If you encounter any issues or have questions, please visit the GitHub repository or join our Discord Community.
Migration from serverless-client
to client
As fal no longer uses “serverless” as part of the AI provider branding, we also made sure that’s reflected in our libraries. However, that’s not the only thing that changed in the new client. There was lot’s of improvements that happened thanks to our community feedback.
So, if you were using the @fal-ai/serverless-client
package, you can upgrade to the new @fal-ai/client
package by following these steps:
- Remove the
@fal-ai/serverless-client
package from your project: - Install the new
@fal-ai/client
package: - Update your imports:
- Now APIs return a
Result<Output>
type that contains thedata
which is the API output and therequestId
. This is a breaking change from the previous version, that allows us to return extra data to the caller without future breaking changes.