Docs
Real-Time Chat Conversations

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

  1. Initiate: POST /v2/chat/initiate to create a live session and receive the Daily room URL plus token.
  2. Connect: Join the Daily room from your client using the returned URL/token (refer to Daily documentation).
  3. Poll: POST /v2/chat/check with the chat ID to retrieve the evolving state (products, recipes, topics mentioned).
  4. Terminate: POST /v2/chat/terminate to 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 subsequent check and terminate calls.
  • 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_token as sensitive client auth and avoid logging it.
  • Lifecycle: Disable UI controls until initiate returns; show a reconnect/ended state based on check responses.
  • Backoff: If check fails transiently, retry with exponential backoff to reduce load.
  • Cleanup: Always call terminate when a user hangs up or times out to free resources.