Elixir client for the Apple Music API.
The public surface is intentionally small:
AppleMusicAPI.search_catalog("The Beatles", types: ["songs", "albums"])
AppleMusicAPI.get_song("123456789")
AppleMusicAPI.get_album("987654321")
AppleMusicAPI.get_artist("111111111")
AppleMusicAPI.get_playlist("222222222")
AppleMusicAPI.get_songs_by_isrc("USUG12002836")
AppleMusicAPI.get_user_playlists()
AppleMusicAPI.token()Configuration
config :apple_music_api,
team_id: System.get_env("APPLE_TEAM_ID"),
key_id: System.get_env("MUSIC_KEY_ID"),
private_key: System.get_env("MUSIC_PRIVATE_KEY"),
base_url: "https://api.music.apple.com",
storefront: "us",
token_ttl_seconds: 600Every function also accepts per-call opts that override the application config.
Summary
Functions
Add a resource to the user's library (requires user token).
Get an album by ID.
Get multiple albums by IDs.
Get an artist by ID.
Get multiple artists by IDs.
Get charts for a specific type (songs, albums, playlists).
Get a playlist by ID.
Get multiple playlists by IDs.
Get recommendations for the user (requires user token).
Get a song by ID.
Get multiple songs by IDs.
Get a song by ISRC (International Standard Recording Code).
Get the user's library albums (requires user token).
Get the user's library artists (requires user token).
Get tracks from the user's library playlist (requires user token).
Get the user's library playlists (requires user token).
Get the user's library songs (requires user token).
List all genres available in the catalog.
Search the Apple Music catalog.
Return a cached-per-call Apple Music access token (after the JWT → token exchange).
Types
Functions
Add a resource to the user's library (requires user token).
Parameters
ids: Map of type to list of IDs, e.g.,%{songs: ["123"], albums: ["456"]}opts::user_token- User MusicKit token (required)
Examples
AppleMusicAPI.add_to_library(%{songs: ["123456789"]})
Get an album by ID.
Parameters
id: Apple Music album IDopts: Optional:storefrontoverride
Get multiple albums by IDs.
Parameters
ids: List of Apple Music album IDs (max 100)opts: Optional:storefrontoverride
Get an artist by ID.
Parameters
id: Apple Music artist IDopts: Optional:storefrontoverride
Get multiple artists by IDs.
Parameters
ids: List of Apple Music artist IDs (max 100)opts: Optional:storefrontoverride
Get charts for a specific type (songs, albums, playlists).
Parameters
opts::types- List of types to get charts for ["songs", "albums", "playlists"]:storefront- Storefront code:chart- Chart ID (optional)
Examples
AppleMusicAPI.get_charts(types: ["songs", "albums"])
Get a playlist by ID.
Parameters
id: Apple Music playlist IDopts: Optional:storefrontoverride
Get multiple playlists by IDs.
Parameters
ids: List of Apple Music playlist IDs (max 100)opts: Optional:storefrontoverride
Get recommendations for the user (requires user token).
Parameters
opts::user_token- User MusicKit token (required):limit- Maximum results (default 10)
Get a song by ID.
Parameters
id: Apple Music song IDopts: Optional:storefrontoverride
Get multiple songs by IDs.
Parameters
ids: List of Apple Music song IDs (max 100)opts: Optional:storefrontoverride
Get a song by ISRC (International Standard Recording Code).
Parameters
isrc: ISRC code (e.g., "USUG12002836")opts: Optional:storefrontoverride
Get the user's library albums (requires user token).
Parameters
opts::user_token- User MusicKit token (required):limit- Maximum results (default 25):offset- Pagination offset
Get the user's library artists (requires user token).
Parameters
opts::user_token- User MusicKit token (required):limit- Maximum results (default 25):offset- Pagination offset
Get tracks from the user's library playlist (requires user token).
Parameters
playlist_id: Library playlist IDopts::user_token- User MusicKit token (required):limit- Maximum results (default 25)
Get the user's library playlists (requires user token).
Parameters
opts::user_token- User MusicKit token (required):limit- Maximum results (default 25):offset- Pagination offset
Get the user's library songs (requires user token).
Parameters
opts::user_token- User MusicKit token (required):limit- Maximum results (default 25):offset- Pagination offset
List all genres available in the catalog.
Parameters
opts: Optional:storefrontoverride
Search the Apple Music catalog.
Parameters
term: Search query termopts::types- List of resource types to search ("songs", "albums", "artists", "playlists"):limit- Maximum results per type (1-25, default 5):offset- Pagination offset:storefront- Storefront code (default from config or "us")
Examples
AppleMusicAPI.search_catalog("The Beatles", types: ["songs", "albums"])
AppleMusicAPI.search_catalog("rock", types: ["playlists"], limit: 10)
Return a cached-per-call Apple Music access token (after the JWT → token exchange).