@audius/sdk

中文文档
17.0.0发布于 2026/09/25Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 6369

Audius SDK

原始使用文档
文档目录15 节
  1. Overview
  2. API Plans
  3. Get Your API Key
  4. Install the SDK
  5. Node.js
  6. HTML + JS
  7. Initialize the SDK
  8. Node.js (backend) example
  9. HTML + JS (frontend) example
  10. Make your first API call using the SDK
  11. Full Node.js example
  12. Full HTML + JS example
  13. Log In with Audius (OAuth)
  14. What's next?
  15. Direct API Access

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:

PlanRate LimitMonthly Requests
Free10 requests/second500,000 requests/month
UnlimitedUnlimitedUnlimited

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

  1. Visit the Audius API Plans page and click "Create API Key" to generate your credentials.

  2. You will receive an API Key and a Bearer Token.

  • API Key — used in all contexts (frontend and backend). Safe to include in client-side code.
  • Bearer Token — backend only. Grants your app the ability to act on behalf of users who have authorized it. Never expose this in browser or mobile code.

Install the SDK

Node.js

If your project is in a Node.js environment, run this in your terminal:

npm install @audius/sdk

@audius/sdk on NPM

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

How you initialize the SDK depends on whether you are running in a backend (Node.js) or frontend (browser/mobile) context.

Node.js (backend) example

Include your API key and bearer token. The bearer token enables your app to perform actions on behalf of authorized users.

import { sdk } from '@audius/sdk'

const audiusSdk = sdk({
  apiKey: 'Your API Key goes here',
  bearerToken: 'Your Bearer Token goes here'
})

HTML + JS (frontend) example

In a browser or mobile context, initialize with your API key only — no bearer token. User authentication is handled via the OAuth flow described below.

const audiusSdk = window.audiusSdk({
  apiKey: 'Your API Key goes here'
})

:::warning

Never include your bearer token in frontend code. The bearer token allows your app to act on behalf of users who have authorized it. Exposing it in client-side code (browser or mobile) is a critical security risk — anyone who inspects your code could use it to impersonate your app.

For frontend apps, use the OAuth flow instead.

:::

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>

Log In with Audius (OAuth)

For frontend apps, use the built-in OAuth 2.0 PKCE flow to authenticate users. This lets your users log in with their Audius account and authorize your app to act on their behalf — without exposing your app's bearer token in client-side code.

const audiusSdk = window.audiusSdk({
  apiKey: 'Your API Key goes here',
  redirectUri: 'https://your-app.com/oauth/callback'
})

// Redirect the user to Audius to log in
audiusSdk.oauth.login()

// On your callback page, handle the redirect:
await audiusSdk.oauth.handleRedirectCallback()

After the user logs in, the SDK stores their access token automatically and includes it in subsequent API calls. See the Log In with Audius guide for the full flow.

What's next?

Direct API Access

You can also access the Audius API directly without the SDK. The examples below use a bearer token and are intended for backend/server-side use only — do not use your bearer token in browser or mobile code.

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.

版本与发布记录

@audius/sdk 共发布 351 个版本,首次发布于 2022/06/02;过去 12 个月发布了 14 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
17.0.0latest2026/09/251 个月前
16.0.02026/08/043 个月前
15.3.12026/05/026 个月前
15.3.02026/05/026 个月前
15.1.02026/03/317 个月前
15.0.12026/03/207 个月前

其他发布通道:hotfix → 3.0.3-beta110hotfix.1,alpha → 3.0.10-alpha.0,beta → 4.1.1-beta.1。

关于 @audius/sdk 的常见问题

@audius/sdk 是什么?

Audius SDK

如何安装 @audius/sdk?

在项目目录运行 npm install @audius/sdk,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@solana/web3.js(^1.95.8)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@audius/sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@audius/sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@audius/sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@audius/sdk 可以商用吗?

@audius/sdk 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@audius/sdk 的下载量有多少?

根据 npm 官方下载统计,@audius/sdk 在 2026/10/07 – 2026/11/05 这 30 天内被下载 6,369 次,日均约 212 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@audius/sdk 还在维护吗?

最新版本 17.0.0 发布于 2026/09/25(1 个月前);至今共发布 351 个版本,其中过去 12 个月发布了 14 个;首次发布于 2022/06/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。