Real-Time Chat Conversations
Initiate, monitor, and terminate live Retrend AI conversations with the chat API.
Use the chat endpoints to run a real-time, call-like conversation with Retrend AI. The initiation response includes a Daily.co room URL and token; Daily provides the WebRTC infrastructure. For custom front ends, integrate with Daily’s client SDKs (see their documentation) and feed your UI with the chat state returned by the check endpoint. Summarization happens automatically after a call; a separate document covers retrieval of summaries.
These examples assume you already created a session token as described in API Dependencies and you
will authenticate each request with organization-id and x-session headers.
Conversation flow
- Initiate:
POST /v2/chat/initiateto create a live session and receive the Daily room URL plus token. - Connect: Join the Daily room from your client using the returned URL/token (refer to Daily documentation).
- Poll:
POST /v2/chat/checkwith the chat ID to retrieve the evolving state (products, recipes, topics mentioned). - Terminate:
POST /v2/chat/terminateto end the session when the conversation is over.
Initiate a conversation
Call POST <https://api.retrend.ai/v2/chat/initiate> with any context payload your integration supports (for example,
customer or store identifiers). If you have no additional context, send an empty JSON object.
curl -X POST "https://api.retrend.ai/v2/chat/initiate" \
-H "organization-id: $RETREND_ORG_ID" \
-H "x-session: $RETREND_SESSION" \
-H "Content-Type: application/json" \
-d "{}"The response includes at minimum:
cid: Identifier for subsequentcheckandterminatecalls.daily_url: Room URL to join via Daily.co.daily_token: Token for client authentication when connecting to Daily.
Join the room using Daily’s SDKs and keep the JWT/token secure on the client.
Poll conversation state
Use POST <https://api.retrend.ai/v2/chat/check> to retrieve the latest state for the active chat. This endpoint is how
your UI learns which products, recipes, and other entities have been referenced.
curl -X POST "https://api.retrend.ai/v2/chat/check" \
-H "organization-id: $RETREND_ORG_ID" \
-H "x-session: $RETREND_SESSION" \
-H "Content-Type: application/json" \
-d "{\"cid\": \"YOUR_cid\"}"Poll on an interval (e.g., 1–3 seconds) or in response to client events. Handle states such as active, ended, or any
domain-specific payload that includes mentioned entities.
Terminate a conversation
End the call with POST <https://api.retrend.ai/v2/chat/terminate> using the same cid.
curl -X POST "https://api.retrend.ai/v2/chat/terminate" \
-H "organization-id: $RETREND_ORG_ID" \
-H "x-session: $RETREND_SESSION" \
-H "Content-Type: application/json" \
-d "{\"cid\": \"YOUR_cid\"}"On success, the room is closed and no further audio/video is processed. Summaries are generated automatically after termination and covered separately.
Implementation tips
- Secure tokens: Treat
daily_tokenas sensitive client auth and avoid logging it. - Lifecycle: Disable UI controls until
initiatereturns; show a reconnect/ended state based oncheckresponses. - Backoff: If
checkfails transiently, retry with exponential backoff to reduce load. - Cleanup: Always call
terminatewhen a user hangs up or times out to free resources.