Overview
The Cobi chat widget can be embedded on any website as an iframe. Visitors interact with your AI assistant directly on your site. Authentication is handled via embed API keys that you create in the Cobi dashboard.Embed keys are scoped to a single data source and can be restricted to
specific domains for production use.
Getting Started
Create an Embed Key
Navigate to Developer > Channels in the Cobi dashboard. Click Create Embed Key and fill in:
| Field | Description |
|---|---|
| Name | A label for this key (e.g. “Production website”) |
| Data Source | The data source the embed will query against |
| Allowed Origins (optional) | Domains permitted to load the widget (e.g. https://yoursite.com) |
| Expiry Date (optional) | When the key should expire. Leave blank for no expiry |
| Chat History (optional) | Allow this key to access conversation history. Must be enabled here before the chatHistory URL parameter has any effect |
Add the Iframe to Your Site
After creating the key, you’ll see an embed snippet. Copy and paste it into your website’s HTML:
Configuration
URL Parameters
The embed URL supports the following query parameters:| Parameter | Required | Description |
|---|---|---|
key | Yes | Your embed API key |
theme | No | light, dark, or system (default). Matches the widget’s appearance to your site |
chatHistory | No | true to show the chat history panel. Only takes effect if history was enabled when the embed key was created |
userId | No | An identifier for the current user. See User Identity below |
Allowed Origins
When you specify allowed origins during key creation, only those domains can load the widget. Requests from other origins are rejected with a403 error.
- Leave empty during development to allow any origin
- For production, always specify your exact domains (e.g.
https://yoursite.com) - The
Originheader is required when allowed origins are configured
Theming
The widget respects light and dark mode via thetheme parameter:
| Value | Behavior |
|---|---|
system | Matches the user’s OS preference (default) |
light | Forces light mode |
dark | Forces dark mode |
Chat History
Chat history lets users return to previous conversations in the widget. It is controlled by two things:- Key setting: History must be enabled when creating the embed key in the dashboard. If it wasn’t, passing
chatHistory=truein the URL has no effect. - URL parameter: Even if the key supports history, you must pass
chatHistory=trueto make the history panel visible in the iframe.
User Identity
By default, the widget generates a unique user ID per browser and stores it inlocalStorage. A returning visitor on the same browser is recognised as the same user and can see their previous chats, but the same user on a different device starts fresh.
To share chat history across browsers, pass your own userId:
Pass a stable, per-user identifier from your own auth system (e.g. a database
user ID). Do not use personally identifiable information such as email
addresses as the
userId.Available Connections
The embed widget queries whichever data source you select when creating the embed key. All data source types supported by Cobi are available:| Type | Notes |
|---|---|
| PostgreSQL | PostgreSQL 12+ |
| MySQL | MySQL 8.0+ |
| MongoDB | MongoDB Atlas and self-hosted instances. See MongoDB for schema conventions |
Rate Limiting
Each embed key is rate-limited to 1,000 requests per hour. When the limit is exceeded:- The API returns
429 Too Many Requestswith aRetry-Afterheader - The widget displays a user-friendly message asking the visitor to wait
Security
Keys are hashed at rest and only the first 18 characters are stored for display. When allowed origins are configured, requests from any other domain are rejected outright. The data source is locked to the key at creation time and cannot be changed by the client. Embed requests have restricted access and cannot view internal documents. The widget does not use cookies or require user authentication.Managing Keys
From Developer > Channels you can view all active embed keys along with their allowed origins and status, and permanently revoke any key. When a key is deleted it takes effect on the next request with no delay or grace period.Troubleshooting
| Issue | Cause | Solution |
|---|---|---|
| Widget shows “Missing API Key” | No key parameter in the URL | Check the iframe src includes ?key=cobi_embed_... |
403 error | Origin not in allowed list | Add your domain to the key’s allowed origins, or leave origins empty for testing |
401 error | Key is invalid, expired, or deleted | Create a new embed key in Developer > Channels |
429 error | Rate limit exceeded | Wait for the rate limit window to reset (1 hour) |
| Widget crashes / white screen | JavaScript error | The widget includes an error boundary. Try refreshing. If it persists, check the browser console |