Skip to main content
Use @vatel/sdk to connect to Vatel voice agents from JavaScript or TypeScript. The SDK provides a REST client and a WebSocket session for real-time voice: send audio, receive events, and handle tool calls. It works in Node.js and the browser.

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 (ws package)

Walkthrough

1

Install the SDK

Install the package:
In Node.js, also install a WebSocket implementation (browsers have one built in):
2

Get a session token

Create a 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.
In the browser, call your backend to get the token (never expose the API key in client code).
3

Connect a session and listen for events

Create a Session with the token, register event handlers, then call connect().
4

Send audio

Send microphone (or other) audio as base64-encoded PCM chunks (24 kHz, mono, 16-bit):
Use your preferred audio capture and encoding; the SDK does not capture the microphone for you.

Node.js: WebSocket setup

Node does not include a WebSocket API. Install ws and pass a WebSocket factory when creating the session:

Session options

REST client

The Client 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 the tool_call event and send the result back with sendToolCallOutput:

TypeScript

The package includes type definitions. No extra @types install; import types when needed: