Skip to navigation

Prepare Chat

Prepare a chat turn: load and merge prior history, resolve intent, build system/context messages, and run any server-side action. The client then streams the model call using the returned messages.

Authentication: Required — Bearer token.

Feature gate: Requires a configured LoyalStream/AI connector — otherwise 403 ai_sdk_unavailable.

Request body (all optional unless noted):

  • client_id — Conversation/client id used to load and merge prior history
  • messages — Array of prior { role, content } turns (last 20 kept)
  • message — The current user message; appended as a user turn if not already last
  • page_context — Context about the page the user is on

Response: data whose shape depends on data.type:

  • ready — system_messages, base_messages, model, intent, action_context, conversation_id, safe_intent, content_cards
  • limit_reached / denied / action_result — carry deny_message or assistant_content plus conversation_id, base_messages, etc. (auto-persisted server-side)

Errors:

  • 403 — ai_sdk_unavailable
  • 422 — { error: { message } } on a raised error

Authentication

AuthorizationBearer

Bearer authentication of the form Bearer <token>, where token is your auth token.

Request

This endpoint expects an object.
client_idstringOptional
messagestringOptional
messageslist of anyOptional
page_contextobjectOptional

Response

OK