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
| Name | Type | Required | Description |
|---|---|---|---|
workspace_id | string | Yes | External workspace identifier |
user_id | string | Yes | External user identifier |
expires_in | number | No | Token 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"
}| Field | Type | Description |
|---|---|---|
token | string | Session token (pass to frontend) |
expires_at | string | ISO 8601 expiration timestamp |
Token Claims
The JWT contains:
{
"gw": "pj_k8s9d7f6",
"ws": "ws_team_123",
"uid": "user_456",
"iat": 1736938800,
"exp": 1736942400
}| Claim | Description |
|---|---|
gw | Project ID (from the platform key) |
ws | Workspace ID |
uid | User ID |
iat | Issued at |
exp | Expires 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
| Status | Cause |
|---|---|
| 400 | Missing workspace_id or user_id, invalid expires_in |
| 401 | Invalid or missing platform key |