Prerequisites
- CometChat app (App ID, Region, Auth Key).
- Chat Widget variant configured in UI Kit Builder.
- An AI Agent already created and enabled in your app via:
- Agent Builder — build and host inside CometChat, or
- Bring Your Own Agent — connect your own hosted agent.
- Agent ID and (optional) variant set to default to that agent.
- (Optional) Frontend Action definitions if you want UI‑bound behaviors.
Finish agent creation first in Agent Builder or Bring Your Own Agent, then continue here to embed the widget.
Step 1 - Export & Embed
In UI Kit Builder click Get Embedded Code → copy credentials:- App ID
- Auth Key
- Region
- Variant ID
1
Include script (<head>)
Add script tag in document head (see snippet below).
2
Initialize (<body> end)
Add mount div + init script before closing body.
Option A - Anonymous (Guest Mode)
Use this when:- Let anyone chat anonymously without signing up or logging in.
- Perfect for marketing pages, help centers, or demo sites.
Option B - Create + Log In User On The Fly (Auth Key + UID)
Use this when:- Use your existing user IDs (email, username etc.) to create and log in users automatically.
- No backend needed—CometChat creates users the first time they visit.
Option C - Backend-Created User (Auth Token Login)
Use this when:- Create your users via server and login them using secure auth token on frontend.
- Ideal for sites with existing login systems and backends.
Replace the placeholder values (app ID, region, auth key or auth token, UID, agent ID, and variant ID) with values from your deployment. KeepchatType: "user"and setdefaultChatIDto your agent for an AI-first experience.
Step 2 - Verify
| Check | How |
|---|---|
| Agent appears | Open widget → new conversation / agent entry available |
| Basic reply | Send a prompt → response under a few seconds |
| Tool logic works | Ask for a tool-backed request (e.g., recipe lookup or data fetch) |
| Error free | Browser console + agent logs have no unhandled errors |
If responses fail, confirm the endpoint is publicly reachable and the Agent ID matches the Dashboard configuration.
Troubleshooting
| Issue | Fix |
|---|---|
| Agent not listed | Confirm it’s enabled in Dashboard + variant saved |
| 404 from agent | Endpoint path or agent key mismatch |
| Timeout | Expose via a tunnel or deploy to a public host |
| Tool not invoked | Ensure tool ID referenced in agent instructions & code |
| Auth error | Re-check Auth Key / App credentials in embed snippet |