v0.1.2
OAS 3.1.1
Scalar API
API for managing Scalar platform resources.
TypeScript SDK
For TypeScript, we provide a SDK that makes using our API even easier.
Install
npm add @scalar/sdk
Get a Scalar API key
Create an API key in your Scalar account:
- Dashboard: https://dashboard.scalar.com/account
- Store it in
.env, for example:
SCALAR_API_KEY=your_personal_token
Exchange your API key for an access token
The personal token is not an access token. Exchange it first with postv1AuthExchange.
If you use the personal token directly for authenticated API calls, the API returns 401 Invalid authentication token.
import { Scalar } from '@scalar/sdk'
const scalar = new Scalar()
const exchange = await scalar.auth.postv1AuthExchange({
personalToken: process.env.SCALAR_API_KEY!,
})
const accessToken = exchange.accessToken
Use the access token
Construct a second client with bearer auth. Use this authenticated client for API calls.
import { Scalar } from '@scalar/sdk'
const scalar = new Scalar()
const exchange = await scalar.auth.postv1AuthExchange({
personalToken: process.env.SCALAR_API_KEY!,
})
const authedScalar = new Scalar({
bearerAuth: exchange.accessToken,
})
Notes
- The exchange request itself can be made from a client constructed with no arguments (
new Scalar()). - The exchanged access token is valid for 12 hours.
- Timestamps are Unix seconds.
Read more
Client Libraries