useAssistant uses it internally.
Import
Usage
Options
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
tokenEndpoint | string | No | /api/mwai/token | Token generation endpoint |
endUserId | string | No | Auto-generated | User identifier |
availableActions | ActionDefinition[] | Yes | — | Available actions |
autoFetch | boolean | No | true | Fetch token on mount |
refreshBuffer | number | No | 30000 | Refresh before expiry (ms) |
Return Value
| Property | Type | Description |
|---|---|---|
token | string | null | Current ephemeral token |
expiresAt | Date | null | Token expiration time |
isLoading | boolean | Fetching token |
error | Error | null | Fetch error |
fetchToken | () => Promise<void> | Manually fetch token |
Token Lifecycle
- Initial fetch — Token fetched on mount (if
autoFetch: true) - Auto refresh — New token fetched
refreshBufferms before expiry - Manual refresh — Call
fetchToken()to force refresh
Example
When to Use
UseuseAssistantToken directly when you need:
- Token state without the chat interface
- Custom token refresh logic
- Multiple assistant instances sharing a token
useAssistant instead—it handles tokens automatically.