Install
openclaw skills install spotify-controllerControl Spotify playback and devices from an AI agent using spotify.py and the official Spotify Web API. Use when users ask to check current track, play/paus...
openclaw skills install spotify-controllerControl Spotify playback from your AI agent using the official Spotify Web API.
This works across setups (local machine, Docker, VPS, and hybrid environments). It is especially useful for fixing Spotify control pain in headless VPS deployments. The server does not need a browser or a local Spotify client.
spotify.pyplay, pause, next, prev)search) and quick play (playsearch)playtrack spotify:track:...)devices, setdevice)volume 0-100, where supported)requests package installedSPOTIFY_CLIENT_IDSPOTIFY_CLIENT_SECRETSPOTIFY_REFRESH_TOKENInstall dependency:
uv pip install requests --system
(Alternative: pip install requests)
If you build OpenClaw in Docker, add this to your Dockerfile when requests is not already present:
RUN uv pip install requests --system
http://127.0.0.1:8888/callbackOpen this URL in your browser (replace YOUR_CLIENT_ID):
https://accounts.spotify.com/authorize?client_id=YOUR_CLIENT_ID&response_type=code&redirect_uri=http://127.0.0.1:8888/callback&scope=user-modify-playback-state%20user-read-playback-state%20user-read-currently-playing
Approve access, then copy the code value from the redirected URL.
Exchange code for tokens:
curl -s -X POST "https://accounts.spotify.com/api/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=authorization_code&code=YOUR_CODE&redirect_uri=http://127.0.0.1:8888/callback&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET"
From response JSON, copy refresh_token.
refresh_tokenis typically long-lived, but can be invalidated if app access is revoked, app settings change, or credentials rotate.
.envSPOTIFY_CLIENT_ID=your_client_id
SPOTIFY_CLIENT_SECRET=your_client_secret
SPOTIFY_REFRESH_TOKEN=your_refresh_token
In docker-compose.yml service environment: section:
- SPOTIFY_CLIENT_ID=${SPOTIFY_CLIENT_ID}
- SPOTIFY_CLIENT_SECRET=${SPOTIFY_CLIENT_SECRET}
- SPOTIFY_REFRESH_TOKEN=${SPOTIFY_REFRESH_TOKEN}
docker compose down
docker compose up -d openclaw-gateway
chown <runtime_user>:<runtime_group> /path/to/workspace/spotify.py
chmod 664 /path/to/workspace/spotify.py
Run commands from workspace:
python3 spotify.py <command>
| Command | Description |
|---|---|
python3 spotify.py status | Show current playback state and track |
python3 spotify.py play | Resume playback |
python3 spotify.py pause | Pause playback |
python3 spotify.py next | Skip to next track |
python3 spotify.py prev | Go to previous track |
python3 spotify.py volume 80 | Set volume (0–100) where supported |
python3 spotify.py search track | Search tracks (top results) |
python3 spotify.py playsearch "track" | Search and play first result |
python3 spotify.py playtrack spotify:track:URI | Play specific track URI |
python3 spotify.py devices | List available Spotify devices |
python3 spotify.py setdevice "BEDROOM-SPEAKER" | Set active device by name or id |
If you see NO_ACTIVE_DEVICE:
python3 spotify.py devices403 Restriction violated for play, prev, or other controls.VOLUME_CONTROL_DISALLOW).status after transfer may briefly show stale state.These are Spotify-side constraints, not necessarily script bugs.
.env with live secrets.python3 spotify.py devices shows your target device?