Liya Engine

Liya Chat

Deploy a grounded AI chat assistant on any website in one script tag. Answers questions from your knowledge base — not from hallucinated generalities.

Liya Chat is a customer-facing AI assistant that answers questions from your uploaded knowledge — docs, FAQs, product content, policies. It deploys as a widget on any web page or as an API-driven backend for your own chat UI.

Domain: chat
Endpoint: POST /v1/run with pack: "liya-chat" or domain: "chat"


How Liya Chat works

Every message goes through four steps:

  1. Retrieval — semantic search over your uploaded knowledge base for that domain
  2. Grounding check — verifies the retrieved context is sufficient to answer confidently
  3. Response generation — answer generated with your configured persona and tone
  4. Source citation — response includes the source documents used

If the knowledge base doesn't have a clear answer, Liya Chat escalates rather than hallucinating.


Deployment options

OptionHowBest for
Embed widgetOne <script> tag in your HTMLMarketing site, help center, docs, SaaS product
API integrationPOST /v1/run from your backendCustom chat UI, mobile apps, internal tools

Widget deployment (fastest path)

1. Create an embed token

In the dashboard, go to Deploy → Embed Tokens and create a token. You must specify at least one allowed origin (the domain your website runs on).

Or via API:

curl -X POST https://api.liyaengine.ai/dashboard/deploy/tokens \
  -H "Authorization: Bearer $JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "label": "Marketing site",
    "allowed_origins": ["https://yourdomain.com"],
    "allowed_intents": ["answer_question", "general_chat"],
    "rate_limit_rpm": 60
  }'

Response:

{
  "data": {
    "id": "tok_abc123",
    "token": "liya_pub_...",
    "token_preview": "liya_pub_a1b2...",
    "allowed_origins": ["https://yourdomain.com"],
    "allowed_intents": ["answer_question", "general_chat"],
    "rate_limit_rpm": 60
  }
}

The full token is shown once only — copy it immediately.


2. Add the widget script

Paste this into the <head> or before </body> of your page:

<script
  src="https://liyaengine.ai/widget.js"
  data-token="liya_pub_your_token_here"
  data-domain="chat"
  async
></script>

The widget mounts automatically. No additional JavaScript required.


3. Customise the widget (optional)

<script
  src="https://liyaengine.ai/widget.js"
  data-token="liya_pub_your_token_here"
  data-domain="chat"
  data-title="Ask anything"
  data-placeholder="How can I help you today?"
  data-position="bottom-right"
  data-theme="dark"
  async
></script>
AttributeDefaultOptions
data-title"Ask anything"Any string
data-placeholder"Type a message..."Any string
data-position"bottom-right""bottom-right" · "bottom-left"
data-theme"light""light" · "dark"

API integration

For custom chat UIs, call POST /v1/run directly from your backend:

curl -X POST https://api.liyaengine.ai/v1/run \
  -H "x-api-key: $LIYA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "pack": "liya-chat",
    "intent": "answer_question",
    "message": "How do I reset my password?",
    "session_id": "ses_existing_or_omit_for_new"
  }'

Response:

{
  "response": {
    "content": "To reset your password, go to the login page and click 'Forgot password'...",
    "intent": "answer_question",
    "confidence": 0.94,
    "sources": [
      {
        "source_id": "src_xyz",
        "title": "Account & Security FAQ",
        "snippet": "Password resets are handled via..."
      }
    ],
    "metadata": {
      "guardrails_passed": true,
      "grounding_verified": true,
      "flags": []
    }
  },
  "session": {
    "id": "ses_01HZ...",
    "turns": 1,
    "memory_updated": true
  },
  "execution": {
    "latency_ms": 840,
    "retrieval_ms": 120
  }
}

Pass session_id on follow-up messages to maintain conversation context.


Chat intents

IntentWhen to use
answer_questionSpecific factual question — returns grounded answer with sources
general_chatOpen-ended conversation — more flexible, context-aware
summarizeSummarise a document, page, or thread
clarifyAsk Liya to explain or elaborate on a previous answer
escalateHand off to a human agent — Liya wraps the session context

Building your knowledge base

Liya Chat answers are only as good as what you've uploaded. Add your content:

# Upload a help article
curl -X POST https://api.liyaengine.ai/dashboard/knowledge/upload \
  -H "Authorization: Bearer $JWT_TOKEN" \
  -F "[email protected]" \
  -F "domain=chat"
 
# Ingest a URL
curl -X POST https://api.liyaengine.ai/dashboard/knowledge/ingest-url \
  -H "Authorization: Bearer $JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://docs.yourproduct.com/faq", "domain": "chat" }'

Supported file formats: PDF, DOCX, TXT, plain text, JSON.


Embed token security

Embed tokens (liya_pub_*) are distinct from API keys:

  • Origin-locked — requests from unlisted origins are rejected at the API layer
  • Intent-scoped — the token can only call the intents you configure
  • Rate-limited — default 60 RPM per token; configurable up to your plan limit
  • Revocable — delete a token from the dashboard at any time; the widget stops working immediately
  • Max 10 active tokens per tenant — rotate unused tokens

Embed tokens are safe to include in public HTML. They cannot access your API key, account settings, or non-chat intents.


Session limits

LimitDefaultPlan
Max turns per session50All plans
Max tokens per session100,000All plans

When a session's token budget is exhausted, Liya Chat returns a graceful escalation response rather than an error. A new session_id starts a fresh session.


Next steps

On this page