Overview

The Vocantly SDK uses token-based authentication. You need an SDK token to connect to the WebSocket server.
New to how tokens work? Read Authentication & tokens first — it covers keys vs. tokens and the three ways your backend provisions a token. This page focuses on wiring that token into the SDK.

SDK token

You need a single SDK token (about 15 minutes lifetime). It is used for both the WebSocket connection and, when you set apiUrl, for REST calls (list conversations, fetch messages) as Bearer.

Authentication Flow

App ID, public key, and secret key are backend-only. Your frontend never sees them. It receives only the token from your backend.

Getting an SDK Token (Backend)

Your backend issues tokens via POST /api/v1/apps/:appId/tokens.

Option A: API key (server-to-server)

Option B: JWT (dashboard user)

Response: { "token", "expires_in", "user_id" } — return token to your frontend.

Initialize SDK (Frontend)

Token refresh

SDK tokens expire after about 15 minutes. When you get a token-expired error, get a new token from your backend, update the client, and reconnect:

Token Claims

The SDK token (issued by POST /api/v1/apps/:appId/tokens) contains claims like:
  • sub is your app’s user identifier (external_user_id). The backend uses it for REST inbox endpoints when you call with Bearer token (e.g. list conversations, fetch messages).
  • type: "sdk_user" identifies this as an SDK token (not a dashboard JWT).

Security Best Practices

Never expose tokens

Never log or expose SDK tokens in client-side code.

Use HTTPS

Always use secure connections (wss://, https://).

Short token lifetime

SDK tokens are intentionally short-lived (15 min) for security.

Backend token exchange

Exchange tokens server-side, not in client code.

Backend Token Exchange Pattern

Your backend calls POST /apps/:id/tokens (JWT or API key), then returns the token to your frontend. Frontend never sees keys.
For a full flow (backend token endpoint, start conversation, chat screen, token refresh), see the Implementation Guide.

Next Steps

Implementation Guide

Full backend + frontend integration

Conversations

Join and send messages

Inbox

List conversations and history

Messaging

Send and receive messages