UNPKG

siliconflow-serverless-client

Version:

![@siliconflow/siliconflow-js npm package](https://img.shields.io/npm/v/@siliconflow/siliconflow-js?color=%25237527D7&label=@siliconflow/siliconflow-js&style=flat-square)

53 lines (36 loc) 2.5 kB
# siliconflow.com JavaScript/TypeScript client library ![@fal-ai/serverless-client npm package](https://img.shields.io/npm/v/@fal-ai/serverless-client?color=%237527D7&label=%40fal-ai%2Fserverless-client&style=flat-square) ## Introduction The `siliconflow.com` JavaScript Client Library provides a seamless way to interact with `fal` serverless functions from your JavaScript or TypeScript applications. With built-in support for various platforms, it ensures consistent behavior across web, Node.js, and React Native environments. ## Getting started Before diving into the client-specific features, ensure you've set up your credentials: ```ts import * as fal from '@fal-ai/serverless-client'; siliconflowconfig({ // 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', }); ``` **Note:** Ensure you've reviewed the [siliconflow.com getting started guide](https://siliconflow.com/docs) to acquire your credentials and register your functions. Also, make sure your credentials are always protected. See the [../proxy](../proxy) package for a secure way to use the client in client-side applications. ## Running functions with `siliconflowrun` The `siliconflowrun` method is the simplest way to execute a function. It returns a promise that resolves to the function's result: ```ts const result = await siliconflowrun('my-function-id', { input: { foo: 'bar' }, }); ``` ## Long-running functions with `siliconflowsubscribe` The `siliconflowsubscribe` method offers a powerful way to rely on the [queue system](https://www.siliconflow.com/docs/function-endpoints/queue) to execute long-running functions. It returns the result once it's done like any other async function, so your don't have to deal with queue status updates yourself. However, it does support queue events, in case you want to listen and react to them: ```ts const result = await siliconflowsubscribe('my-function-id', { input: { foo: 'bar' }, onQueueUpdate(update) { if (update.status === 'IN_QUEUE') { console.log(`Your position in the queue is ${update.position}`); } }, }); ``` ## More features The client library offers a plethora of features designed to simplify your serverless journey with `siliconflow.com`. Dive into the [official documentation](https://siliconflow.com/docs) for a comprehensive guide.