Session token
REST endpoint used to obtain a short-lived JWT for the WebSocket connection.
Connection
WebSocket channel, message types, and request/response flow.
Prerequisites
- Node.js 18+ or a modern browser
- API key (organization API key from the Vatel dashboard)
- Agent ID for the agent you want to connect to
- In Node.js only: a WebSocket implementation (
wspackage)
Walkthrough
Install the SDK
Install the package:In Node.js, also install a WebSocket implementation (browsers have one built in):
Get a session token
Create a In the browser, call your backend to get the token (never expose the API key in client code).
Client with your API key and call generateSessionToken with your agent ID. The token is a short-lived JWT used to open the WebSocket session.Connect a session and listen for events
Create a
Session with the token, register event handlers, then call connect().Node.js: WebSocket setup
Node does not include a WebSocket API. Installws and pass a WebSocket factory when creating the session:
Session options
| Option | Description |
|---|---|
token | Required. JWT from client.generateSessionToken(agentId). |
baseUrl | API base URL. Default: https://api.vatel.ai. Use https://… or wss://…; the SDK picks the right protocol. |
createWebSocket | Node only. Function that takes a URL and returns a WebSocket instance. Use with the ws package. |
REST client
TheClient uses your organization API key as a Bearer token and exposes the REST API. See the API reference for all endpoints. Example:
Tool calls
When the agent invokes a tool, handle thetool_call event and send the result back with sendToolCallOutput:
TypeScript
The package includes type definitions. No extra@types install; import types when needed:

