> The HTTP layer over your Layero project database — tables, functions, user sign-in, files. Compatible with Supabase clients.

<!-- https://docs.layero.ru/en/data-api/ -->

> **Problems with this page.** Layero fixes its documentation from
> reports. If this page was wrong, outdated, or did not have what was
> needed (even if the answer was then found in the CLI's source code), a
> short report — page, quote, problem, the command and what it returned —
> can be sent with the Layero MCP tool `report_docs_issue` or
> `POST https://api.layero.ru/public/docs-feedback`, once the user agrees.
> No sign-in, no code or data from the user's project. Template and
> rules: https://docs.layero.ru/en/agents/feedback.md

# Data API

:::info[Beta]

Data API is in beta. Everything described on these pages already works, but
names, buttons, and endpoint responses are still changing. A page may lag
behind the product by a few days; if you notice a discrepancy, write to us in
the dashboard chat — it helps.

**Data API is available on the Pro plan.** On the free plan the «Data API», «Авторизация» (Sign-in) and «Файлы» (Files) items on the database page are visible, but
you can turn them on only after [upgrading to Pro](../billing/plans.md).

:::

**Data API is your database, available over HTTP.** The frontend talks to it
directly: no server to write, nothing to deploy, nothing to pay for an idle
container.

The address is `https://data.layero.ru/<database>`, where `<database>` is the
database slug from the panel. A request looks like this:

```bash
curl "https://data.layero.ru/moya-baza/rest/v1/entries?select=*&limit=5" \
     -H "apikey: pk_live_…"
```

## The contract is Supabase

Paths, headers, the response shape, and error codes mirror PostgREST and
GoTrue. This means **`@supabase/supabase-js` works** — the same client, the
same examples, the same filter documentation:

```js
import { createClient } from "@supabase/supabase-js";

const db = createClient("https://data.layero.ru/moya-baza", "pk_live_…");
const { data, error } = await db.from("entries").select("*").limit(5);
```

Compatibility exists for migration: a project written for Supabase runs
without editing access policies. The runtime underneath is our own, and
whatever we don't have responds with a refusal naming the missing capability,
not a silent stub — see [What's Missing](./limits.md).

## Keys and roles

A database has two keys, and the difference between them is the difference
between roles inside the database itself.

| Key | Role in the database | Where it lives |
|---|---|---|
| `pk_live_…` — public | `anon` | in the frontend bundle, visible to every visitor |
| `sk_live_…` — secret | `service_role` | only on your server |

The key is passed in the `apikey` header (as with Supabase) or as
`authorization: Bearer …`. A signed-in application user puts their token in
`authorization`, while the key stays in `apikey` — the request then runs
as `authenticated`. The roles are the same as in Supabase — policies and grants
from its migrations work as written.

🚨 **A key does not grant rights.** It selects a role, and what that role can
access is decided by grants and RLS policies inside the database itself. As
in Supabase, a new table in `public` is open to `anon` and `authenticated`
right away: without RLS it returns every row to anyone holding the public key.
Turn RLS on as soon as you create a table — see
[Tables and REST](./rest.md).

Get the keys onto your machine:

```bash
layero data env            # view
layero data env --write    # write to .env.local
```

## What to use to call it

Nothing in particular — a request is just an ordinary `fetch`. If you want a
client: our own thin `@layero/data` (calling functions) or
`@supabase/supabase-js` (tables, filters, sign-in) — the contract is
compatible with both. Details — [What's Missing](./limits.md).

## Which schemas are visible

| Schema | Tables | Functions |
|---|---|---|
| `api` | yes | yes; a new function is closed until `EXECUTE` is granted |
| `public` | yes | yes; a new function is callable right away — as in Supabase |
| `app` | yes | no |

The gateway looks for tables in three schemas and for `/rpc/` functions in
`api` and `public`. The difference is the defaults: a `public` function can be
called right after `CREATE FUNCTION`, an `api` function only after an explicit
`GRANT EXECUTE`. So keep internal helpers in a separate closed schema, not in
`public`. Details — [Functions and RPC](./rpc.md).

## What's next

- [Tables and REST](./rest.md) — reading, writing, filters, access
- [Functions and RPC](./rpc.md) — a public function as the only entry point
- [User sign-in](./auth.md) — sign-up, sessions, sign-in from the panel
- [Files](./storage.md) — buckets, policies, signed URLs
- [Accepting requests from another domain](./origins.md) — a form on a
  client's site
- [HTTP from SQL](./outbound.md) — Telegram notifications and webhooks from a database function
- [Migration pitfalls](./pitfalls.md) — where people trip up most often
- [What's Missing](./limits.md) — what's unsupported and what to do instead
