Skip to main content
The SDK authenticates by passing a token to the apiKey configuration option. Both API tokens and OAuth access tokens are supported.

API Token

API tokens use the rp_ prefix and are created in Organizations > Settings > Tokens. Pass the token directly when creating the client:
import { Royaltyport } from '@royaltyport/sdk';

const royaltyport = new Royaltyport({
  apiKey: 'rp_your_token_here',
});
See API Token management for details on creating and scoping tokens.

OAuth Access Token

OAuth access tokens obtained through the browser-based consent flow can also be used:
const royaltyport = new Royaltyport({
  apiKey: oauthAccessToken,
});

Environment Variables

The SDK does not automatically read environment variables. To use an environment variable, read it explicitly:
const royaltyport = new Royaltyport({
  apiKey: process.env.ROYALTYPORT_TOKEN,
});
VariableDescription
ROYALTYPORT_TOKENAPI token or OAuth access token
ROYALTYPORT_API_URLCustom API base URL (default: https://api.royaltyport.com)
const royaltyport = new Royaltyport({
  apiKey: process.env.ROYALTYPORT_TOKEN,
  baseUrl: process.env.ROYALTYPORT_API_URL,
});

Custom Base URL

Override the default API base URL for staging or self-hosted environments:
const royaltyport = new Royaltyport({
  apiKey: 'rp_your_token_here',
  baseUrl: 'https://your-api-url.com',
});

Custom Fetch

Pass a custom fetch implementation for testing, proxying, or environments without a global fetch:
import { Royaltyport } from '@royaltyport/sdk';

const royaltyport = new Royaltyport({
  apiKey: 'rp_your_token_here',
  fetch: customFetchImplementation,
});