Start free
Docs / RAG Widget / Widget Chat API
Reference

Widget Chat API

If you'd rather build your own interface (mobile app, custom UI) instead of the ready-made widget.js, you can call the HTTP API the widget uses directly.

Base URL: https://semagent.ai

ℹ️

For most scenarios the one-line embed code is enough — this page is for custom integrations.

Authentication

Every request requires the X-Tenant-Id header — its value is your tenant slug or tenant ID (panel → Widget → Setup). This API is designed to be called from the browser; it carries no secret key and reaches only widget-scoped endpoints.

POST /api/chat/widget

Sends a customer message and returns the assistant's answer. Don't send conversation_id on the first call — it's generated in the response; send the same value back on subsequent messages.

curl -X POST https://semagent.ai/api/chat/widget \
  -H "Content-Type: application/json" \
  -H "X-Tenant-Id: your-slug" \
  -d '{
    "message": "When will my order arrive?",
    "session_id": "visitor-123",
    "conversation_id": null,
    "type": "rag"
  }'

Request body

FieldTypeDescription
messagestring · requiredCustomer message.
session_idstring · requiredVisitor session ID (a stable value you generate).
conversation_idstring · optionalConversation ID from a previous response; empty opens a new conversation.
type"rag" | "ecommerce" · opt.If empty, the tenant's default widget mode is used.
customer_name / _email / _phonestring · opt.Pre-chat form data (passed to human support on escalation).

Response 200 OK

{
  "response": "Orders are delivered in 1-3 business days.",
  "conversation_id": "c7a1…",
  "widget_type": "rag",
  "rag_active": true,
  "ecommerce_active": false
}

GET /api/chat/welcome

Returns the tenant's welcome message — shown when the widget opens. Only the X-Tenant-Id header is required.

GET /api/chat/widget/messages/{conversation_id}

Returns a conversation's message history (to restore the chat when the page reloads).

GET /api/chat/widget-settings

Returns widget behavior settings: whether the pre-chat form is on (widget_prechat_enabled), which fields are requested (widget_prechat_fields), the client rate limit (widget_rate_limit).

POST /api/chat/widget/csat

Sends a satisfaction score at the end of a conversation:

{ "conversation_id": "c7a1…", "score": 5, "feedback": "Very helpful" }

Error codes

CodeMeaningWhat to do
404Tenant not foundVerify the X-Tenant-Id value in the panel.
403Assistant not activeActivate the widget in the panel.
429Rate limitPer-client limit exceeded; wait briefly and retry.
200 + limit messageMonthly plan limit reachedThe widget returns a graceful redirect message instead of an error; upgrade the plan.
📝

This page is updated as endpoints expand. Missing something you need? Get in touch.

Was this page helpful? Send feedback