Assistant Billing

Sessions

Create session tokens scoped to a workspace and user. Session tokens let @assistant-billing/react call the Client API directly from the browser.

Auth: Platform key (sk_pj_*) required.

Create a Session

POST /v1/platform/sessions

Create a session token scoped to a workspace and user. Requires a platform key.

Body Parameters

NameTypeRequiredDescription
workspace_idstringYesExternal workspace identifier
user_idstringYesExternal user identifier
expires_innumberNoToken lifetime in seconds. Default: 3600 (1h)
import { BillingClient } from '@assistant-billing/sdk';
 
const billing = new BillingClient({
  platformKey: process.env.ASSISTANT_BILLING_PLATFORM_KEY,
  workspaceId: 'ws_team_123',
  userId: 'user_456',
});
 
const session = await billing.sessions.create({ expiresIn: 3600 });

Response

{
  "token": "sess_eyJhbGciOiJIUzI1NiJ9...",
  "expires_at": "2025-01-15T13:00:00.000Z"
}
FieldTypeDescription
tokenstringSession token (pass to frontend)
expires_atstringISO 8601 expiration timestamp

Token Claims

The JWT contains:

{
  "gw": "pj_k8s9d7f6",
  "ws": "ws_team_123",
  "uid": "user_456",
  "iat": 1736938800,
  "exp": 1736942400
}
ClaimDescription
gwProject ID (from the platform key)
wsWorkspace ID
uidUser ID
iatIssued at
expExpires at

Use with @assistant-billing/react

import { GatewayClient } from '@assistant-billing/react';
import { BillingClient } from '@assistant-billing/sdk';
 
const client = new BillingClient({
  baseURL: 'https://api.assistant-billing.dev/v1/platform',
  getToken: () => sessionToken,
});
 
<GatewayClient client={client} />

Workspace Registration

The first time a session is created for a workspace_id, the workspace is automatically registered. No explicit workspace creation needed.

Errors

StatusCause
400Missing workspace_id or user_id, invalid expires_in
401Invalid or missing platform key