Skip to main content
Use the programmatic session-message API when your backend needs to notify an embedded agent about an event or state change. The message behaves exactly like a user turn typed in the chat widget: Caylex appends it to the existing transcript, runs the agent, stores the assistant response, and returns the completed turn. Enable enableExternalSessionSync on chat widgets that need to receive these turns. While that option is enabled, the widget checks for persisted updates only when the tab is visible and the interactive session is idle. The polling interval defaults to five seconds and can be changed with externalSessionSyncIntervalMs.
Call this API from your backend. Platform access tokens and navigator API keys must never be exposed to the browser.

Endpoint

All three identity values must match the existing production session:
  • The platform access token must belong to the session’s tenant.
  • caylex_api_key must identify the session’s navigator instance.
  • user_email must identify the end user who owns the widget session.
The API returns 404 rather than revealing a session when any scope does not match. Playground and background-task sessions cannot receive programmatic chat turns.

Response

This is a synchronous endpoint: it waits for the agent turn to finish.
If another agent run is active in the session, the endpoint returns 409. Retry after that turn finishes; do not submit concurrent turns to the same session.

Capture the Session ID

The preferred approach is to save the ID emitted by the chat widget’s onSessionCreated callback and associate it with the corresponding user in your application. If your application already has a mapped session, pass it back through initialSessionId; otherwise, pass null to explicitly create a new session:
After the lookup completes, savedCaylexSessionId should be the mapped session ID or null when no mapping exists. Do not render the widget while the lookup is still pending: null intentionally creates a new session. See Session Management for restoration behavior, session-change callbacks, and host-managed session examples. If you did not capture the ID, list recent sessions from your backend:
Use navigator_instance_id, project_id, and timestamp filters to narrow the results. Session summaries include session_id, session_name, created_at, and last_message_at. For complete lookup and export examples, see Get All Assistant Session Messages.

Example

send_session_message.py