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-ukorACCOUNT-xxxxxxx)project_id: Your PolyAI project ID (for examplePROJECT-191bfa2a)operation:create,respond, orclose
Authentication
All requests must include the following headers (case-sensitive):| Header | Description |
|---|---|
X-API-KEY | Your API key for PolyAI |
X-TOKEN | Agent authentication token (connector) |
Content-Type | Must be application/json |
Example: Create chat
POST/v1/poly-scs-uk/PROJECT-191bfa2a/chat/create
Body (optional)
Example: Send message
POST/v1/poly-scs-uk/PROJECT-191bfa2a/chat/respond
Body
Example: Close chat
PUT/v1/poly-scs-uk/PROJECT-191bfa2a/chat/close
Body
Passing custom data with integration_attributes
The integration_attributes field allows you to pass custom data when creating a chat. These attributes are accessible in your project functions via 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
Pass
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.

