Skip to content

Getting Started

You need a paid Apple Developer Program membership ($99/yr).

  1. Go to the Apple Developer Certificates, Identifiers & Profiles page.

  2. Click KeysCreate a new key.

  3. Enable MusicKit under Services.

  4. Download the .p8 file. You can only download it once, so keep it safe.

  5. Note the Key ID and your Team ID (found in your account’s membership details).

Terminal window
npm install node-musickit-api

Never hardcode your credentials. Use environment variables or a gitignored file:

// ✅ Recommended: environment variables
import { MusicKit } from "node-musickit-api"
const musicKit = new MusicKit({
key: {
id: process.env.MUSICKIT_KEY_ID!,
teamId: process.env.MUSICKIT_TEAM_ID!,
p8: process.env.MUSICKIT_P8!
}
})
// ✅ Alternative: read from a gitignored file
import { MusicKit } from "node-musickit-api"
const p8 = await Bun.file("./AuthKey_XXXXXXXX.p8").text()
const musicKit = new MusicKit({
key: {
id: "YOUR_KEY_ID",
teamId: "YOUR_TEAM_ID",
p8
}
})

Add the key file path to .gitignore:

.gitignore
AuthKey_*.p8
await musicKit.auth()

Call auth() before making any requests. It generates a JWT signed with your private key that expires every 180 days. Call auth() again to refresh it.

Verify your token is valid without making a catalog request:

const status = await musicKit.testAuth()
// Returns 200 if the token is valid

testAuth() hits the Apple Music API’s /test endpoint. A 200 response means your credentials are working.

The client sends requests to https://api.music.apple.com/v1 by default. Override baseUrl to route through a proxy or local server:

const musicKit = new MusicKit({ key: { id, teamId, p8 } })
musicKit.baseUrl = "http://localhost:8080/v1"

This is useful for debugging, caching proxies, or environment-specific setups.