Skip to content

Chat / Query API

Send a customer message; receive the agent's answer as a stream. When you pass a visitor_id, RagSystem manages the whole conversation for you — history, order tools, escalation state — so your side can stay stateless.

POST /api/v1/widget/query
X-API-Key: rsk_...
Content-Type: application/json
{
  "query": "Сколько стоит eSIM на месяц?",
  "visitor_id": "tg_774411",
  "channel_type": "telegram"
}
Field Required Notes
query yes The customer's message, any language
visitor_id recommended Any stable id for this customer (chat id, phone hash, …). Enables server-side history, ordering tools and human-takeover state
channel_type recommended Free-form label: telegram, whatsapp, instagram, api, …

Response (Server-Sent Events)

data: {"token":"Безлимит на месяц (Oylik cheksiz) стоит 120 000 UZS...","done":false}

data: {"done":true,"sources":[...],"tokens_used":812,"conversation_id":"..."}
  • Concatenate token values for the full answer
  • done: true closes the turn and carries metadata

Escalated conversations

If a human has taken over this visitor's conversation, the stream is a single event:

data: {"token":"","done":true,"escalated":true}

Your bot should send nothing to the customer in that case — a person is answering them directly. The customer's message is still recorded for the operator.

What happens behind one call

With visitor_id set, a single request does all of this: find/continue the conversation (24 h session window), load history, detect language, retrieve knowledge, expose the order tools (search_products, create_order, escalate_to_human), stream the reply, and persist both sides of the exchange.