Welcome
Music Assistant provides a powerful API to control your music library, manage players, and stream audio. Whether you're building a custom interface, integrating with home automation, or creating a music app, our API gives you complete control.
This documentation will help you get started quickly with examples and best practices.
API Documentation
Explore the Music Assistant API with our documentation tools:
📚 Commands Reference
Complete list of all available commands with parameters, descriptions, working curl examples, and interactive testing
View Commands📊 Schemas Reference
All data models and types with their properties, descriptions, and relationships
View Schemas📘 Swagger UI
Interactive API explorer with OpenAPI specification and "Try it out" functionality
Open Swagger UIQuick Start
WebSocket API (Recommended)
The WebSocket API provides real-time bidirectional communication and automatic event notifications. Perfect for applications that need live updates.
message_id field to match requests with responses.
This allows multiple concurrent requests over the same connection.
HTTP API (RPC)
The HTTP API provides a simple RPC-like interface for executing commands. This allows you to call the same commands available via WebSocket over a simple HTTP POST endpoint. Perfect for one-off commands without needing real-time updates.
message_id field is optional for HTTP requests
since each HTTP request is isolated. The response returns the command result directly.
WebSocket Events
When connected via WebSocket, you automatically receive real-time event notifications for all state changes. No polling required!
🔊 Player Events
player_added- New player discoveredplayer_updated- Player state changedplayer_removed- Player disconnectedplayer_config_updated- Settings changed
🎵 Queue Events
queue_added- New queue createdqueue_updated- Queue state changedqueue_items_updated- Content changedqueue_time_updated- Playback position updated
📚 Library Events
media_item_added- New media addedmedia_item_updated- Metadata updatedmedia_item_deleted- Media removedmedia_item_played- Playback started
⚙️ System Events
providers_updated- Provider status changedsync_tasks_updated- Sync progress updatedapplication_shutdown- Server shutting down
Client Libraries
Don't want to implement the API from scratch? Use our official client libraries:
Python Client
Official Python client library with full type hints and async support:
TypeScript/JavaScript
Reference implementation in the Music Assistant frontend:
Best Practices
✓ Do:
- Use WebSocket API for real-time applications
- Handle connection drops and reconnect automatically
- Subscribe to relevant events instead of polling
- Use unique message IDs for WebSocket commands
- Implement proper error handling
✗ Don't:
- Poll the REST API frequently for updates (use WebSocket events instead)
- Send commands without waiting for previous responses
- Ignore error responses
- Hardcode server URLs (make them configurable)
Authentication
As of API Schema Version 28, authentication is now mandatory for all API access (except when accessed through Home Assistant Ingress).
Authentication Overview
Music Assistant supports the following authentication methods:
- Username/Password - Built-in authentication provider
- Home Assistant OAuth - OAuth flow for HA users (optional)
- Bearer Tokens - Token-based authentication for HTTP and WebSocket
HTTP Authentication Endpoints
The following HTTP endpoints are available for authentication (no auth required):
Using Bearer Tokens
Once you have an access token, include it in all HTTP requests:
WebSocket Authentication
After establishing a WebSocket connection, you must send an
auth command as the first message:
- Short-lived tokens: Created automatically during login. Expire after 30 days of inactivity but auto-renew on each use (sliding expiration window). Perfect for user sessions.
- Long-lived tokens: Created via
auth/token/createcommand. Expire after 10 years with no auto-renewal. Intended for external integrations (Home Assistant, mobile apps, API access).
auth/tokens and auth/token/create WebSocket commands to manage your tokens.
User Management Commands
The following WebSocket commands are available for authentication management:
auth/users- List all users (admin only)auth/user- Get user by ID (admin only)auth/user/create- Create a new user (admin only)auth/user/update- Update user profile, password, or role (admin for other users)auth/user/enable- Enable user (admin only)auth/user/disable- Disable user (admin only)auth/user/delete- Delete user (admin only)auth/tokens- List your tokensauth/token/create- Create a new long-lived tokenauth/token/revoke- Revoke a token
See the Commands Reference for detailed documentation of all auth commands.
Remote Access (WebRTC)
Music Assistant supports remote access via WebRTC, enabling you to connect to your Music Assistant instance from anywhere without port forwarding or VPN configuration.
How It Works
Remote access uses WebRTC technology to establish a secure, peer-to-peer connection between your remote client (PWA) and your local Music Assistant server:
- WebRTC Data Channel: Establishes encrypted connection through NAT/firewalls
- Signaling Server: Cloud-based server coordinates connection setup
- Remote ID: Unique identifier (format: MA-XXXX-XXXX) to connect to your instance
- API Bridge: Remote commands work identically to local WebSocket API
Getting Your Remote ID
Use the remote_access/info WebSocket command to get your Remote ID and connection status:
Connecting Remotely
To connect from outside your local network:
- Get your Remote ID from the
remote_access/infocommand - Open the Music Assistant PWA from any device (https://app.music-assistant.io)
- Enter your Remote ID when prompted
- Authenticate with your username and password (or OAuth)
- Full API access over encrypted WebRTC connection
- Have the Home Assistant integration configured
- Possess an active Home Assistant Cloud subscription
Security
Remote access maintains the same security standards as local access:
- End-to-end encryption: All data encrypted via WebRTC (DTLS/SRTP)
- Authentication required: Same login and token system as local access
- No data inspection: Signaling server cannot decrypt your commands or data
- Role-based access: Admin and user permissions work identically