Package Exports
- @fal-ai/serverless-client
- @fal-ai/serverless-client/src/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@fal-ai/serverless-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
The fal.ai JS client
About the Project
The fal-serverless JavaScript/TypeScript Client is a robust and user-friendly library designed for seamless integration of fal serverless functions in Web, Node.js, and React Native applications. Developed in TypeScript, it provides developers with type safety right from the start.
Getting Started
The serverless-js library serves as a client for fal serverless Python functions. For guidance on creating your functions, refer to the quickstart guide.
Client Library
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 fal-serverless getting started guide to acquire your credentials and register your functions.
- Start by configuring your credentials:
import * as fal from '@fal-ai/serverless-js';
fal.config({
// Can also be auto-configured using environment variables:
// Either a single FAL_KEY or a combination of FAL_KEY_ID and FAL_KEY_SECRET
credentials: 'FAL_KEY_ID:FAL_KEY_SECRET',
});- Retrieve your function id and execute it:
const result = await fal.run('my-function-id');The result's type is contingent upon your Python function's output. Types in Python are mapped to their corresponding types in JavaScript.
The fal client proxy
Although the fal client is designed to work in any JS environment, including client-side, 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 serverless APIs. Luckily fal supports that out-of-the-box with plug-and-play proxy functions for the most common engines/framrworks.
For example, if you are using Next.js, you can:
- Instal the proxy library
npm install --save @fal-ai/serverless-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/serverless-proxy/nextjs';
- Configure the client to use the proxy:
import * as fal from '@fal-ai/serverless-js'; fal.config({ requestMiddleware: fal.withProxy({ targetUrl: '/api/_fal/proxy', }), });
- Make sure your server has
FAL_KEYas 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.
The example Next.js app
You can find a minimal Next.js + fal application examples in apps/demo-nextjs-app/.
- Run
npm installon the repository root. - Create a
.env.localfile and add your API Key asFAL_KEYenvironment variable (or export it any other way your prefer). - Run
npx nx serve demo-nextjs-appto start the Next.js app.
Roadmap
See the open feature requests for a list of proposed features and join the discussion.
Contributing
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!
License
Distributed under the MIT License. See LICENSE for more information.