Overview
Lavalink uses password-based authentication to secure both REST and WebSocket connections. All API requests must include the configured password in theAuthorization header.
Setting the Password
Configure the password in your Lavalink server’sapplication.yml:
application.yml
REST API Authentication
All REST endpoints (except/version) require the Authorization header.
Required Header
Example Request
Unauthorized Response
If authentication fails, Lavalink returns a401 Unauthorized response:
WebSocket Authentication
WebSocket connections require authentication headers during the initial handshake.Required Headers
When establishing a WebSocket connection to/v4/websocket, include these headers:
| Header | Description | Required | Example |
|---|---|---|---|
Authorization | Your Lavalink password | Yes | youshallnotpass |
User-Id | Discord bot user ID | Yes | 170939974227541168 |
Client-Name | Client identifier in NAME/VERSION format | Yes | my-bot/1.0.0 |
Session-Id | Previous session ID for resuming | No | xtaug914v9k5032f |
Connection Example
Authentication Failure
If WebSocket authentication fails, the connection is immediately closed with a close code indicating the error.Resuming Sessions with Authentication
When resuming a session, include theSession-Id header along with authentication:
Verifying Session Resumption
Check if resumption succeeded via the response header:ready op payload:
If the session ID is invalid or expired, Lavalink creates a new session instead of resuming. Check the
resumed field to confirm.Client Name Format
TheClient-Name header should follow the format NAME/VERSION:
Security Best Practices
Use Strong Passwords
Use Strong Passwords
Generate a cryptographically secure random password:
Store Passwords Securely
Store Passwords Securely
Never hardcode passwords. Use environment variables:
Use TLS/SSL in Production
Use TLS/SSL in Production
For production deployments, use WSS (WebSocket Secure) and HTTPS:
Restrict Network Access
Restrict Network Access
Use firewall rules to limit access to your Lavalink server:
- Only allow connections from your bot server’s IP
- Block public internet access
- Use VPC/private networks when possible
Rotate Passwords Regularly
Rotate Passwords Regularly
Change your Lavalink password periodically:
- Generate a new password
- Update
application.ymlon the server - Restart Lavalink
- Update client configuration
- Restart client applications
Monitor Failed Authentication Attempts
Monitor Failed Authentication Attempts
Check Lavalink logs for repeated authentication failures, which may indicate:
- Misconfigured clients
- Brute force attacks
- Compromised credentials
Multi-Client Authentication
Multiple clients can connect to the same Lavalink server using the same password. Each client receives a unique session ID:Testing Authentication
Verify your authentication is working correctly:Test REST Authentication
Test WebSocket Authentication
Troubleshooting
401 Unauthorized on all requests
401 Unauthorized on all requests
WebSocket connection immediately closes
WebSocket connection immediately closes
Cause: Missing or invalid authentication headersSolution:
- Ensure all three required headers are present
- Verify
User-Idis a valid Discord user ID (numeric string) - Check
Client-NamefollowsNAME/VERSIONformat
Session not resuming
Session not resuming
Cause: Session expired or invalid session IDSolution:
- Check if session timeout was exceeded (default 60s)
- Verify session ID is correct
- Ensure resuming was enabled via Update Session endpoint
- Confirm Lavalink server didn’t restart (sessions don’t persist across restarts)
Cannot access from remote server
Cannot access from remote server
Cause: Lavalink server not binding to public interface or firewall blockingSolution:
- Check
application.ymlserver address:server.address: 0.0.0.0 - Verify firewall allows port 2333
- Test connection:
telnet lavalink-server 2333
Next Steps
Implementation Guide
Build your Lavalink client integration
REST API
Explore authenticated endpoints
WebSocket API
Real-time event streaming
Configuration
Configure Lavalink server settings