bulky-car-15738
12/18/2025, 12:06 PMtall-airline-16756
12/18/2025, 12:06 PMtall-airline-16756
12/18/2025, 12:06 PMinfo contains the stream ID (e.g., info.stream_id in Python).
• When receiving, the handler gives reader.info.id (e.g., console.log(reader.info.id)).
Which platform/language are you using so I can give a concrete code example?
Sources: Sending text | LiveKit docsbulky-car-15738
12/18/2025, 12:07 PMtall-airline-16756
12/18/2025, 12:08 PMinfo contains the stream ID.
# async example using LiveKit Python SDK
info = await room.local_participant.send_text("Hello", topic="chat")
print(info.stream_id) # message / stream ID
Frontend — React (receiving text)
1. When registering a text stream handler in the browser, the reader.info.id contains the stream ID.
// assume `room` is a connected LiveKit Room
room.registerTextStreamHandler("chat", async (reader, participantIdentity) => {
console.log("Received stream ID:", reader.info.id);
// read the text if needed
const msg = await reader.readText();
console.log("Text:", msg);
});
Frontend — React (sending text)
1. When sending from the client, the returned info object includes the ID:
const info = await room.localParticipant.sendText("Hello", { topic: "chat" });
console.log("Sent stream ID:", info.id);
Notes
• The field name differs slightly between SDKs: Python uses stream_id on the returned `info`; JS uses id on the returned info and reader.info.id when receiving.
• If you want to persist or reference IDs across backend and frontend, capture the returned ID when sending and store it in your database or return it in your API response.
Would you like full examples showing how to persist these IDs in a database or correlate a sent ID from backend to frontend?bulky-car-15738
12/18/2025, 12:10 PMtall-airline-16756
12/18/2025, 12:11 PMconversation_item_added event and want the message ID in both backend (Python) and frontend (React). Here's exactly how to get it and how to deliver it to the frontend.
Backend — Python (inside your event handler)
• Extract the ID from the event item:
@session.on("conversation_item_added")
def on_conversation_item_added(event: ConversationItemAddedEvent):
message_id = event.item.id
role = event.item.role
text = event.item.text_content
# persist or forward the ID + content as needed
print(f"Message ID: {message_id}, role: {role}, text: {text}")
Options to get the ID to the React frontend
• Send it via your backend API: store the message (ID + content) in your DB and return it from an API endpoint the React app calls or polls.
• Push it in real time via WebSocket / Server-Sent Events: send the event payload including item.id to connected clients as soon as you receive conversation_item_added.
• Embed the ID in a text stream sent through LiveKit: include the ID in the JSON payload when sending text streams so receivers see it (e.g., sendText(JSON.stringify({ id, text, sender }))) and parse it in React.
Frontend — React
• If you receive via your own socket/API:
◦ Parse the incoming payload and read id.
• If you receive via LiveKit text stream with embedded ID:
room.registerTextStreamHandler("chat-messages", async (reader) => {
for await (const chunk of reader) {
const msg = JSON.parse(chunk);
console.log("Message ID:", msg.id, "Text:", msg.text);
}
});
Which delivery method do you prefer (API polling, WebSocket push, or embedding IDs in LiveKit text streams)? I can give a concrete React + backend example for the one you pick.
Sources: Events and error handling | LiveKit docs