The fal JavaScript/TypeScript Client is a robust and user-friendly library designed for seamless integration of fal endpoints in Web, Node.js, and React Native applications. Developed in TypeScript, it provides developers with type safety right from the start.
The @fal-ai/client
library serves as a client for fal apps hosted on fal. For guidance on consuming and creating apps, refer to the quickstart guide.
This client library is crafted as a lightweight layer atop platform standards like fetch
. This ensures a hassle-free integration into your existing codebase. Moreover, it addresses platform disparities, guaranteeing flawless operation across various JavaScript runtimes.
Note: Ensure you've reviewed the getting started guide to acquire your credentials, browser existing APIs, or create your custom functions.
-
Install the client library
npm install --save @fal-ai/client
-
Start by configuring your credentials:
import { fal } from "@fal-ai/client"; fal.config({ // Can also be auto-configured using environment variables: credentials: "FAL_KEY", });
-
Retrieve your function id and execute it:
const result = await fal.run("user/app-alias");
The result's type is contingent upon your Python function's output. Types in Python are mapped to their corresponding types in JavaScript.
See the available model APIs for more details.
Although the fal client is designed to work in any JS environment, including directly in your browser, it is not recommended to store your credentials in your client source code. The common practice is to use your own server to serve as a proxy to fal APIs. Luckily fal supports that out-of-the-box with plug-and-play proxy functions for the most common engines/frameworks.
For example, if you are using Next.js, you can:
- Instal the proxy library
npm install --save @fal-ai/server-proxy
- Add the proxy as an API endpoint of your app, see an example here in pages/api/fal/proxy.ts
export { handler as default } from "@fal-ai/server-proxy/nextjs";
- Configure the client to use the proxy:
import { fal } from "@fal-ai/client"; fal.config({ proxyUrl: "/api/fal/proxy", });
- Make sure your server has
FAL_KEY
as environment variable with a valid API Key. That's it! Now your client calls will route through your server proxy, so your credentials are protected.
See libs/proxy for more details.
You can find a minimal Next.js + fal application examples in apps/demo-nextjs-page-router/.
- Run
npm install
on the repository root. - Create a
.env.local
file and add your API Key asFAL_KEY
environment variable (or export it any other way your prefer). - Run
npx nx serve demo-nextjs-page-router
to start the Next.js app (demo-nextjs-app-router
is also available if you're interested in the app router version).
Check our Next.js integration docs for more details.
See the open feature requests for a list of proposed features and join the discussion.
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Make sure you read our Code of Conduct
- Fork the project and clone your fork
- Setup the local environment with
npm install
- Create a feature branch (
git checkout -b feature/add-cool-thing
) or a bugfix branch (git checkout -b fix/smash-that-bug
) - Commit the changes (
git commit -m 'feat(client): added a cool thing'
) - use conventional commits - Push to the branch (
git push --set-upstream origin feature/add-cool-thing
) - Open a Pull Request
Check the good first issue queue, your contribution will be welcome!
Distributed under the MIT License. See LICENSE for more information.