LiveKit LogoDocs

Generating tokens

On this page

1. Install Livekit Server SDK2. Keys and Configuration3. Make an endpoint that returns a token4. Create a client app to connect
Sign in with Cloud

In order for client apps to connect to LiveKit rooms, they need a token generated by your backend server. In this guide, we'll walk through how to set up a server to generate tokens for your clients.

1. Install Livekit Server SDK

go get

2. Keys and Configuration

Create a new file at development.env and with your API Key and Secret:

export LK_API_KEY=<API Key>
export LK_API_SECRET=<API Secret hidden>

3. Make an endpoint that returns a token

Create a server:

// server.go
import (
lksdk ""
func getJoinToken(room, identity string) string {
config = readFile(config)
at := auth.NewAccessToken(os.GetEnv("LK_API_KEY"), os.GetEnv("LK_API_SECRET"))
grant := &auth.VideoGrant{
RoomJoin: true,
Room: room,
return at.ToJWT()
func main() {
http.HandleFunc("/getToken", func(w http.ResponseWriter, r *http.Request) {
w.write(getJoinToken("my-room", "identity"))
log.Fatal(http.ListenAndServe(":8080", nil))

Load the environment variables and run the server:

$ source development.env
$ go run server.go

4. Create a client app to connect

Create a client app that fetches a token from the server we just made, then uses it to connect to a LiveKit room:


Chevron IconClient: Handling Events
LiveKit logo






GitHub LogoSlack Logo