Skip to content

Authentication

Pass a static token, or a provider function (called per request — useful for OAuth token refresh).

import { Brex } from 'brex';
// Static token
const brex = new Brex({ token: process.env.BREX_TOKEN! });
// Provider function — called on every request
const brexOAuth = new Brex({
token: async () => getFreshAccessToken(),
});

The provider form is awaited before each request, so you can return a cached token and refresh it out of band, or fetch a fresh one on demand. Generate a user token in your Brex dashboard, or obtain one via OAuth.