Introduction
Lavalink provides two primary APIs for controlling audio playback in Discord bots:- REST API - For managing players, loading tracks, and controlling playback
- WebSocket API - For real-time player state updates and event notifications
API Versions
Lavalink uses versioned API endpoints:/v4/*- Current API version (v4.0.0+)/v3/*- Legacy API version (v3.7.0+)/version- Version endpoint (no prefix)
/version endpoint.
Architecture
Core Components
Sessions
A session represents a connection between your client and Lavalink. Each WebSocket connection creates a session with a unique session ID. Sessions can be configured for resuming to maintain playback during reconnections.Players
Players are per-guild entities that manage audio playback. Each guild you want to play audio in requires its own player. Players are created automatically when you update them via the REST API.Tracks
Tracks are audio resources loaded from various sources (YouTube, SoundCloud, etc.). Tracks are identified by a base64-encoded string that contains metadata and playback information.API Endpoints Overview
REST API
| Endpoint Category | Purpose | Examples |
|---|---|---|
| Track API | Load and decode tracks | /v4/loadtracks, /v4/decodetrack |
| Player API | Control playback | /v4/sessions/{sessionId}/players/{guildId} |
| Session API | Manage connections | /v4/sessions/{sessionId} |
| Info API | Server information | /v4/info, /v4/stats |
| RoutePlanner API | IP rotation | /v4/routeplanner/status |
WebSocket API
| OP Type | Purpose | Direction |
|---|---|---|
ready | Connection established | Server → Client |
playerUpdate | Player state updates | Server → Client |
stats | Server statistics | Server → Client |
event | Player/voice events | Server → Client |
Common Data Types
Track Object
Represents an audio track with metadata:Player Object
Represents the current state of a player:Error Handling
All REST endpoints return structured error responses:trace=true as a query parameter to receive stack traces for debugging.
Next Steps
Implementation Guide
Learn how to integrate Lavalink with your Discord bot
Authentication
Set up authentication and secure connections
REST API Reference
Explore REST API endpoints
WebSocket API
Real-time events and updates