Visit the web chat homepage if you are looking for more information on chat integrations.
Use the Chat API to integrate PolyAI agents into existing systems, and use its endpoints to get programmatic access to automated chat interactions. This API structures non-voice web conversations, messages, and chat sessions using a simple set of REST endpoints.The Chat API can power multiple Webchat integrations, including WhatsApp, email, and in-app widgets.
Start a conversation
Call POST /{version}/{account_id}/{project_id}/chat/create.
The response includes a conversation_id and the assistant’s initial response.
You can optionally pass integration_attributes to provide custom context to the agent.
Send and receive messages
Call POST /{version}/{account_id}/{project_id}/chat/respond with the conversation_id.
message is optional. The response includes the assistant’s response, an end_conversation flag, and may include a handoff object.
Close a conversation
Call PUT /{version}/{account_id}/{project_id}/chat/close with the conversation_id in the body.
The response returns { "success": true } on success.
{ "conversation_id": "CONV-1234567890", "message": "What's your return policy?"}
Response
Copy
Ask AI
{ "conversation_id": "CONV-1234567890", "response": "Our return policy is 30 days with proof of purchase.", "end_conversation": false}
Response with handoff
Copy
Ask AI
{ "conversation_id": "CONV-1234567890", "response": "Transferring you to a live agent.", "end_conversation": true, "handoff": { "destination": "live_agent_queue", "reason": "billing_question" }}
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.
def start(conv): # Get integration attributes (always check for None) attrs = conv.integration_attributes or {} user_id = attrs.get("user_id") customer_tier = attrs.get("customer_tier", "standard") # Store in state for use throughout the conversation if user_id: conv.state.user_id = user_id # Customize greeting based on tier if customer_tier == "premium": return "Welcome back! As a premium member, how can I assist you today?" return "Hello! How can I help you?"
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.