createSessionToken
Create a session token to authenticate a customer with the React SDK.Parameters
| Name | Type | Required | Description |
|---|---|---|---|
externalUserId | string | Yes | Your user’s unique ID from your database |
email | string | No, but recommended | Your user’s email. Lets BillingOS lazy-bind imported Stripe customers on first session. See Migrating from Stripe. |
externalOrganizationId | string | No | Organization ID for B2B scenarios |
expiresIn | number | No | Token lifetime in seconds (60–86400, default: 3600) |
allowedOperations | string[] | No | Scope the token to specific operations |
metadata | Record<string, any> | No | Additional metadata (IP, user agent, etc.) |
Response
unresolvedCustomers field is populated when you have imported customers from Stripe that haven’t been bound yet. The SDK uses it to surface a one-time console.warn if you’re issuing tokens without email.
revokeSessionToken
Revoke a previously created session token.Token format
Session tokens are prefixed based on your API key environment:| API key | Token prefix | Routes to |
|---|---|---|
sk_test_* | bos_session_test_* | Sandbox API |
sk_live_* | bos_session_live_* | Production API |
Next.js example
app/api/billingos-session/route.ts
Security notes
- Tokens are short-lived (default: 1 hour)
- Each token is scoped to a single customer
- Tokens are verified on every API call
- Expired tokens are automatically rejected
- Always authenticate the user before creating a token