Skip to main content
Embedding requires the embedding add-on for Cloud Pro or Enterprise. Get in touch to add embedding to your plan. For self-hosted deployments, follow embedding setup.
Try it and see the code. embed.lightdash.com is an interactive demo and helper that lets you preview embedded content and generate a JWT for your own project. For a working end-to-end example, see the example embed app on GitHub — a Node.js app that mints tokens server-side and renders a Lightdash dashboard.

Overview

AI agent embedding lets you drop a Lightdash AI agent into your own application. Embedded users can start new threads, ask questions in natural language, and view the charts the agent generates — all scoped to a single agent and space that you control with the embed JWT. AI agent embeds use the same JWT-based security model as dashboard and chart embeds, but with a dedicated content.type: "aiAgent" token. Dashboard and chart tokens cannot access AI agent routes, and an AI agent token only grants access to the agent named in the token.

When to use AI agent embedding

  • Add a “Chat with your data” experience to your customer-facing app
  • Let customers ask ad-hoc questions about their own data without giving them a Lightdash login
  • Scope each customer’s AI session to their own spaces, so the agent only sees and writes content the customer is allowed to see
  • Keep one shared conversation per customer dashboard, with the agent’s changes limited to that dashboard
To build your own chat interface instead, connect it to the Lightdash MCP server. MCP clients sign in as a Lightdash user, through OAuth or a personal access token, or with a service account token. There’s no embed token: to scope each request to one of your customers, pass their attributes in the X-Lightdash-User-Attributes header. Charts from render_chart only display in MCP App-capable clients, so your interface draws charts itself from the query results.

Available features

Embedded AI agents support:
  • Creating and continuing threads with the agent, and stopping or steering an answer while it streams
  • Resuming a previous conversation on load, and listing past threads to build your own thread history UI
  • Binding a thread to a dashboard and giving it background context
  • Viewing agent-generated charts and tables in the response
  • Opening saved charts and dashboards the agent references, when they live in one of the token’s write spaces or sourceSpaceUuids: charts in a side panel next to the chat, dashboards as a read-only view inside the embed
  • Saving AI-generated charts into the token’s write spaces (via write actions)
  • Row-level filtering via user attributes
Embedded AI sessions hide non-embed UI surfaces by default — including thread history sidebars, dashboard navigation, SQL mode, MCP server tools, and user preference screens. Saved charts from the write spaces open in a read-only side panel, and saved dashboards from those spaces open as a read-only view with a “Back to AI” control, both inside the embed. “Explore from here” appears only when the token sets content.canExplore or the actor’s role grants view:EmbedExplore, and Explore stays inside the embed. The Debug panel on agent answers is hidden unless the token sets content.canViewDebugInfo (or the actor’s role grants it in roles mode); see Debug information. View SQL and Download on chart answers follow the actor’s role; see SQL and downloads on answers. Embedded users can’t verify answers, whatever the token or the actor’s role, so verify them in the Lightdash app. Links to other content, such as documents or scheduled deliveries, are shown as plain references.

Prerequisites

Before you embed an AI agent, you need:
  • An AI agent configured in your Lightdash project. See Set up AI agents.
  • An embed secret for the project. See Embedding quickstart.
  • At least one space where AI-generated charts will be saved.
  • A service account user (or regular Lightdash user) to act as the writer for AI actions. See Write actions.

Embed an AI agent with the React SDK

The React SDK ships a Lightdash.AiAgent component. Use it when you want the agent to live inside a React or Next.js app. By default it renders the agent inside an iframe; set renderMode="native" to render it directly in your page instead .
You can pass a threadUuid to deep-link the embed straight into an existing thread, or omit it to land on the new-thread screen. Pair it with the onThreadChange callback to persist the active thread in your app (for example in localStorage) so users pick up where they left off next time they visit. To render a list of the embed user’s previous conversations, use the Lightdash.useLightdashAiAgentThreads hook — it calls the AI agent threads endpoint with the same embed JWT and returns only threads scoped to the JWT user and their embed space. See Lightdash.AiAgent for the full prop list and styling options.

Resuming a thread from an iframe embed

If you construct the embed URL yourself (Node, Python, Go, or any other backend), append the thread UUID as an extra path segment before the JWT fragment to resume a specific conversation:
Omit the /{threadUuid} segment to land on the new-thread screen. The thread must have been created with an embed token for the same agent, write actor, and first write space — thread access is enforced server-side. Threads aren’t separated by user.externalId, so every viewer whose token shares that actor and first write space can open them.

Bind a thread to a dashboard

