The command-line tool
@open-music-sdk/cli is a command you run while you build, not a library you import. It does what your app can't do for you yet:
logingets a Music User Token for your own Apple Music account. It serves a page onlocalhostthat runs Apple's sign-in, opens it in your browser, and keeps the token once Apple has accepted it.tokenprints that token, and nothing else, for another program to read.token --developermints a developer token from your key instead, which lives an hour.doctorasks Apple whether your key works, then whether the kept token does. A401can mean either, and this tells them apart. It prints nothing secret.checkasks the live API, as you, what the SDK takes on trust about it, and prints what Apple did. With--writeit also makes a playlist and adds to your library, and ends with the steps that remove what it added.logoutforgets the kept token.
It reads your key and its IDs from APPLE_MUSIC_PRIVATE_KEY, APPLE_MUSIC_TEAM_ID and APPLE_MUSIC_KEY_ID, the variables these docs use, so with those set it needs no flags. A value it can't find, it asks for. You also need Node 24 or newer, and an Apple Account with an Apple Music subscription to sign in with.
To use your own account from a script, sign in once, then hand the token to the script in an environment variable. On your machine:
open-music-sdk login
APPLE_MUSIC_USER_TOKEN=$(open-music-sdk token) node job.jsIn job.js, music.as(process.env.APPLE_MUSIC_USER_TOKEN) gives a client that acts for you.
Add the CLI to your project as a dev dependency and run it with pnpm exec. Or run it once with npx, pinned to a version: unpinned, npx runs whatever is newest, with your key in reach.
pnpm add -D @open-music-sdk/cli
pnpm exec open-music-sdk doctor
npx @open-music-sdk/cli@<version> loginopen-music-sdk --help lists every command, and open-music-sdk help <command> gives a command's options. The CLI's README covers where it finds your key and where it keeps the token: in one file in your user profile, readable by you alone and not encrypted, until logout forgets it. On your machine, with the CLI explains how login keeps the sign-in safe.
The token the CLI keeps is yours. Your listeners' tokens come from their own sign-in in your app: see Sign a listener in.