Integration Guide

Embed & API

Two ways to connect a LunieAI chatbot to the outside world: embed a visual widget on a website, or call it directly from your own backend or app with an API key. Both are configured from your chatbot's Embed & API page in the dashboard.

Overview

Embed Widget

For putting a chat window on a website - your own, or a customer's. Visual, visitor-facing, no authentication required. Three flavors: a JavaScript snippet (recommended), a plain iframe, or a WordPress-specific version of the same snippet.

Developer API

For calling the chatbot from your own backend, a custom app, or a service like Slack or WhatsApp - anywhere that isn't a browser. Requires an API key you generate per chatbot.

Go to Dashboard → your chatbot → Embed & API in the sidebar to reach both. The page has a live preview of the actual widget, and a "Try It" panel that sends a real request through the API using your key - so you can see either integration working before you write any code.

Embed Widget: JavaScript (recommended)

A floating chat bubble your visitors can open from any page on your site.

  1. 1Open your chatbot's Embed & API page and choose the Embed Widget mode.
  2. 2Enter your website's domain under "Website Configuration" and click Generate.
  3. 3Copy the generated script from the Widget tab.
  4. 4Paste it into your site's HTML, just before the closing </body> tag.
html
<!-- Lunie-Ai Chat Widget -->
<script>
  (function() {
    window.LunieAiConfig = {
      chatbotId: '<YOUR_CHATBOT_ID>',
      domain: '<YOUR_DOMAIN>',
      apiUrl: 'https://lunie.ai'
    };
    var script = document.createElement('script');
    script.src = 'https://lunie.ai/widget.js';
    script.async = true;
    script.onload = function() {
      if (window.LunieAiWidget) window.LunieAiWidget.init(window.LunieAiConfig);
    };
    document.head.appendChild(script);
  })();
</script>
<!-- End Lunie-Ai Chat Widget -->

The exact snippet (with your real chatbot ID) is generated for you on the Embed & API page - you don't need to hand-write this.

Simple iframe

Works anywhere HTML works, with less customization than the JS widget - a fixed-size chat window rather than a floating bubble.

html
<iframe
  src="https://lunie.ai/widget/<YOUR_CHATBOT_ID>"
  width="400"
  height="500"
  frameborder="0"
  style="border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.15);">
</iframe>

WordPress

Method 1: Custom HTML Widget

  1. 1Go to Appearance → Widgets in your WordPress admin.
  2. 2Add a "Custom HTML" widget.
  3. 3Paste the JavaScript embed code from the Widget tab.
  4. 4Save the widget.

Method 2: Theme Customizer

  1. 1Go to Appearance → Customize → Additional CSS.
  2. 2Scroll to the bottom and add the embed code.
  3. 3Publish your changes.

Developer API

A single endpoint, authenticated with a per-chatbot API key, for calling a chatbot from anywhere that isn't a browser: POST /api/v1/chat/<chatbotId>.

Getting an API key

  1. 1Open your chatbot's Embed & API page and choose the Developer API mode.
  2. 2Click Generate API Key.
  3. 3Copy it somewhere safe - it's shown once in full, then masked. You can reveal or regenerate it any time.

Regenerating a key immediately invalidates the old one - any integration still using it starts getting 401 errors. Revoking disables API access entirely until you generate a new key.

Making a request

curl
curl -X POST https://lunie.ai/api/v1/chat/<YOUR_CHATBOT_ID> \
  -H "Authorization: Bearer <YOUR_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{"message": "Hello, what can you help me with?"}'
javascript
const response = await fetch('https://lunie.ai/api/v1/chat/<YOUR_CHATBOT_ID>', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer <YOUR_API_KEY>',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ message: 'Hello, what can you help me with?' })
})

const { data } = await response.json()
console.log(data.message)
python
import requests

response = requests.post(
    "https://lunie.ai/api/v1/chat/<YOUR_CHATBOT_ID>",
    headers={"Authorization": "Bearer <YOUR_API_KEY>"},
    json={"message": "Hello, what can you help me with?"}
)

print(response.json()["data"]["message"])

message can also be sent as question if you're porting integration code written for another chatbot platform - both are accepted.

Continuing a conversation

Every response includes a conversationId. Pass it back in your next call (as conversationId, or chatId) to continue the same conversation with full context, instead of starting a new one each time.

json
{
  "message": "And what about pricing?",
  "conversationId": "62e97f64-db06-45de-91eb-3962c568c592"
}

Response shape

json
{
  "success": true,
  "data": {
    "message": "The AI's reply, as plain text/markdown",
    "conversationId": "uuid - pass this back in to continue the conversation",
    "sources": [
      { "title": "...", "source": "...", "score": 0.82, "excerpt": "..." }
    ],
    "metadata": {
      "confidence": 0.74,
      "processing_time": 1120,
      "rag_success": true
    }
  }
}

Security

  • Domain allowlisting. Each domain you generate embed code for is added to that chatbot's approved-domains list, enforced server-side. The widget itself never carries your API key in the browser - it doesn't need one.
  • Keep your API key secret. It grants full access to that chatbot's conversations. Call the API from your own backend, not from client-side code where the key would be visible to anyone.
  • Rotate keys periodically, and revoke immediately if a key is ever exposed (committed to a public repo, logged somewhere, etc.).
Questions about your specific setup are best answered from your chatbot's own Embed & API page, where every code sample is generated with your real chatbot ID and key already filled in.