Open source SoundCloud libraries
To build the sub delta we needed a typed SoundCloud API client, a sign-in flow that works on Next.js, and a player we could control from React. None of the existing options did the job, so we wrote them. All three are MIT licensed, published on npm, and running in production on this site every day.
| Library | What it is for | Works with |
|---|---|---|
| soundcloud-api-ts | TypeScript client for the official SoundCloud API | Node.js 20 or later, and any runtime with fetch |
| soundcloud-api-ts-next | React hooks and Next.js route handlers for SoundCloud | Next.js 13 to 16, React 18 or 19 |
| soundcloud-widget-react | React component for the SoundCloud HTML5 Widget | React 17 or later |
soundcloud-api-ts
TypeScript client for the official SoundCloud API
Tracks, users, playlists, search and the signed-in user's endpoints, fully typed. It uses SoundCloud's documented API with registered app credentials and OAuth 2.1 with PKCE. No runtime dependencies: it runs on native fetch. It retries on rate limits and server errors, paginates for you, and ships a command-line tool.
Where we use it: Every SoundCloud call our discovery engine makes goes through this client, including token refresh.
npm install soundcloud-api-tsimport { SoundCloudClient } from "soundcloud-api-ts";
const sc = new SoundCloudClient({
clientId: process.env.SOUNDCLOUD_CLIENT_ID!,
clientSecret: process.env.SOUNDCLOUD_CLIENT_SECRET!,
});
const token = await sc.auth.getClientToken();
sc.setToken(token.access_token, token.refresh_token);
const results = await sc.search.tracks("electronic");soundcloud-api-ts-next
React hooks and Next.js route handlers for SoundCloud
Typed React hooks that fetch through your own Next.js API routes, so the client secret never reaches the browser. It includes the SoundCloud OAuth sign-in flow with PKCE and a cookie-based PKCE store that works on serverless hosts. It supports the App Router and the Pages Router.
Where we use it: Sign in with SoundCloud on this site runs on it.
npm install soundcloud-api-ts-next// app/api/soundcloud/[...route]/route.ts
import { createSoundCloudRoutes } from "soundcloud-api-ts-next/server";
const sc = createSoundCloudRoutes({
clientId: process.env.SOUNDCLOUD_CLIENT_ID!,
clientSecret: process.env.SOUNDCLOUD_CLIENT_SECRET!,
redirectUri: process.env.SOUNDCLOUD_REDIRECT_URI,
});
const handler = sc.handler();
export const GET = handler;
export const POST = handler;
export const DELETE = handler;soundcloud-widget-react
React component for the SoundCloud HTML5 Widget
A typed React wrapper around SoundCloud's embeddable player. It gives you promise-based getters, a hook for playback state, and a hidden-player mode for building your own audio controls. It is safe to render on the server and has no runtime dependencies.
Where we use it: The player bar at the bottom of this site is built on it.
npm install soundcloud-widget-reactimport { SCWidget } from "soundcloud-widget-react";
export default function Player() {
return (
<SCWidget
trackId={308946187}
autoPlay={false}
onPlay={(event) => console.log("Playing at", event.currentPosition)}
onFinish={() => console.log("Track finished")}
/>
);
}How they fit together
soundcloud-api-ts is the base. soundcloud-api-ts-next is built on it and adds the Next.js and React layer. soundcloud-widget-react is separate and only handles playback. A typical app uses the first two to fetch data and sign users in, and passes a track id from the API to the widget to play it. That is how this site works.
Why we publish them
The SoundCloud developer ecosystem is small, and most older libraries predate SoundCloud's current OAuth requirements. We fix problems in these libraries when we hit them in production, and everyone else building on SoundCloud gets the fix. Issues and pull requests are welcome on GitHub.
If you are here for the music and not the code, start with how to find new music on SoundCloud or see what the engine has found on You Were Early.
Questions
Is there a TypeScript client for the SoundCloud API?+
Yes. soundcloud-api-ts is a typed client for SoundCloud's official API with OAuth 2.1 and PKCE, no runtime dependencies, and an MIT license. It is built and maintained by the sub delta.
How do I add Sign in with SoundCloud to a Next.js app?+
soundcloud-api-ts-next provides the route handlers and the OAuth flow with PKCE, and keeps the client secret on the server. On serverless hosts use its cookie-based PKCE store, because the sign-in start and the callback can run on different instances.
How do I control the SoundCloud player from React?+
soundcloud-widget-react wraps the SoundCloud HTML5 Widget in a typed component with a ref, promise-based getters and a hook for playback state.
Are these libraries official SoundCloud products?+
No. They are independent open source projects built on SoundCloud's public API and widget. Neither they nor the sub delta are affiliated with SoundCloud.
Do I need a SoundCloud API key?+
The API client and the Next.js package need a client ID and secret from a registered SoundCloud app. The widget component does not.