Can we start a livekit agent directly from the rea...
# ask-ai
n
Can we start a livekit agent directly from the react SDK? I mean can we create token and start room on the frontend itself?
t
Thanks for reaching out, Hari. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking whether you can create tokens and start a LiveKit agent/room entirely from the React frontend. No — you should not generate tokens or start agents from the frontend. Tokens must be created on a trusted backend using your LiveKit API key and secret. The React SDK can only use a pre-generated token to connect to a room (e.g.,
Room.connect()
). LiveKit agents run on the backend and require the
livekit-server-sdk
to receive job assignments; they cannot be started from frontend code. Typical flow: 1. Frontend requests a token from your backend. 2. Backend generates the token with
livekit-server-sdk
and returns it. 3. Frontend uses the token to connect to the room. 4. Backend/agent joins or is dispatched via room configuration (
roomConfig.agents
). If you want, I can show a minimal backend token-generation example for your stack (Node/Go/Python) or a sample React connect call. Which would you prefer? Sources: Generating tokens | LiveKit docs | React quickstart | LiveKit docs | Android quickstart | LiveKit docs | Authentication | LiveKit docs
n
I want very basic test agent conversation. Can't i do this without involving backend?
t
You cannot run a LiveKit agent or securely create access tokens purely from the frontend. Agents must run on the backend (they use the
livekit-server-sdk
and receive job assignments), and tokens must be generated server-side using your API key/secret — those secrets must never be exposed in browser code. Options for a very quick test without building a full backend: • Use LiveKit’s sandbox token server for demos (issue tokens from a temporary/dev server). This avoids exposing secrets in your frontend. • Run a minimal local token server for testing (example below). It’s a tiny backend just to mint tokens and return them; frontend requests the token and calls
Room.connect()
. Minimal Node example (for local testing):
Copy code
// Install: npm install @livekit/server-sdk express
const express = require('express');
const { AccessToken } = require('@livekit/server-sdk');

const apiKey = 'API_KEY';
const apiSecret = 'API_SECRET';

const app = express();
app.get('/token', (req, res) => {
  const at = new AccessToken(apiKey, apiSecret, { identity: 'test-user' });
  at.addGrant({ room: '*' });
  res.json({ token: at.toJwt() });
});
app.listen(3000);
Frontend flow: 1. Fetch token from your token endpoint:
GET /token
. 2. Use the token with the React SDK:
room = await connect(url, token)
and interact. If you want, I can: • Provide a complete Node/Go/Python token-server snippet tailored to your environment. • Show the minimal React code to fetch the token and connect. Which would you like?