> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lovable.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect your app to the dbt Semantic Layer

> Connect your app to the dbt Semantic Layer to query governed metrics defined in dbt, sliced by dimensions and time, without writing warehouse SQL.

export const connector_0 = "dbt Semantic Layer"

The [dbt Semantic Layer](https://www.getdbt.com/product/semantic-layer) is dbt Cloud's API for governed metrics: definitions your data team maintains in dbt with MetricFlow, computed consistently wherever they are queried. The connector lets your Lovable app query those metrics directly instead of writing SQL against your warehouse.

With the dbt Semantic Layer, your app can:

* Query governed metrics sliced by dimensions and time grains
* Discover the metrics and dimensions defined in your dbt project with metadata queries
* Filter, order, and limit results
* Read the same metric definitions used across your BI stack
* Power dashboards, embedded analytics, and metric explorers

The connector is **read-only**: your app reads metric values, while your data team continues to define and maintain the metrics in dbt.

## Common use cases and example apps

| Example app                           | Example prompt                                                                                                                   | Description                                                                                                                                                         |
| :------------------------------------ | :------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **Company KPI dashboard**             | *Use the dbt Semantic Layer and build a KPI dashboard that shows monthly revenue and active customers with filters by region.*   | **Turn governed metrics into charts in your app.**<br />The app queries metric values by month and region and renders trends everyone can trust.                    |
| **Embedded analytics**                | *Use the dbt Semantic Layer and build a customer-facing usage page that shows each account's key metrics over time.*             | **Show customers metrics from your own data stack.**<br />The app slices metrics by account dimensions and presents them inside your product.                       |
| **Metric explorer**                   | *Use the dbt Semantic Layer and build a metric explorer where I pick a metric, slice it by any dimension, and chart the result.* | **Self-serve exploration on top of defined metrics.**<br />The app discovers available metrics and dimensions with metadata queries and lets users combine them.    |
| **Natural-language metric questions** | *Use the dbt Semantic Layer and build a chat interface that answers questions like "what was revenue by region last quarter?"*   | **Answer questions with governed numbers.**<br />The app maps each question to a metric query, so answers come from your dbt definitions rather than generated SQL. |
| **Board and executive reporting**     | *Use the dbt Semantic Layer and build an executive report page with quarterly trends for our core metrics.*                      | **Recurring reporting from a single source of truth.**<br />The app queries quarterly grains for the metrics leadership follows and lays them out as a report.      |
| **Team scorecard**                    | *Use the dbt Semantic Layer and build a team scorecard that compares this week's metrics against the previous week.*             | **Track performance with consistent definitions.**<br />The app queries the same metrics at weekly grains and highlights week-over-week changes.                    |

## How dbt Semantic Layer connections work

* **Queries**: Your app queries metrics through the GraphQL API at your Semantic Layer's `/api/graphql` endpoint. dbt's MetricFlow generates the warehouse SQL from your metric definitions.
* **Gateway**: Requests are proxied through Lovable's [connector gateway](/integrations/introduction#gateway-based-connectors), which injects your dbt service token. The token is never exposed in app code.
* **Environment**: Every Semantic Layer query includes an `environmentId` argument. Lovable syncs the environment ID from the connection to linked projects so app code can use it.

<Note>
  Semantic Layer queries run through your dbt Cloud account and your data warehouse. Usage counts toward your dbt Cloud plan, and warehouse compute is billed by your warehouse provider, not by Lovable.
</Note>

## How to connect the dbt Semantic Layer

Who can connect the dbt Semantic Layer depends on your plan and workspace settings. See [Who can create connections](/integrations/introduction#who-can-create-connections) for details.

Each connection queries one dbt environment. You can create multiple connections with different environment IDs or service tokens, for example to separate staging and production environments.

### Prerequisites

Before connecting the dbt Semantic Layer, make sure you have:

* A dbt Cloud account on a plan that includes the dbt Semantic Layer (Starter, Enterprise, or Enterprise+)
* The dbt Semantic Layer configured for the environment you want to query, with MetricFlow metrics defined in your dbt project
* Permission to create connections in your Lovable workspace

### Step 1: Get your credentials in dbt Cloud

You need three values from dbt Cloud: the Semantic Layer host, the environment ID, and a service token.

<Steps>
  <Step title="Open the Semantic Layer settings">
    Sign in to dbt Cloud, open **Account settings**, select your project, and open its **Semantic Layer** settings.
  </Step>

  <Step title="Copy the Semantic Layer host">
    Copy the GraphQL API host shown in the Semantic Layer settings, for example `semantic-layer.cloud.getdbt.com`. Hosts are region-specific, so copy the exact value dbt shows for your account.
  </Step>

  <Step title="Copy the environment ID">
    Copy the numeric ID of the environment the Semantic Layer is configured for. This is the environment whose metrics your app queries.
  </Step>

  <Step title="Create a service token">
    Go to **Account settings → API tokens → Service tokens** and create a token with the **Semantic Layer Only** and **Metadata Only** permission sets. Copy the token; it starts with `dbtc_`.
  </Step>
</Steps>

<Warning>
  Your service token functions like a password. Store it securely and never share it publicly. You'll need it in the next step.
</Warning>

See dbt's documentation for detailed instructions: [Set up the dbt Semantic Layer](https://docs.getdbt.com/docs/use-dbt-semantic-layer/setup-sl).

### Step 2: Connect the dbt Semantic Layer to Lovable

<Steps>
  <Step title="Open dbt Semantic Layer in Connectors">
    Go to **Connectors → App connectors** and select **dbt Semantic Layer**.
  </Step>

  <Step title="Add a connection">
    Click **Add connection**.
  </Step>

  <Step title="Configure the connection">
    1. **Display name**: name the connection, for example `dbt Semantic Layer Prod`.
    2. **Semantic Layer host**: enter the GraphQL API host from your Semantic Layer settings, for example `semantic-layer.cloud.getdbt.com`. Enter the bare hostname only, without `https://` or a path.
    3. **Environment ID**: enter the numeric dbt environment ID from the Semantic Layer settings.
    4. **Service token**: paste your dbt service token (it starts with `dbtc_`).
  </Step>

  <Step title="Choose who can use this connection">
    Under **Who can use this connection**, decide who in your workspace can use the connection:

    * **Only you** (default): only the person creating the connection can use it and its associated data.
    * **Invite specific people**: only you and explicitly added workspace members can use the connection and its associated data.
    * **Invite entire workspace**: click **Invite entire workspace** to make the connection available to everyone in your Lovable workspace.

    See [Who can manage connections](/integrations/introduction#who-can-manage-connections) for more information.
  </Step>

  <Step title="Connect">
    Click **Connect**. Lovable validates the credentials against your dbt environment, so the connection fails if the host, environment ID, or service token is wrong.
  </Step>
</Steps>

When connected, anyone building in a project can ask Lovable in chat to link their project to the dbt Semantic Layer (based on configured connection-level access). Your Lovable apps can then query the metrics and dimensions defined in your dbt project.

## Limitations

The dbt Semantic Layer connector is **read-only**. It cannot:

* Create or modify dbt models, metrics, or jobs, or trigger dbt runs
* Query data outside the metrics and dimensions defined in your dbt project
* Connect to dbt Core alone (it requires dbt Cloud with the Semantic Layer enabled)
* Query more than one dbt environment per connection (create a separate connection for each environment)
* Support per-end-user dbt authentication (each connection uses a single service token shared by its linked projects)

## How to unlink projects from a {connector_0} connection

Editors and above can remove specific projects from a connection without deleting the connection entirely. The connection will remain available for other projects.

To unlink projects:

<Steps>
  <Step title="Open Connectors">
    Open **Connectors**, then go to **App connectors**, and select **{connector_0}**.
  </Step>

  <Step title="Open the connection">
    Open the connection you want to manage.
  </Step>

  <Step title="Select projects">
    Under **Linked projects**, check the projects you want to unlink.
  </Step>

  <Step title="Confirm">
    Click **Unlink projects** and confirm.
  </Step>
</Steps>

When unlinked, those projects will no longer have access to {connector_0} through this connection. If a project needs {connector_0} again, you can link it to any available connection.

## How to delete a {connector_0} connection

Workspace admins and owners can delete {connector_0} connections. Other members can delete a connection if they created it, or if they have been explicitly granted access to it.

<Warning>
  Deleting a connection is permanent and cannot be undone. It will remove the credentials from all linked projects, and any apps using this connection will stop working until a new connection is added.
</Warning>

Before deleting, review the **Linked projects** section to see which projects are currently using the connection.

To delete a connection:

<Steps>
  <Step title="Open Connectors">
    Open **Connectors**, then go to **App connectors**, and select **{connector_0}**.
  </Step>

  <Step title="Open the connection">
    Open the connection you want to remove.
  </Step>

  <Step title="Review linked projects">
    Review the **Linked projects** section.
  </Step>

  <Step title="Delete">
    Under **Delete this connection**, click **Delete** and confirm.
  </Step>
</Steps>
