Skip to main content

Examples

Working examples can be found at the Lemon Slice Examples Github Repo

Getting Started

Follow these steps to create your first Lemon Slice agent session and integrate it into your application.

1. Get your API key

Retrieve your API Key from the Lemon Slice dashboard.
All API requests must include this header:
X-API-Key: YOUR_API_KEY

2. Create a room

Use the POST /rooms endpoint to create a Daily room configured with a Lemon Slice agent. The agent will automatically join the room once it’s startup is complete.
Example request
curl -X POST https://lemonslice.com/api/rooms \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "agent_id": "YOUR_AGENT_ID" }'

3. Join the room from your frontend

Use Daily’s JavaScript SDK to join the room with the URL and token returned by the API.
Example (JavaScript)
import DailyIframe from "@daily-co/daily-js";

const callObject = DailyIframe.createCallObject();

await callObject.join({
  url: room_url,
  token: token
});
Once joined, the Lemon Slice agent will connect and begin responding in the room.

4. Listen for Lemon Slice events

Lemon Slice uses Daily’s app-message channel to push events about the agent, image updates, and errors.
Example event handler
useDailyEvent("app-message", (ev) => {
  if (ev?.data?.type === "bot_ready") {
    console.log("Agent is ready!");
  }
  if (ev?.data?.type === "daily_error") {
    console.log("An error occurred. ", ev?.data?.err_msg);
  }
});

You’re ready to build

With a room created, the agent connected, and event hooks wired up, you’re ready to:
  • Build interactive video AI apps
  • Customize agent behavior
  • Trigger image changes and respond to events
Explore the rest of the API docs for more capabilities.

Receiving Events

Hook into the Daily event handler to get Lemon Slice specific events
Event TypeDescription
bot_readyFired when the Lemon Slice agent has successfully joined the Daily room and is ready to send and receive audio and video.
idle_timeoutEmitted when the agent stops due to inactivity. The idle timeout threshold is defined by the agent’s configuration.
user_transcriptionEmitted when the user’s speech has been finalized. Includes the field transcription. This event also captures messages sent by the user via text.
agent_transcriptionEmitted when the agent’s response has been finalized. Includes the field transcription.
image_change_requestedA new agent look has been requested, typically after an /imagine request is made.
image_createdA new agent look has been created and is available for use.
image_change_completeThe agent’s look has finished updating and the new look is now active.
image_change_errorThe agent failed to update its look. Includes an error field with additional details.
daily_errorA Daily-related error occurred. Includes error and fatal fields.
video_generation_errorA failure occurred while generating a video segment or rendering agent output.

Full event handler

useDailyEvent(
  "app-message",
  useCallback((ev: DailyEventObjectAppMessage) => {
    if (ev?.data?.type === "bot_ready") {
      console.log("Agent has joined the room")
    }
    if (ev?.data?.type === "idle_timeout") {
      console.log("Agent has timed out")
    }
    if (ev?.data?.type === "user_transcription") {
      console.log("Latest user transcription: ", ev?.data?.transcription);
    }
    if (ev?.data?.type === "agent_transcription") {
      console.log("Latest agent transcription: ", ev?.data?.transcription);
    }
    if (ev?.data?.type === "image_change_requested") {
      console.log("Request to edit agent has been received")
    }
    if (ev?.data?.type === "image_created") {
      console.log("New base image for Agent created")
    }
    if (ev?.data?.type === "image_change_complete") {
      console.log("Updated agent is ready")
    }
    if (ev?.data?.type === "image_change_error") {
      console.log("Failed to update agent", ev?.data?.error)
    }
    if (ev?.data?.type === "daily_error") {
      console.log("An error occurred. ", ev?.data?.error, ev?.data?.fatal);
    }
    if (ev?.data?.type === "video_generation_error") {
      console.log("A video generation error occurred.");
    } 
  }, [])
);

Control Events

Send events through Daily to control the Lemon Slice agent
Control EventDescription
chat-msgSend a message to the agent for it to respond to.
force-endImmediately stop the realtime agent. The agent will leave the room and billing will stop.

Sending Events

sendAppMessage(
  {
    event: "chat-msg",
    message: "Your message here",
    name: "User",
  },
  "*",
);

sendAppMessage(
  { event: "force-end" },
  "*",
);