Spotify

Enable an Agent to search Spotify for tracks, artists, and albums with a read-only toolkit configuration.

SpotifyTools enable an Agent to search Spotify's catalog and access authenticated-user playback data.

Prerequisites

The example requires a Spotify access token from Spotify and an Anthropic API key. It enables only catalog search, so the Spotify token does not need playlist modification scopes.

uv pip install -U agno anthropic
export SPOTIFY_TOKEN=***
export ANTHROPIC_API_KEY=***

Spotify changed several endpoints and response fields for Development Mode apps in February 2026. Extended Quota Mode apps are unaffected. The current Agno adapter still uses the earlier paths and fields, so the affected methods below are unavailable to Development Mode apps. Use the read-only example until SpotifyTools is updated. See Spotify's February 2026 migration guide.

Example

The following agent searches Spotify for tracks and returns their names and URIs.

cookbook/91_tools/spotify_tools.py
from os import getenv

from agno.agent import Agent
from agno.models.anthropic import Claude
from agno.tools.spotify import SpotifyTools

# Your Spotify access token (get one from https://developer.spotify.com)
SPOTIFY_TOKEN = getenv("SPOTIFY_TOKEN")

# Initialize the Spotify toolkit
spotify = SpotifyTools(
    access_token=SPOTIFY_TOKEN,
    default_market="US",
    include_tools=["search_tracks"],
)

# Create an agent with the Spotify toolkit
agent = Agent(
    name="Spotify DJ",
    model=Claude(id="claude-sonnet-5"),
    tools=[spotify],
    instructions=[
        "Search Spotify for tracks that match the request.",
        "Return each track's name, artists, and Spotify URI.",
    ],
    markdown=True,
)

response = agent.run("Find five tracks by The Weeknd.")
print(response.content)

Toolkit Params

ParameterTypeDefaultDescription
access_tokenstr-Spotify OAuth access token with required scopes.
default_marketOptional[str]"US"Default market/country code for search results.
timeoutint30Request timeout in seconds.

Toolkit Functions

FunctionDescription
search_tracksSearch for tracks on Spotify
search_playlistsUnavailable to Development Mode apps in the current Agno adapter because it expects the earlier playlist response fields
search_artistsSearch for artists on Spotify
search_albumsSearch for albums on Spotify
get_user_playlistsUnavailable to Development Mode apps in the current Agno adapter because it expects the earlier response fields
get_track_recommendationsRestricted for new and Development Mode apps by Spotify's November 2024 API changes; requires eligible prior access.
get_artist_top_tracksUnavailable to Development Mode apps because Spotify removed the endpoint
get_album_tracksGet tracks from a specific album
get_my_top_tracksGet current user's top tracks
get_my_top_artistsGet current user's top artists
create_playlistUnavailable to Development Mode apps in the current Agno adapter because it calls the removed user-specific endpoint
add_tracks_to_playlistUnavailable to Development Mode apps in the current Agno adapter because it calls the removed /tracks endpoint
get_playlistFor Development Mode apps, use include_tracks=False; item parsing expects the earlier field names
update_playlist_detailsUpdate playlist name, description, or other details
remove_tracks_from_playlistUnavailable to Development Mode apps in the current Agno adapter because it calls the removed /tracks endpoint
get_current_userGet current user's profile information
play_trackStart or resume playback (requires an active Spotify session)
get_currently_playingGet information about currently playing track

Development Mode setup

Development Mode apps require their owner to have Spotify Premium. Keep search requests at 10 results or fewer: the current Development Mode endpoint rejects higher limits even though the Agno method permits up to 50. The example's five-track request fits that limit. Extended Quota Mode apps are unaffected by the February 2026 migration described above.

Developer Resources