Documentation
Real Time Models ⚡️
Quickstart

Real Time Models Quickstart

In this example, we'll be using our most popular optimized ultra fast latent consistency model (opens in a new tab).

All our Model Endpoint's support HTTP/REST. Additionally our real-time models support WebSockets. You can use the HTTP/REST endpoint for any real time model but if you are sending back to back requests using websockets gives the best results.

Before we proceed, you need to create your API key.

import * as fal from "@fal-ai/serverless-client";
 
fal.config({
  credentials: "FAL_KEY",
});
 
const connection = fal.realtime.connect("fal-ai/fast-lcm-diffusion", {
  onResult: (result) => {
    console.log(result);
  },
  onError: (error) => {
    console.error(error);
  },
});
 
connection.send({
  prompt:
    "an island near sea, with seagulls, moon shining over the sea, light house, boats int he background, fish flying over the sea",
  sync_mode: true,
  image_url:
    "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==",
});

You can read more about the real time clients in our real time client docs section.

To get the best performance from this model:

  • Make sure the image is provided as a base64 encoded data url.
  • Make sure the image_url is exactly 512x512.
  • Make sure sync*mode is true, this will make sure you also get a base64 encoded data url back from our API.

You can also use 768x768 or 1024x1024 as your image dimensions, the inference will be faster for this configuration compared to random dimensions but wont be as fast as 512x512.

Video Tutorial: Latent Consistency - Build a Real-Time AI Image App with WebSockets, Next.js, and fal.ai by Nader Dabit


2023 © Features and Labels Inc.