gentle-jackal-41968
10/30/2025, 1:48 PMtall-airline-16756
10/30/2025, 1:48 PMtall-airline-16756
10/30/2025, 1:48 PMgentle-jackal-41968
10/30/2025, 1:50 PMtall-airline-16756
10/30/2025, 1:51 PMmetadata field in your dispatch request to send structured information such as phone numbers. Here's a simple example:
lk dispatch create \
--new-room \
--agent-name your-agent \
--metadata '{"phone_number": "+1234567890", "user_id": "user123", "user_name": "John Doe"}'
Just so you know, the metadata field expects a string, and using JSON is a great way to structure your data.
Access Metadata in the Agent
Inside your agent’s entrypoint function, you can parse this metadata and use it like this:
import json
async def entrypoint(ctx: JobContext):
# Parse job metadata
dial_info = json.loads(ctx.job.metadata)
phone_number = dial_info["phone_number"]
user_id = dial_info.get("user_id")
user_name = dial_info.get("user_name")
# Use the data in agent logic
This way, your agent will have access to the phone number and any other metadata throughout the session.
Alternative: Update Room Metadata
If you find yourself needing to send or update data after the session has already started, you can use the UpdateRoomMetadata API like this:
const roomService = new RoomServiceClient(LIVEKIT_URL, API_KEY, API_SECRET);
await roomService.updateRoomMetadata("my-room", '{"status": "call_connected"}');
Just a quick note: this updates the room’s metadata, not the agent’s job metadata.
Important Notes
• Keep in mind that job metadata can’t be changed once the session starts, so it’s best to include all the important info at dispatch time.
• If you need to make updates dynamically during the session, using room or participant metadata updates is the way to go.
If anything isn’t clear or you want to explore this further, please don’t hesitate to ask—I’m here to help!
Sources: livekit/livekit_connector_whatsapp.pb.go | Job lifecycle | LiveKit Docs | Agent dispatch | LiveKit Docs | README.md | agent-console/app/api/room/update-metadata/route.tsgentle-jackal-41968
10/30/2025, 1:54 PMtall-airline-16756
10/30/2025, 1:55 PMUpdateRoomMetadata API. This involves calling the RoomService API directly. Here’s a simple example:
const roomService = new RoomServiceClient(LIVEKIT_URL, API_KEY, API_SECRET);
await roomService.updateRoomMetadata("my-room", '{"status": "call_connected"}');
This method works great for updating room-wide metadata once a session is underway.
Custom HTTP Endpoints in the Agent
If you want to send metadata (like phone numbers) from another system to the agent, you can build a custom HTTP server inside your agent code. For instance:
• Use a web framework such as FastAPI (Python) or Express (Node.js) to create your own endpoints.
• Handle incoming POST requests to update the agent’s internal state or call the LiveKit server API to update room metadata.
This way, you can tailor the solution to fit your specific needs and workflow.
Job Metadata Limitations
One important thing to keep in mind: job metadata can’t be changed once a session starts and must be set when dispatching. If you need to update data dynamically during a session, using room metadata updates or participant-level metadata is the way to go.
Please feel free to reach out if you’d like more detailed help on setting up custom endpoints or working with the LiveKit API—I’m here to help!
Sources: Job lifecycle | LiveKit Docs | Agent dispatch | LiveKit Docs | livekit/livekit_room.twirp.go | agent-console/lib/types.ts | agent/game_host.pygentle-jackal-41968
10/30/2025, 2:15 PMtall-airline-16756
10/30/2025, 2:16 PM{
"livekit_url": "https://your-livekit-server.com",
"livekit_token": "your-agent-jwt-token",
"room_name": "your-room-name"
}
Feel free to add extra fields such as image, agent_id, or model if your setup requires them.
2. Generate a LiveKit JWT Token
Within your LiveKit agent, you’ll want to generate a room join token using the AccessToken class like this:
livekit_token = (
api.AccessToken(api_key=livekit_api_key, api_secret=livekit_api_secret)
.with_kind("agent")
.with_identity("my-ai-agent")
.with_grants(api.VideoGrants(room_join=True, room=ctx.room.name))
.to_jwt()
)
This token is essential for authenticating your AI agent with LiveKit, so make sure to include it in your POST payload.
3. Send the POST Request
To send the request, you can use an HTTP client like aiohttp or httpx. Here’s a simple example:
async with httpx.AsyncClient() as client:
response = await client.post(
<YOUR_AI_AGENT_ENDPOINT>,
json={
"livekit_url": livekit_url,
"livekit_token": livekit_token,
"room_name": room_name
}
)
response.raise_for_status()
4. Add Retry Logic
Sometimes requests might fail temporarily, so adding retry logic can really help improve reliability. Here’s a basic pattern you can follow:
for attempt in range(max_retries):
try:
response = await client.post(...)
break
except Exception:
await asyncio.sleep(retry_interval)
5. Use Environment Variables
For your sensitive data like API keys and URLs, it’s best to store them in environment variables. This keeps your setup secure and flexible.
Important Notes:
• LiveKit agents don’t come with built-in HTTP endpoints for external POST requests, so you’ll need to add this functionality within your AI agent yourself.
• Keep in mind that job metadata can’t be changed after dispatch, so for any dynamic updates, consider using room or participant metadata instead.
If you have any questions or want to dive deeper into any part of this, just let me know—I’m here to help!
Sources: livekit-plugins/livekit-plugins-simli/livekit/plugins/simli/avatar.py | Deploying to custom environments | LiveKit Docsgentle-jackal-41968
10/30/2025, 2:59 PMtall-airline-16756
10/30/2025, 3:00 PMsendData method. For example, the RoomServiceClient lets you send a message to the room, and the agent can pick it up and process it.
• Custom HTTP Server: If you want to send POST requests directly to the agent, you could add a custom HTTP server inside the agent’s code (like with FastAPI or Express). This way, your agent can handle incoming requests and take action.
• External API Integration: Agents can also send POST requests to external APIs. You might have seen this in plugins like Anam, Bithuman, and Simli, where the agent acts as an HTTP client instead of a server.
If your goal is to trigger an action on the agent from an external system, the best way is to send data into the LiveKit room using the RoomServiceClient, or to set up a custom HTTP server within the agent. Please feel free to reach out if you’d like some guidance on either of these approaches—I’m here to help!
Sources: plugins/anam/src/api.ts | livekit-plugins/livekit-plugins-simli/livekit/plugins/simli/avatar.py | agent-console/app/api/room/send-data/route.ts | Egress API | LiveKit Docs | SIP APIs | LiveKit Docsgentle-jackal-41968
10/30/2025, 3:03 PMsendData method. For example, the RoomServiceClient lets you send a message to the room, and the agent can pick it up and process it.
tell me more about it, the room need to be the same every call? or notall-airline-16756
10/30/2025, 3:03 PMRoomServiceClient.sendData method in LiveKit is a wonderful tool that lets you send data messages to participants in a specific room. When you use sendData, you’ll just need to specify the room name in the room parameter each time.
Room Flexibility:
• The room doesn’t have to be the same every time you call it. You can easily send data to different rooms by just changing the room name in each call.
• This gives you great flexibility to reach multiple rooms dynamically, depending on what you need.
If you’d like a hand with implementing this or managing multiple rooms, please don’t hesitate to ask—I’m here to help!
Sources: packages/livekit-server-sdk/src/RoomServiceClient.ts | src/main/kotlin/io/livekit/server/RoomServiceClient.kt | livekit-api/src/services/room.rsgentle-jackal-41968
10/30/2025, 3:05 PMtall-airline-16756
10/30/2025, 3:06 PMcreateRoom API method. This lets you set important parameters like empty_timeout and max_participants to fit your needs.
2. Room Cleanup
• It’s a good idea to set an appropriate empty_timeout so rooms close automatically once everyone leaves, keeping things tidy without extra effort.
• And if you ever need to manually clean up, the deleteRoom API is there for you.
3. Room Metadata
• Don’t forget, you can store application-specific details like call info in the room metadata. This data stays in sync for all participants and can be updated as things change.
4. Scaling and Multi-Node Setup
• For larger setups, configuring Redis helps with distributed room management and balances the load automatically across nodes.
• Also, keep in mind that each room lives on a single node, so planning room sizes accordingly will keep everything running smoothly.
5. Monitoring and Observability
• Keeping an eye on metrics like the number of active rooms, participants per room, and how long rooms last can give you great insights.
• Setting up alerts for unusual activity, such as rapid room creation or rooms staying open too long, can help you catch issues early.
If you’d like, I’m here to dive deeper into any of these points or help tailor advice specifically for your setup. Just let me know!
Sources: Core Platform Architecture & Authentication | livekit/livekit_composite | D... | pkg/service/roommanager.go | Distributed Setup | LiveKit docs | livekit-api/livekit/api/room_service.py | README.mdgentle-jackal-41968
10/30/2025, 3:12 PMtall-airline-16756
10/30/2025, 3:14 PMLIVEKIT_URL, LIVEKIT_API_KEY, and LIVEKIT_API_SECRET are automatically provided as environment variables to your agents at runtime. These credentials are managed by LiveKit itself, so they can’t be manually set or overridden through n8n.
2. Custom/Self-Hosted Deployments
• If you’re working with custom environments like Docker, Kubernetes, or Fly.io, you’ll need to provide these credentials manually as environment variables. Here’s how n8n can help make this smoother:
◦ Orchestrating deployment workflows that set environment variables (for example, with fly secrets set).
◦ Managing the injection of environment variables during container deployment.
◦ Coordinating CI/CD pipelines to securely pass along your credentials.
◦ Automating credential rotation to keep your setup secure across environments.
Security Best Practices
• It’s super important to never hardcode credentials in your source code or config files.
• Always use environment variables for sensitive information.
• And keep your secrets out of version control by using proper secrets management tools.
If you’d like, I’m here to help you with implementing this setup or answer any specific questions about your deployment platform. Just let me know!
Sources: Server-Side SDKs & Authentication | livekit/livekit_composite | DeepWiki | fly.io/README.md | Secrets management | LiveKit Docs | CLI Tools & Token Management | livekit/livekit_composite | DeepWiki | Community & Support | livekit/livekit_composite | DeepWiki