Voisnap Docs
Real-Time APIs

Real-Time Overview

Introduction to Voisnap's three real-time SignalR hubs — VoiceHub, ChatHub, and WebRtcHub — and when to use each.

Real-Time APIs

Voisnap exposes three real-time WebSocket interfaces built on SignalR (ASP.NET Core's real-time library). All three hubs run over wss:// WebSocket connections.


The three hubs

HubURLUse case
VoiceHubwss://api.voisnap.ai/hubs/voiceStream raw PCM audio for phone calls, PSTN, SIP
ChatHubwss://api.voisnap.ai/hubs/chatReal-time text chat exchange (web chat widget)
WebRtcHubwss://api.voisnap.ai/hubs/webrtcWebRTC signaling (SDP + ICE) for browser voice

When to use each

VoiceHub

Use VoiceHub when you're building a custom telephony integration or need direct PCM audio access. The standard phone channel (Twilio/Vonage/Telnyx) connects to VoiceHub automatically. You'd use it directly only for custom SIP integrations or building your own audio pipeline.

ChatHub

Use ChatHub for text-based web chat embedded in a website or app. It handles turn-by-turn text messages, typing indicators, and session lifecycle without any audio.

WebRtcHub

Use WebRtcHub to embed browser voice calls into your web application. The user speaks directly via their microphone — no phone number required. Voisnap handles the WebRTC SDP negotiation and connects to the agent's audio pipeline.


Authentication

All three hubs require a JWT access token passed as a query parameter:

wss://api.voisnap.ai/hubs/voice?agentId=agt_01HXK8Z3MNPQRS&access_token=eyJhbGci...

:::warning API keys cannot be used for real-time hub connections — only JWT access tokens. Obtain a short-lived token via POST /api/v1/auth/login or the JS SDK's getAccessToken() helper. :::


Connection lifecycle

All hubs follow the same lifecycle:

Client connects (WebSocket handshake)

Hub authenticates token (401 if invalid)

Hub emits SessionStarted

Bidirectional exchange (audio/messages)

Either party calls EndSession / disconnects

Hub emits SessionEnded

WebSocket closes

SignalR client libraries

Use the official SignalR client library for your platform:

# Browser / Node.js
npm install @microsoft/signalr
 
# Python
pip install signalrcore
 
# .NET
dotnet add package Microsoft.AspNetCore.SignalR.Client

Error codes

All hubs can emit an Error event with a structured error:

{
  "code": "AGENT_NOT_FOUND",
  "message": "No agent with ID agt_01HXK8Z3MNPQRS found.",
  "recoverable": false
}
CodeDescription
AGENT_NOT_FOUNDAgent ID does not exist
AGENT_INACTIVEAgent is not activated
AUTH_FAILEDJWT is invalid or expired
STT_PROVIDER_TIMEOUTSpeech-to-text did not respond in time
LLM_PROVIDER_ERRORLLM request failed
SESSION_LIMIT_REACHEDMax concurrent sessions for your plan
RECONNECT_FAILEDCould not reconnect within retry window

On this page