Website & Web Apps

JavaScript Embed

Embed your AI agent directly into your website with a simple script tag. This integration provides a lightweight, customizable chat widget that loads asynchronously and doesn't block page rendering.

Features

  • Zero-dependency lightweight script
  • Asynchronous loading (non-blocking)
  • Customizable positioning and styling
  • Domain whitelist security
  • Mobile responsive design
  • Real-time message delivery
  • Session persistence

Requirements

  • An active AI agent
  • HTTPS-enabled website (required for security)
  • Domain whitelist configured (recommended)

Setup

  1. 1Navigate to Your APIs page in your dashboard
  2. 2Find "JavaScript Embed" and click "Connect"
  3. 3Select the agent you want to embed
  4. 4Configure domain whitelist (optional, for security)
  5. 5Copy the generated script tag
  6. 6Paste the script before the closing </body> tag on your website
  7. 7The widget will automatically load and display

API Reference

Endpoint:GET /api/embed.js

Authentication

Token-based authentication via query parameter

Rate Limits

1000 requests per hour per domain

Code Examples

cURL

curl "https://your-domain.com/api/embed.js?agent_id=YOUR_AGENT_ID&token=YOUR_TOKEN"

JavaScript

<script src="https://your-domain.com/api/embed.js?agent_id=YOUR_AGENT_ID&token=YOUR_TOKEN"></script>
<script>
  CentralAI.embed({
    agentId: 'YOUR_AGENT_ID',
    container: document.body,
    position: 'bottom-right', // 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left'
    theme: 'light', // 'light' | 'dark'
    primaryColor: '#70FF5B'
  });
</script>

Troubleshooting

Issue: Widget not appearing

Solution: Check browser console for errors, verify agent_id and token are correct, ensure domain is whitelisted

Issue: CORS errors

Solution: Ensure your domain is added to the whitelist in integration settings