Skip to main content

Classes & Interfaces

FalStream

interface FalStream
The class representing a streaming response. With t

Properties

NameTypeDescription
configRequiredConfig-
endpointIdstring-
urlstring-
optionsStreamOptions<Input>-
listenersMap<FalStreamEventType, EventHandler[]>-
bufferOutput[]-
currentDataOutput | undefined-
lastEventTimestampany-
streamClosedany-
_requestIdstring | null-
donePromisePromise<Output>-
abortControllerany-
startany-
handleResponseany-
handleErrorany-
onany-
emitany-
doneanyGets a reference to the Promise that indicates whether the streaming is done or not. Developers should always call this in their apps to ensure the request is over. An alternative to this, is to use on('done') in case your application architecture works best with event listeners.
abortanyAborts the streaming request. Note: This method is noop in case the request is already done.

Methods

[Symbol.asyncIterator]

async [Symbol.asyncIterator](): any
Returns: any

StreamingClient

interface StreamingClient
The streaming client interface.

Methods

stream

stream(endpointId: Id, options: StreamOptions<InputType<Id>>): Promise<FalStream<InputType<Id>, OutputType<Id>>>
Calls a fal app that supports streaming and provides a streaming-capable object as a result, that can be used to get partial results through either AsyncIterator or through an event listener.
ParameterTypeDescription
endpointIdIdthe endpoint id, e.g. fal-ai/llavav15-13b.
optionsStreamOptions<InputType<Id>>the request options, including the input payload.
Returns: Promise<FalStream<InputType<Id>, OutputType<Id>>>

Functions

createStreamingClient

function createStreamingClient({ config, storage, }: StreamingClientDependencies): StreamingClient
ParameterTypeDescription
{ config, storage, }StreamingClientDependencies-
Returns: StreamingClient

Types

StreamingConnectionMode

type StreamingConnectionMode = "client" | "server"

StreamOptions

type StreamOptions = {
  /**
   * The endpoint URL. If not provided, it will be generated from the
   * `endpointId` and the `queryParams`.
   */
  readonly url?: string;

  /**
   * The API input payload.
   */
  readonly input?: Input;

  /**
   * The query parameters to be sent with the request.
   */
  readonly queryParams?: Record<string, string>;

  /**
   * The maximum time interval in milliseconds between stream chunks. Defaults to 15s.
   */
  readonly timeout?: number;

  /**
   * Whether it should auto-upload File-like types to fal's storage
   * or not.
   */
  readonly autoUpload?: boolean;

  /**
   * The HTTP method, defaults to `post`;
   */
  readonly method?: "get" | "post" | "put" | "delete" | string;

  /**
   * The content type the client accepts as response.
   * By default this is set to `text/event-stream`.
   */
  readonly accept?: string;

  /**
   * The streaming connection mode. This is used to determine
   * whether the streaming will be done from the browser itself (client)
   * or through your own server, either when running on NodeJS or when
   * using a proxy that supports streaming.
   *
   * It defaults to `server`. Set to `client` if your server proxy doesn't
   * support streaming.
   */
  readonly connectionMode?: StreamingConnectionMode;

  /**
   * The signal to abort the request.
   */
  readonly signal?: AbortSignal;
}
The stream API options. It requires the API input and also offers configuration options.