Embed an AI Chat
Last updated
Was this helpful?
Target Audience: Developers
Embed a self-service AI chat from Toucan AI into a host application to enable conversational analytics.
At least one connected and active database.
A valid API key for token generation.
(Recommended): Enriched metadata to improve the AI assistant's accuracy.
(Recommended): Row-Level Security (RLS) configured for multi-tenant data isolation.
Execute an AI analysis on your datasets to generate semantic metadata.
Review column descriptions and metric definitions to ensure the AI assistant has sufficient context.
High-quality metadata directly improves the relevance of natural language answers.
Define required token attributes (e.g., customer_id or region).
Map these attributes to specific dataset columns using the RLS interface.
Validate the configuration with different attribute values to confirm data isolation.
Generate a token including all necessary user attributes.
Set an appropriate expiration time for the session.
Ensure the token scope includes permission for the AI assistant capability.
Locate the embed snippet in your admin panel or use the following standard web component format:
Paste the embed code into your application's HTML.
Replace YOUR_AUTH_TOKEN with a dynamic variable from your backend.
Load your application and submit a test prompt (e.g., "How many hires last quarter?") to verify the connection.

In a multi-tenant environment, the integration follows this logic to ensure data privacy:
Attribute
customer_id defined in the token.
RLS Mapping
Token customer_id maps to database customer_id column.
User Query
"How many hires last quarter?".
Execution
The query is automatically filtered by customer_id before execution.
Result
The user only sees data belonging to their specific organization.
The AI assistant is now embedded and respects the security boundaries defined by your authentication tokens. Users can perform ad-hoc analysis through natural language while Toucan AI handles the underlying query generation and data visualization.
Last updated
Was this helpful?
Was this helpful?
<script type="module" src="https://toucanai.cloud/embed/embed.js"></script>
<link rel="stylesheet" href="https://toucanai.cloud/embed/embed.css" />
<tc-ai-assistant
auth-token="YOUR_AUTH_TOKEN"
server-url="https://toucanai.cloud/api"
data-theme="light"
></tc-ai-assistant>