A thread can be bound to one dashboard for its whole life, and can carry background context for the agent. Use this when each customer has a dashboard with one shared conversation, for example to keep a dashboard’s conversation going after you copy it into another customer’s space. In a bound thread:
  • A Linked dashboard card at the top of the thread opens the dashboard.
  • The agent treats “this dashboard” as the bound dashboard. If the agent can create content, its changes are limited to that dashboard and the charts saved in it; see Threads bound to a dashboard.
  • The thread context, up to 10,000 characters, is given to the agent on every turn as background from the user. It is never shown as a chat message, and embedded viewers can’t read it back.
  • Neither the binding nor the context can be changed after the thread is created.
The dashboard must be in one of the token’s write spaces or sourceSpaceUuids. When it’s in a source space, the agent reads it and answers questions about it but can’t change it; anything the agent creates from it, such as a copy filtered to one region, is saved into a write space. To refresh an embedded dashboard after the agent edits it, see Refresh a dashboard after the agent saves it.

From the React SDK

Pass binding and threadContext to Lightdash.AiAgent. The embed creates the bound thread when the user sends the first message, and onThreadChange returns its UUID so you can reopen it later. See Start a thread bound to a dashboard for the example.

From your backend

To create a bound thread before anyone opens it, call the create-thread endpoint from your server with the customer’s AI agent embed token in the lightdash-embed-token header. prompt is optional when you send binding or threadContext; without one, the thread starts empty.
The response’s results.uuid is the thread UUID; pass it to Lightdash.AiAgent as threadUuid, or add it to the iframe URL.
Create the thread with the same embed token setup your viewers use. A thread created with a personal access token or a Lightdash session isn’t attached to an embed space, so embedded viewers can’t open it.
If the bound dashboard is deleted later, the thread stays bound and shows Dashboard no longer available. The agent can still answer questions and run queries, but can’t create or change saved content in that thread.

Generate an AI agent embed token

AI agent embeds require a JWT with content.type: "aiAgent" and a writeActions claim. Generate it server-side using your embed secret; the embedding reference has the complete token structure.
Required fields:
  • content.type — must be "aiAgent".
  • content.agentUuid — the agent the embed is allowed to use. Tokens cannot switch to a different agent at runtime.
  • writeActions.writeSpaceUuids — the spaces the agent can create and update charts and dashboards in, and read them from. The first space is the default save target and scopes the embed’s threads.
  • One of writeActions.serviceAccountUserUuid or writeActions.userUuid — the actor whose permissions are used when the agent runs queries and saves charts, and whose name appears next to messages in the chat. See Write actions.
Every space on the token — each write space, and each space in writeActions.sourceSpaceUuids — is gated twice: the write actor needs its own view access to it, and if the agent itself is restricted to certain spaces, the space must be on the agent’s own list. A space that fails either check is silently dropped from what the agent can read or bind to; the token as a whole is only rejected once the agent has access to none of the write spaces. See Add charts from other spaces for the full rules, including sourceSpaceUuids. Optional fields:
  • content.projectUuid — pins the embed to a specific project.
  • content.canViewDebugInfo — shows the Debug panel on agent answers. See Debug information.
  • writeActions.sourceSpaceUuids — extra spaces the agent can read, search, and bind threads to dashboards in, without being able to create or update content in them. See Add charts from other spaces.
  • userAttributes — applies row-level filters to the agent’s queries, identical to other embed types.
  • user.externalId / user.email — identifies the embedded viewer. Agent queries run as the write actor, so neither value is sent as a warehouse query tag; see User metadata for per-viewer attribution.

Access control

To let the actor’s role enable or disable embedded AI access, configure Permission modes in your server-side token generation. AI agent embeds enforce a tight scope:
  • A token issued for agent A cannot access agent B, even within the same project.
  • The agent can read dashboards and saved charts that live in the token’s write spaces or sourceSpaceUuids, and only the spaces the write actor can view and the agent itself has access to. Other content returns a not-found error.
  • Embedded viewers can open those saved charts in the chat side panel and those dashboards as a read-only view. Both run with the write actor’s permissions and the token’s userAttributes; content outside that scope is rejected.
  • Charts are saved into the first write space by default. When the actor can create charts in more than one write space, the save dialog lets embedded users choose among them.
  • Threads belong to the write actor and the first write space. Changing which space comes first changes which past threads viewers see.
  • In a bound thread, the agent can only change the bound dashboard and the charts saved in it.
  • Query results respect the write actor’s permissions and any userAttributes claims on the JWT, so embedded viewers only see the rows they’re entitled to.
  • Dashboard and chart embed tokens are rejected by AI agent routes, and AI agent tokens are rejected by dashboard or chart routes.