Authenticate with LiveKit Server APIs
mainThe LiveKitAPI client supports two authentication modes:
- API Key & Secret: Recommended for backend services. The SDK signs requests using your credentials. You can provide these via environment variables (
LIVEKIT_URL,LIVEKIT_API_KEY,LIVEKIT_API_SECRET) or explicitly via functional options. - Access Token: Used for client-side/frontend scenarios where you want to use a pre-signed token. Pass the token using
lksdk.WithToken("token").
Explicitly provided values take precedence over environment variables.
// Backend (API key & secret) using environment variables or explicit options
api, _ := lksdk.NewLiveKitAPI(lksdk.WithURL(hostURL), lksdk.WithAPIKey("api-key", "api-secret"))
// Frontend (pre-signed access token)
api, _ := lksdk.NewLiveKitAPI(lksdk.WithToken("token"))