Last.fm API
Music metadata, scrobbling, artist info and charts.
What it does
The Last.fm API exposes scrobbling data and music metadata: artist, album and track info, similar artists, tags, global and per-user charts, and a user’s listening history and loved tracks. Read methods are simple GET calls; scrobbling requires a signed session.
Base URL
Authentication
Register for a free API key and pass it as &api_key=YOUR_KEY with &format=json and a &method=. Write methods (scrobble, love) need a user session key plus an MD5 api_sig of the sorted parameters.
Code examples
curl -s "https://ws.audioscrobbler.com/2.0/?method=artist.getinfo"\ "&artist=Bjork&api_key=$LASTFM_KEY&format=json"
import requests
r = requests.get("https://ws.audioscrobbler.com/2.0/", params={
"method": "user.getrecenttracks", "user": "rj",
"api_key": KEY, "format": "json", "limit": 5}, timeout=10)
for t in r.json()["recenttracks"]["track"]:
print(t["artist"]["#text"], "-", t["name"])Rate limits & quotas
Guideline of roughly 5 requests/second per IP for read methods; sustained heavier use can get your key throttled or revoked. Errors come back as JSON with an error code and message, sometimes with HTTP 200.
Key response fields
| artist.stats.listeners / playcount | Popularity for artist.getinfo |
| toptracks.track[] | Ranked tracks with playcount |
| recenttracks.track[] | A user’s scrobbles, newest first |
| @attr.nowplaying | Present on the currently-playing track |
| error / message | Non-zero code means the call failed |
Common errors
| error 10 | Invalid API key. |
| error 6 | Invalid parameters — e.g. unknown user or missing artist. |
| error 29 | Rate limit exceeded — slow down. |
| error 17 | User has their listening data set to private. |
When to use it (and alternatives)
Best for listening-history features, music discovery (similar artists, tags) and charts. For catalogue metadata with stable IDs use MusicBrainz; for previews and playback use Spotify or Deezer.
FAQ
Can I read someone's scrobbles without their permission?
Yes, if their profile is public — user.getrecenttracks and friends work with just your API key. Private profiles return error 17.
Do I need the shared secret?
Only for authenticated write methods (scrobble, love/unlove) and for creating a user session. Plain reads need just the api_key.
Why is artist data sometimes missing or merged oddly?
Last.fm keys metadata on name strings, so different artists with the same name can collide. Use the mbid parameter (a MusicBrainz ID) when you have one for exact matches.
New to APIs?
Short guides for working with this API — and any other.