Setup
To use Spotify features, you need to create a Spotify application and configure your credentials.Create a Spotify App
Go to the Spotify Developer Dashboard and create a new application:
- Click Create App
- Fill in app name and description
- Add redirect URI:
http://localhost:8080/api/spotify/callback - Note your Client ID and Client Secret
Configure credentials
Add your Spotify credentials to Asta’s settings:Or configure via the Settings UI in the Asta web interface.
OAuth Flow
The OAuth connection flow allows Asta to control your Spotify playback.Authorization URL
user-read-playback-state- Read current playbackuser-modify-playback-state- Control playbackuser-read-currently-playing- Get current trackplaylist-read-private- Access private playlistsplaylist-read-collaborative- Access collaborative playlists
Callback Handling
After authorization, Spotify redirects to:Token Refresh
Access tokens expire after 1 hour. Asta automatically refreshes them:If the refresh token is revoked (e.g., user disconnects via Spotify settings), Asta will detect the
invalid_grant error and clear stored tokens, requiring re-authorization.Searching Music
Search for tracks, artists, and playlists using natural language.Track Search
- Track name
- Artist(s)
- Spotify URL
- Track URI (for playback)
Artist Search
Playlist Search
Playback Control
Control Spotify playback across your devices using natural language.Play Music
- Search for the track/artist/playlist
- Detect available Spotify devices
- Prompt for device selection (if multiple devices)
- Start playback
Device Selection
When multiple devices are available:- Device number (e.g.,
2) - Device name (e.g.,
MacBook Pro) - Partial name (e.g.,
macbook)
Playback Commands
Playlists
Manage and play your Spotify playlists.List Your Playlists
Play Playlist
Play Playlist by URI
You can also paste a Spotify playlist link:Create Playlist
Advanced Features
The Spotify service includes enhanced features for better playback experience.Intent-Based Routing
The service uses pattern matching to detect user intent:Retry Mechanism
If playback fails (e.g., no active device), Asta stores a retry request:Album Context Playback
When playing a track, Asta can play it in album context:Implementation Files
The Spotify integration is split across multiple files:backend/app/spotify_client.py
Core Spotify API client:
- Token management (Client Credentials & OAuth)
- Search (tracks, artists, playlists)
- Playback control (play, pause, skip, volume)
- Device management
- Current playback status
backend/app/services/spotify_service.py
High-level service layer:
- Natural language intent parsing
- Device selection flow
- Retry mechanism
- Enhanced playlist matching
- Album context playback
- Recommendations queueing
Configuration Options
Best Practices
Keep Spotify app open
For playback control to work, you need at least one active Spotify device:
- Open Spotify on your phone, computer, or speaker
- Asta will detect available devices automatically
Use specific commands
More specific commands work better:
- ✅
play bohemian rhapsody by queen - ✅
play my playlist workout - ❌
play music(too vague)
Reconnect if needed
If Asta says “I need to reconnect to Spotify”:
- Go to Settings > Spotify
- Click Disconnect, then Connect again
- This refreshes the OAuth tokens
Troubleshooting
Connection Issues
Error:Spotify is not connected
Solution: Go to Settings > Spotify and click “Connect Spotify”
Error:
I need to reconnect to Spotify
Solution: Your refresh token expired. Disconnect and reconnect in Settings.
Error:
Token expired. Please reconnect in Settings.
Solution: OAuth tokens are invalid. Reconnect your Spotify account.
Playback Issues
Error:No active Spotify devices found
Solution:
- Open Spotify on any device (phone, computer, speaker)
- Play something briefly to activate the device
- Try your command again, or say “done” to retry
Error:
Failed to play
Solution:
- Check if the device is still active
- Verify Spotify Premium (free accounts have limited API access)
- Check device volume and connectivity
Search Issues
Error:I couldn't find 'X' on Spotify
Solution:
- Check spelling of track/artist name
- Try a different query (e.g., include artist name)
- Verify the content exists on Spotify
Playlist Issues
Error:I couldn't find playlist 'X'
Solution:
- List your playlists to see exact names
- Use the full playlist name or paste the Spotify link
- Check that the playlist is in your library (not just followed)