In Unity, I want to create an agent in an existing...
# ask-ai
b
In Unity, I want to create an agent in an existing room. I need the right auth token. Do I use the same participant token I used for creating the room or do I need a different auth token?
t
Thanks for reaching out, Mat. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your question about which auth token to use when creating an agent in an existing Unity room. Short answer: do not reuse the participant token. The agent needs its own access token with a unique identity and the appropriate grants for the room. What to do: 1. Generate a new access token for the agent on your secure backend. ◦ Give it a unique
identity
(for example,
agent-bot-1
). ◦ Grant it permission to join the specific room (e.g.,
roomJoin: true
and the
room
name). 1. Return that agent token to whatever process will run the agent (the agent itself or the service that spawns the agent). 2. Have the agent connect to the room using that token independently from the Unity client participant. Why: each token represents a specific participant identity. Reusing a participant’s token would attempt to authenticate as that same identity, which is not correct for a separate agent and can cause identity/permission conflicts. If you’d like, I can: • Show a short server-side token-generation snippet in the language you use. • Walk through how to wire this into your Unity client and the agent process. Which language is your backend written in? Sources: server-sdk-kotlin | livekit/livekit_composite | DeepWiki | client-sdk-unity | livekit/livekit_composite | DeepWiki
b
Right now to create my room I'm getting my token from the LiveKit sandbox, using https://cloud-api.livekit.io:443/api/sandbox/connection-details . What is the equivalent way to get a token for creating an agent, given that the room is already created?
t
Thanks — I’m responding to your question about using the sandbox
/api/sandbox/connection-details
endpoint to get a token for creating an agent in an existing room. Short answer: the sandbox endpoint is for quick participant tokens (demo clients) and is not the right way to create an agent. You should generate a server-signed Access Token for the agent using your LiveKit API Key and Secret (via a LiveKit server SDK), or dispatch the agent from a server-generated participant token. What to do next (two common approaches): 1) Generate an agent token directly (recommended for agents) • On your secure backend, use a LiveKit server SDK to build an Access Token for the agent. • Set a unique
identity
for the agent and include a grant that allows joining the specific room (e.g.,
roomJoin: true
,
room: "existing-room-name"
). • Return that JWT to the agent process; the agent connects to the room with that token independently from Unity. 2) Dispatch an agent when a user joins (alternative) • Instead of separately issuing an agent token, you can include an agent dispatch configuration in the participant’s server-generated token so the agent is automatically dispatched to the room when the participant connects. • This dispatch configuration is created server-side when you generate the participant token. If you want, I can: • Show a short server-side example in the language you use (Node.js, Python, Go, or Kotlin). • Help you pick between direct agent tokens vs. dispatch based on how your agent runs (backend process vs. auto-started agent). Which backend language do you use for token generation? Sources: server-sdk-js | livekit/livekit_composite | DeepWiki | Agent dispatch | LiveKit Documentation