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

# Connect Supabase (read-only)

> Let an assistant look up data in your Supabase project during a conversation, with a read-only request.

With a [webhook](https://docs.klatt.ai/voice-agent/webhooks.md) during the conversation, an assistant can read data that lives in your Supabase project, for example the status of an order or a booking, or your opening hours. Klatt only sends a read request (GET). In function mode, what the function does is up to you: keep it read-only.

## Choose a mode

| Your data | Mode | How it is protected |
| - | - | - |
| Customer or personal data (orders, bookings, names) | **Function** | An Edge Function in your project answers only to a key that Klatt generates. The table stays closed to the public. |
| Public data (opening hours, catalog, prices) | **Table** | Klatt reads the table directly with your publishable key. Row Level Security (RLS) is on and a `SELECT` policy allows reading. |

Use the table mode only if you do not mind that anyone can see this data. The publishable key is not secret, so anyone who has it can read every row the policy allows. For anything personal, use a function.

If your app was built with Lovable, it already runs on Supabase. A Lovable app can create the function for you.

## With your AI assistant

If you connect an AI assistant to [Klatt's MCP](https://docs.klatt.ai/api-reference/mcp.md), you can ask it to set the webhook up for you. For example:

> Connect my Supabase function `<function>` to my Klatt assistant `<assistant>`, to look up a booking by the caller's phone number. Read Klatt's Supabase guide first.

The assistant reads this guide and creates the webhook without the key. It then gives you a link to the console.

1. Open the link and press **Generate key** in **Authentication**. Copy the key.
2. Save the key in your function as the secret the assistant names, `KLATT_KEY_<FUNCTION>`, as in the [function steps](#function-mode-with-lovable) below.

Never give the key to the assistant, in the chat or anywhere else. Klatt does not accept it from there.

A second webhook to the same function (for example one to look up a customer and one to create it) needs no new key. Supabase keeps one secret per function, so Klatt keeps one key per function too: the new webhook uses the key of the first one, and the assistant does not ask you to generate or store another. If you press **Generate key** on one of them later, store the new key in the function once.

## Function mode with Lovable

1. In your Supabase project, or in Lovable, get the address of your function. It looks like `https://<project-ref>.supabase.co/functions/v1/<function>`. If you do not have a function yet, [create one](#i-do-not-have-a-function-yet) first.
2. In Klatt, open the assistant. In **General**, under **Abilities**, open **Webhooks** and select **Add webhook**. Choose **During the conversation** and paste the address in **URL**.
3. A Supabase card appears under the URL. Press **Use this setup**. It sets the method to GET and the **Authentication** type to **Custom header**, and fills the search value in the URL. You can undo it.
4. In **Authentication**, press **Generate key**, then **Copy**. The key is shown once. After you save it, you cannot see it again, only generate another.
5. In **Authentication**, copy the message for Lovable and paste it into Lovable. Lovable asks you for the key in a secure field: paste the key there.

   > In the Edge Function `<name>`, do not require a Supabase login for this function. Reject the request unless the `KLATT_KEY_<FUNCTION>` secret is set and the klatt-key header matches it, compared in constant time. Ask me for the value of `KLATT_KEY_<FUNCTION>` in a secure field.

   `KLATT_KEY_<FUNCTION>` is the function name in capitals with `-` replaced by `_`: for `find-customer` it is `KLATT_KEY_FIND_CUSTOMER`. The console writes the right name for you. Supabase secrets are shared by every function in the project, so each function keeps its key under its own name. Otherwise, setting up a second function replaces the first one's key, and the first webhook starts failing with 401.

   Without Lovable, open your project in Supabase, go to **Edge Functions → Secrets**, and add a secret named `KLATT_KEY_<FUNCTION>` with the key. Your function must then reject any request when that secret is empty or when its `klatt-key` header is different, compare the two in constant time, and must not require a Supabase login.
6. Press **Test request**. When it works, press **Save**.

The key is only sent to the address shown next to it in **Authentication**. Check that it is your function.

### I do not have a function yet

Paste this into Lovable and replace the names. It creates the function and its protection together:

> Create a Supabase Edge Function called `<function>`. It receives the parameter `<parameter>` and returns only the `<fields>` of the `<table>` row that matches it. Do not require a Supabase login for this function. Reject the request unless the `KLATT_KEY_<FUNCTION>` secret is set and the klatt-key header matches it, compared in constant time, and ask me for the `KLATT_KEY_<FUNCTION>` value in a secure field. Keep the table closed to public access. Tell me the function URL.

Return only the fields the assistant needs to answer. Everything the function returns can end up in the conversation.

## Table mode

1. In Supabase, open **Table Editor**, choose the table and make sure **RLS** is enabled.
2. Add a policy that allows `SELECT` for everyone, for example **Enable read access for all users**. Share only a table that holds public data.
3. In **Project Settings → API Keys**, copy the **Publishable key**, which starts with `sb_publishable_`. In older projects it is called `anon`.
4. In Klatt, open the assistant. In **General**, under **Abilities**, open **Webhooks** and select **Add webhook**. Choose **During the conversation** and paste your project address, `https://<project-ref>.supabase.co`, in **URL**.
5. In the Supabase card, enter the **Table** and press **Use this table**. It builds the address with `select=*` and sets **Authentication** to **API key**, with the header `apikey`.
6. Paste the publishable key into **Authentication**. Add a filter to the URL if the assistant should look up one row, for example `?select=*&<column>=eq.{{<value>}}`.
7. Press **Test request**, then **Save**.

## Keys Klatt does not accept

Klatt does not let you save a Supabase secret key (`sb_secret_…`) or a `service_role` key in a webhook, in **Authentication**, in a header or in the URL. These keys open your whole database and bypass RLS, so an assistant, or anyone who could make it say the key, would have full access. Use the publishable key (table mode) or a key generated by Klatt (function mode) instead.

For more on Supabase's keys, RLS and function protection, see Supabase's own documentation:

* [API keys](https://supabase.com/docs/guides/api/api-keys)
* [Row Level Security](https://supabase.com/docs/guides/database/postgres/row-level-security)
* [Securing Edge Functions](https://supabase.com/docs/guides/functions/auth)

## Empty values in the browser preview

When you talk to an assistant in the browser preview there is no real call, so the caller's number (`personNumber`) is empty. A lookup that uses it shows **Missing the caller's number** and the note that the preview has no real call. **Test request** uses an example number instead, and a real call fills in the real one. To try a lookup in the preview, use a value the customer says, or test with a real call.

## Troubleshooting

| What you see | What to do |
| - | - |
| **Your function does not accept the key**, or a 401 error | Check that Lovable finished and that the function has the same key. If in doubt, press **Generate key** again, update the function and test again. If it still fails, ask Lovable to stop requiring a Supabase login for that function: Supabase checks it before your code runs. |
| **That's your Lovable app's address** | The address ends in `lovable.app`. The assistant needs the address of a Supabase function. Ask Lovable for it with the message in the card. |
| **It works, but it found nothing** | Test with a value that exists in your data. In table mode, check that the table has a `SELECT` policy. |
| **The URL is missing** a value | The URL uses a value that has no data, such as the caller's number in the preview. Give it a test value or remove it. See [above](#empty-values-in-the-browser-preview). |
| **That key cannot be used** | You pasted a secret or `service_role` key. Use the publishable key, or generate a key in Klatt. |
| The server rejected the credentials (403) in table mode | Check that the publishable key is right and that the table has RLS and a `SELECT` policy. |

For other messages, see [Test the request](https://docs.klatt.ai/voice-agent/webhooks.md#test-the-request).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.