Docs
Embed on your website
Add your chatbot to any website as a chat bubble, an iframe, or a component.
Open your chatbot and go to Connect. Each option below has ready-made code with your chatbot's API key already filled in, so the quickest route is to copy it from there.
Chat bubble
The chat bubble is a floating button in the corner of the page that opens the chat. Paste the script before the closing </body> tag of your site:
<script src="https://www.mochii.ai/widget.js"></script>
<script>
new MochiiWidget({
apiKey: "YOUR_API_KEY",
domain: "https://www.mochii.ai",
title: "Customer Support",
primaryColor: "#7C3AED",
firstMessages: ["Hi! How can I help you today?"],
});
</script>
Replace YOUR_API_KEY with the key shown under Connect. See the widget reference for all options.
Iframe
To place the chat inside your page layout instead of in a floating bubble, copy the iframe code from Connect → Website → Embed and paste it where the chat should appear.
NPM package
For applications built with a bundler, install the widget package:
npm install @mochii-ai/widget
React
import { MochiiChat } from "@mochii-ai/widget/react";
export default function ChatWidget() {
return <MochiiChat apiKey={process.env.NEXT_PUBLIC_MOCHII_API_KEY} />;
}
Vue
<template>
<MochiiChat :api-key="apiKey" />
</template>
<script setup lang="ts">
import { MochiiChat } from "@mochii-ai/widget/vue";
const apiKey = import.meta.env.VITE_MOCHII_API_KEY;
</script>
JavaScript or TypeScript
import { MochiiWidget } from "@mochii-ai/widget";
const widget = new MochiiWidget({
apiKey: "YOUR_API_KEY",
});
API
If you want to build your own interface, Connect → API shows the API endpoint and API key for your chatbot. Send the key in the X-API-KEY request header.
API keys
The API key identifies your chatbot. It is visible to anyone who views your page source when used in a browser widget, which is expected. If you need to revoke a key, regenerate it under Connect; the old key stops working and you will need to update your embed code.
Usage and billing
Conversations through the website widget, the API and messaging channels all use credits from your account. Set a credit limit in the chatbot's settings to cap its usage.