Getting Started with the Audius SDK
Overviewβ
The Audius JavaScript (TypeScript) SDK allows you to easily interact with the Audius protocol. Use the SDK to:
- π Search and display users, tracks, and playlists
- π΅ Stream and upload tracks
- β€οΈΒ Favorite, repost, and curate playlists
- βοΈ Allow your users to log in with their Audius account and act on their behalf
...and much more!
API Plansβ
Audius offers two API plans:
| Plan | Rate Limit | Monthly Requests |
|---|---|---|
| Free | 10 requests/second | 500,000 requests/month |
| Unlimited | Unlimited | Unlimited |
The Free plan is always free with no restrictions. For higher limits and support, contact [email protected] about the Unlimited plan.
Get Your API Key and Bearer Tokenβ
-
Visit the Audius API Plans page and click "Create API Key" to generate your credentials.
-
You will receive an API Key and a Bearer Token. Save both securely β treat them like passwords.
The bearer token is the recommended way to authenticate with the Audius API.
Install the SDKβ
Node.jsβ
If your project is in a Node.js environment, run this in your terminal:
npm install @audius/sdk
HTML + JSβ
Otherwise, include the SDK script tag in your web page. The Audius SDK will then be assigned to
window.audiusSdk.
<script src="https://cdn.jsdelivr.net/npm/@audius/sdk@latest/dist/sdk.min.js"></script>
Initialize the SDKβ
Initialize the SDK with your API key and bearer token.
Node.js exampleβ
import { sdk } from '@audius/sdk'
const audiusSdk = sdk({
apiKey: 'Your API Key goes here',
bearerToken: 'Your Bearer Token goes here',
})
HTML + JS exampleβ
const audiusSdk = window.audiusSdk({
apiKey: 'Your API Key goes here',
})
DO NOT include the bearer token if you are running the SDK in the browser or anywhere on the client. The bearer token is what allows your app to write on behalf of the users that have authorized it to do so. Keep your bearer token secure and never expose it in client-side code that could be inspected.
Make your first API call using the SDK!β
Once you have the initialized SDK instance, it's smooth sailing to making your first API calls.
// Fetch your first track!
const track = await audiusSdk.tracks.getTrack({ trackId: 'D7KyD' })
console.log(track, 'Track fetched!')
// Favorite a track
const userId = (
await audiusSdk.users.getUserByHandle({
handle: 'Your Audius handle goes here',
})
).data?.id
await audiusSdk.tracks.favoriteTrack({
trackId: 'D7KyD',
userId,
})
Full Node.js exampleβ
import { sdk } from '@audius/sdk'
const audiusSdk = sdk({
apiKey: 'Your API Key goes here',
bearerToken: 'Your Bearer Token goes here',
})
const track = await audiusSdk.tracks.getTrack({ trackId: 'D7KyD' })
console.log(track, 'Track fetched!')
const userId = (
await audiusSdk.users.getUserByHandle({
handle: 'Your Audius handle goes here',
})
).data?.id
await audiusSdk.tracks.favoriteTrack({
trackId: 'D7KyD',
userId,
})
console.log('Track favorited!')
Full HTML + JS exampleβ
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@audius/sdk@latest/dist/sdk.min.js"></script>
<script>
const fn = async () => {
const audiusSdk = window.audiusSdk({
apiKey: 'Your API Key goes here',
})
const track = await audiusSdk.tracks.getTrack({ trackId: 'D7KyD' })
console.log(track, 'Track fetched!')
}
fn()
</script>
</head>
<body>
<h1>Example content</h1>
</body>
</html>
What's next?β
-
Get authorization to access your app's users' Audius accounts
-
Explore the API docs to see what else you can do with the Audius SDK
Direct API Accessβ
You can also access the Audius API directly without the SDK:
REST API:
curl -X GET "https://api.audius.co/v1/tracks/trending" \
-H "Authorization: Bearer <YOUR-API-BEARER-TOKEN>"
gRPC:
grpcurl -H "authorization: Bearer <YOUR-API-BEARER-TOKEN>" \
grpc.audius.co:443 list
For more details, visit the API documentation or the Swagger definition.