The Messaging API lets you embed real-time text conversations into your application. End users chat with a PolyAI agent, and the conversation can be handed off to a live human agent inside the same session when needed. Communication happens over a WebSocket connection after a short HTTP handshake. All messages are JSON-encoded events.Documentation Index
Fetch the complete documentation index at: https://docs.poly.ai/llms.txt
Use this file to discover all available pages before exploring further.
The Messaging API is a real-time, event-driven protocol. If you only need simple turn-based request/response (for example for SMS), use the Chat API instead. See Messaging API vs Chat API below.
Base URL
Each region has its own cluster-specific host:| Cluster | Base URL | Description |
|---|---|---|
us-1 | https://messaging.us-1.poly.ai | US Mainland |
uk-1 | https://messaging.uk-1.poly.ai | UK |
euw-1 | https://messaging.euw-1.poly.ai | EU West |
Prerequisites
Before integrating, you need two values, both generated when you create a webchat widget in Agent Studio under Channels → Chat → Widget:| Value | What it is | Where to find it |
|---|---|---|
| Connector token | A secret token that identifies your integration | Generated automatically when you create a widget in Agent Studio |
| Host identifier | The domain (e.g. https://www.yourcompany.com) or app namespace (e.g. com.yourcompany.app) you registered when generating the token | Set as the host domain when creating the widget. The server rejects requests where X-Host doesn’t match. |
Getting started
Every conversation follows this sequence:Obtain an access token
POST /api/v1/access-token with your connector token. Returns a short-lived JWT.Minimal JavaScript example
Messaging API vs Chat API
PolyAI offers two APIs for non-voice channels. Pick the one that matches your integration model.| Messaging API | Chat API | |
|---|---|---|
| Protocol | WebSocket (real-time, event-driven) | REST (turn-based request/response) |
| Streaming responses | Yes (incremental chunks) | No |
| Typing indicators | Yes | No |
| Live-agent handoff | Yes (full event flow over the WebSocket) | Yes (via handoff in the respond response) |
| Reconnection / history replay | Built-in (cursor query param) | Client manages turns |
| Auth | Connector token + host domain → short-lived JWT | API key + connector token |
| Best for | Web apps, iOS/Android apps, custom SDKs | SMS, server-to-server, simple webchat |
Reference
Sessions and authentication
Obtain an access token and create a session
WebSocket connection
Connect, reconnect, and keep the connection alive
Event format
Common envelope, echo behavior, delivery receipts
Client events
Events your client can send
Server events
Events your client receives
Streaming
Receive agent responses as incremental chunks
Handoff to live agent
Server-managed and client-managed handoff flows
Session lifecycle
Every event in order, from connect to session end
Errors
HTTP codes and system-message error catalog
Best practices
Connection management, dedup, ordering, UX, security

