Chat API
Use the Chat API to integrate PolyAI agents into non-voice channels. It provides a simple set of REST endpoints for starting conversations, sending and receiving messages, and handling handoffs–ideal for webchat widgets, web SDKs, and SMS platforms.
The Chat API powers webchat integrations including in-browser widgets, web SDK implementations, and SMS.
If you need real-time streaming responses, typing indicators, or in-session live-agent handoff events over a persistent connection, use the Messaging API instead. See Messaging API vs Chat API for guidance on choosing.
Chatting with the API
-
Start a conversation Call
POST /{version}/{account_id}/{project_id}/chat/create. The response includes aconversation_idand the agent’s initialresponse. You can optionally passintegration_attributesto provide custom context to the agent, andvariant_idto target a specific variant. -
Send and receive messages Call
POST /{version}/{account_id}/{project_id}/chat/respondwith theconversation_id.messageis optional. The response includes the agent’sresponse, anend_conversationflag, and may include ahandoffobject. -
Close a conversation Call
PUT /{version}/{account_id}/{project_id}/chat/closewith theconversation_idin the body. The response returns{ "success": true }on success.
Endpoints
Base URLs
Endpoint format:
/{version}/{account_id}/{project_id}/chat/{operation}
version: API version (for examplev1)account_id: Your PolyAI account ID (for examplepoly-scs-ukorws-xxxxxxxx)project_id: Your PolyAI project ID (for examplePROJECT-191bfa2a)operation:create,respond, orclose
Finding your account_id and project_id
Your account_id and project_id are the first two path segments of your Agent Studio URL, immediately after the host:
Agent Studio is region-specific. Each Studio host serves one region and pairs with the matching API host. Replace <region> with the subdomain for your tenant:
A workspace lives in exactly one region — log in to the Studio host for that region and call the matching API host.
For example, if your Studio URL is https://studio.uk.poly.ai/acme-uk/acme-team-4/agent, then:
<region>=uk(so calls go toapi.uk-1.platform.polyai.app)account_id=acme-ukproject_id=acme-team-4
Account and project identifiers are also shown in prefixed form in Agent Studio — both the slug form (visible in the URL) and the prefixed form are accepted in API paths:
The account_id path parameter is shown as Workspace ID in Agent Studio and uses a ws- prefix — not ACCOUNT-. Older docs may still call it ACCOUNT-xxxxxxx; the value you see in Agent Studio (prefixed with ws-) is the correct one to use. If you only have the prefixed form, your PolyAI representative can confirm the matching slug.
The same IDs are exposed inside Agent Studio functions as conv.account_id and conv.project_id — see the Conversation object reference.
Authentication
All requests must include the following headers (case-sensitive):
Getting your credentials
Both X-API-KEY and X-TOKEN are provisioned by PolyAI — there is no self-serve endpoint to create a Chat API connector or generate a connector token.
To request access, contact your PolyAI representative with:
- Your
account_id - Your
project_id - The client environment you need (
live,pre-release, orsandbox) - Your
variant_id(optional, only if targeting a specific variant)
PolyAI will provision a Chat API connector for your project and return:
- An API key to use in the
X-API-KEYheader - A connector token to use in the
X-TOKENheader
The Chat API connector is distinct from the voice/telephony connectors managed under the Agents API. You do not need SIP details, phone numbers, or language codes to provision a Chat API connector.
Example: Create chat
POST /v1/{account_id}/{project_id}/chat/create
Response
Example: Send message
POST /v1/{account_id}/{project_id}/chat/respond
Response
Response with handoff
Example: Close chat
PUT /v1/{account_id}/{project_id}/chat/close
Response
Passing custom data with integration_attributes
The integration_attributes field lets you pass custom data when creating a chat. These attributes are accessible in your project functions at conv.integration_attributes.
When to use
- Pass user context (user ID, session ID, authentication status)
- Include customer information (tier, preferences, history)
- Send external system references (CRM ID, ticket number)
- Provide A/B test parameters or feature flags
Accessing in project functions
integration_attributes when creating the chat. They’re set on the first turn and available throughout the conversation. Store values in conv.state to access them in later turns.Targeting a variant with variant_id
Pass variant_id in the create request body to route the conversation to a specific variant. This is useful for multi-site deployments where different variants serve different brands, languages, or regions.
variant_id is only accepted on POST /chat/create. It cannot be changed after the conversation starts.Notes
createaccepts an optional request body withvariant_idandintegration_attributes.respondrequiresconversation_id;messageis optional.handoffmay appear in therespondresponse withdestinationandreason.closerequires a JSON body containingconversation_id.- Header names are case-sensitive:
X-API-KEY,X-TOKEN. - Use the regional base URL closest to your deployment.

