decart/lucy2-realtime/realtime
1. Calling the API#
Install the client#
The client provides a convenient way to interact with the model API.
npm install --save @fal-ai/clientMigrate to @fal-ai/client
The @fal-ai/serverless-client package has been deprecated in favor of @fal-ai/client. Please check the migration guide for more information.
Setup your API Key#
Set FAL_KEY as an environment variable in your runtime.
export FAL_KEY="YOUR_API_KEY"Real-time via WebSockets#
This model has a real-time mode via websockets, this is supported via the fal.realtime client.
import { fal } from "@fal-ai/client";
const connection = fal.realtime.connect("decart/lucy2-realtime/realtime", {
onResult: (result) => {
console.log(result);
},
onError: (error) => {
console.error(error);
},
// Fetch short-lived JWT token from your backend
tokenProvider: async (app) => {
const response = await fetch("/api/fal/realtime-token", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ app }),
});
return response.text();
},
tokenExpirationSeconds: 10,
});
connection.send({});2. Authentication#
The API uses an API Key for authentication. It is recommended you set the FAL_KEY environment variable in your runtime when possible.
API Key#
import { fal } from "@fal-ai/client";
fal.config({
credentials: "YOUR_FAL_KEY"
});Protect your API Key
When running code on the client-side (e.g. in a browser, mobile app or GUI applications), make sure to not expose your FAL_KEY. Instead, use a server-side proxy to make requests to the API. For more information, check out our server-side integration guide.
4. Files#
Some attributes in the API accept file URLs as input. Whenever that's the case you can pass your own URL or a Base64 data URI.
Data URI (base64)#
You can pass a Base64 data URI as a file input. The API will handle the file decoding for you. Keep in mind that for large files, this alternative although convenient can impact the request performance.
Hosted files (URL)#
You can also pass your own URLs as long as they are publicly accessible. Be aware that some hosts might block cross-site requests, rate-limit, or consider the request as a bot.
Uploading files#
We provide a convenient file storage that allows you to upload files and use them in your requests. You can upload files using the client API and use the returned URL in your requests.
import { fal } from "@fal-ai/client";
const file = new File(["Hello, World!"], "hello.txt", { type: "text/plain" });
const url = await fal.storage.upload(file);Auto uploads
The client will auto-upload the file for you if you pass a binary object (e.g. File, Data).
Read more about file handling in our file upload guide.
5. Schema#
Input#
prompt stringRealtime edit instruction sent to Lucy 2. Default value: ""
image_url stringImage data URI or HTTP(S) URL for realtime frame input. Data URI format: data:image/<type>;base64,... Default value: ""
reference_image_url stringReference image URL or data URI. When set, Lucy 2 will use this as a character reference for the transformation. Default value: "https://v3b.fal.media/files/b/0a8ea2cb/-xGTNhbMcXFFS8rQYnBhR_cINVWhYM.png"
{
"reference_image_url": "https://v3b.fal.media/files/b/0a8ea2cb/-xGTNhbMcXFFS8rQYnBhR_cINVWhYM.png"
}Output#
Edited output frame(s) for the current realtime input frame.
{
"images": [
{
"content": "",
"content_type": "image/jpeg"
}
]
}Other types#
RawImage#
height integer* requiredcontent string* requiredcontent_type stringDefault value: "image/jpeg"
width integer* required