Query historical stream totals & daily deltas on any track or album you want. Start tracking new, missing, or niche songs/albums by crafting your own tracking playlist.
Note: The entire streamcounts.xyz backend, SQLite tracking engine, and API were manually built from scratch.
The database tracks exact Spotify URIs. Different album versions (Standard vs. Deluxe vs. Single) maintain separate database entries unless aggregated.
To track missing songs or ensure an artist's full catalog is indexed, put the tracks in a public Spotify playlist and submit its ID to /api/v1/new-playlist/:id.
In track responses, the album and artists fields are returned as escaped JSON strings. Always run JSON.parse() on them in your client!
Copy this prompt and paste it directly into ChatGPT, Claude, Cursor, or Gemini along with your project context to automatically wire up this API.
I want you to integrate the streamcounts.xyz Open Spotify Stream Tracking API into my application.
### API Base URL
Use `https://streamcounts.xyz` (or configure via an environment variable like `API_BASE_URL`). No API key or authentication headers are required.
### Core Rules & Data Parsing Requirements (CRITICAL)
1. **URI Sensitivity:** All IDs are standard 22-character Spotify Base62 IDs (e.g., `6LqNN22kT3074XbTVUrhzX`).
2. **Double-Parse Stringified JSON Fields:** In endpoints returning track objects (`/artist-tracks`, `/album-tracks`, `/track-details`), the `album` and `artists` properties are returned as **JSON-encoded strings** rather than native objects/arrays. You MUST wrap them in `JSON.parse()` (with a fallback try/catch) before accessing `album.cover`, `album.name`, or mapping over `artists` (`role: "0"` = primary artist, `role: "1"` = featured artist).
3. **Album Track Completeness:** `/api/v1/album-tracks/:id` may return tracks out of tracklist order. Always cross-reference the array length against `album.track_count` from `/api/v1/album/:id` to verify if all tracks on that URI are tracked.
4. **Error Handling:** Missing resources return HTTP 200 with `"typename": "__notFound"` and a `message` field. Check `data.typename === "__notFound"` in your fetch wrapper.
### Available Endpoints
1. **Get Artist Info**
- `GET https://streamcounts.xyz/api/v1/artist/:artistId`
- Success (`typename: "__artist"`): `{ typename, artist: { id, name } }`
2. **Get All Tracked Songs for an Artist (Auto-Deduped)**
- `GET https://streamcounts.xyz/api/v1/artist-tracks/:artistId`
- Success (`typename: "__artistTracks"`): `{ typename, tracks: [{ id, name, total, daily, date, album (JSON string), artists (JSON string) }] }`
3. **Get Album Overview & Aggregate Streams**
- `GET https://streamcounts.xyz/api/v1/album/:albumId`
- Success (`typename: "__albumOverview"`): `{ typename, album: { album (JSON string), total, daily, track_count } }`
4. **Get Album Tracklist with Stream Counts**
- `GET https://streamcounts.xyz/api/v1/album-tracks/:albumId`
- Success (`typename: "__albumTracks"`): `{ typename, tracks: [{ id, name, total, daily, date, artists (JSON string) }] }`
5. **Get Historical Daily Stream Time-Series for a Track**
- `GET https://streamcounts.xyz/api/v1/track-history/:trackId`
- Success (`typename: "__trackHistory"`): `{ typename, data: [{ total, daily, date }] }` (Ordered newest to oldest)
6. **Get Single Track Details**
- `GET https://streamcounts.xyz/api/v1/track-details/:trackId`
- Success (`typename: "__track"`): `{ typename, track: { id, name, total, daily, date, artist_name, artists (JSON string), album (JSON string) } }`
7. **Submit a Public Playlist to Ingest/Track New Songs**
- `GET https://streamcounts.xyz/api/v1/new-playlist/:playlistId`
- Helper note: Extract the 22-character playlist ID if the user pastes a full `open.spotify.com/playlist/...` URL. Playlist MUST be public.
- Response (`typename: "__playlistAddResponse"`): `{ typename, message }`
### Your Task
Create a clean, typed API client/service module in my codebase with helper functions for all 7 endpoints above, automatically parsing the stringified `album` and `artists` fields, handling `__notFound` responses, and including a URL-to-ID parser for submitting playlists.
Base URL: https://streamcounts.xyz • All endpoints return application/json with a root typename discriminator.
/api/v1/artist/:id
{
"typename": "__artist",
"artist": {
"id": "6LqNN22kT3074XbTVUrhzX",
"name": "Kesha"
}
}
{
"typename": "__notFound",
"message": "Artist with that id could not be found.",
"artist": {}
}
/api/v1/artist-tracks/:id
/api/v1/new-playlist/:id.
{
"typename": "__artistTracks",
"tracks": [
{
"id": "0BMgkRvlTsZrit5S1ysx4n",
"name": "TiK ToK",
"total": 2003084336,
"daily": 780403,
"date": "2026-11-28",
"album": "{\"id\":\"5hs0wQFqXp1fNdkchK5wyE\",\"name\":\"Animal\",\"cover\":\"https://...\"}",
"artists": "[{\"id\":\"6LqNN22kT3074XbTVUrhzX\",\"name\":\"Kesha\",\"role\":\"0\"}]"
}
]
}
{
"typename": "__notFound",
"message": "Artist with that id could not be found.",
"tracks": []
}
/api/v1/album/:id
{
"typename": "__albumOverview",
"album": {
"album": "{\"id\":\"6fpLLJsDSSAlToEDW2jv4F\",\"name\":\"Animal (Expanded Edition)\",\"cover\":\"https://...\"}",
"total": 3520342140,
"daily": 1425075,
"track_count": 18
}
}
/api/v1/album-tracks/:id
tracks.length against track_count from /api/v1/album/:id.
{
"typename": "__albumTracks",
"tracks": [
{
"id": "0HPD5WQqrq7wPWR7P7Dw1i",
"name": "TiK ToK",
"total": 2003084336,
"daily": 780403,
"date": "2026-11-28",
"artists": "[{\"id\":\"6LqNN22kT3074XbTVUrhzX\",\"name\":\"Kesha\",\"role\":\"0\"}]"
}
]
}
/api/v1/track-history/:id
{
"typename": "__trackHistory",
"data": [
{
"total": 358176562,
"daily": 189552,
"date": "2026-11-28"
},
{
"total": 357987010,
"daily": 190001,
"date": "2026-11-27"
}
]
}
/api/v1/track-details/:id
{
"typename": "__track",
"track": {
"id": "0WCiI0ddWiu5F2kSHgfw5S",
"name": "Take It Off",
"total": 358176562,
"daily": 189552,
"date": "2026-11-28",
"artist_name": "kesha",
"artists": "[{\"id\":\"6LqNN22kT3074XbTVUrhzX\",\"name\":\"Kesha\",\"role\":\"0\"}]",
"album": "{\"id\":\"6fpLLJsDSSAlToEDW2jv4F\",\"name\":\"Animal (Expanded Edition)\",\"cover\":\"https://...\"}"
}
}
/api/v1/new-playlist/:id
{
"typename": "__playlistAddResponse",
"message": "Added playlist to database. If it is not a valid playlist id, it will not work."
}