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

# The ai schema

> Where the AI surface's state (sources, knowledge bases, agents, runs, sessions, workflows) lives, and why it's backend-only: the ai schema isn't exposed through PostgREST. Reach AI resources through the typed /api/* endpoints.

The typed `/api/*` surface gives you RPC-style access to the AI features. Underneath, the state those endpoints manage lives in a single Postgres schema, `ai`: sources, knowledge bases, chunks, agents, runs, sessions, workflows and the rest.

The `ai` schema is **backend-only**. Only the project service, using the Service Role, touches it. It isn't exposed through PostgREST, and signed-in users and the Anon key have no access to it. Earlier versions of this page described querying `ai.*` via `/rest/v1/*`; that no longer works.

## How `ai.*` is locked down

Since project-service migration `0025_lock_ai_schema_class_b`:

* `ai` is not in PostgREST's exposed schemas (`PGRST_DB_SCHEMAS`), so `/rest/v1/*` requests with `Accept-Profile: ai` or `Content-Profile: ai` are rejected, whichever key you use.
* Every `authenticated` and `anon` grant on the schema, its tables, sequences and RPC functions is revoked, and every `authenticated` / `anon` RLS policy on `ai.*` is dropped.
* RLS stays enabled with no client policies, so access is deny-by-default. The service role bypasses RLS, which is how the project service reads and writes.

There are no per-user or per-tenant database policies on `ai.*`.

## Reaching AI resources

Use the typed `/api/*` endpoints. Almost all of them require the Service Role (Secret) Key. A signed-in user's JWT from the project's GoTrue works only on the conversation routes: the user's own agent and orchestration sessions, runs on them, and approvals of their own paused runs. The full list is in [Which key for which route](https://docs.powabase.ai/guides/auth-connection.md#which-key-for-which-route).

Per-user scoping on those conversation routes is enforced in application code:

* Reading a session, its messages or its runs returns `404` unless the caller owns the session.
* A run continues only an existing session that belongs to the caller, and an end user can't name a new session id.
* Session listings are scoped to the caller.
* An end user's run uses the knowledge bases configured on the agent; it can't name other knowledge bases or stored context.

Service Role callers bypass these checks. Knowledge bases, knowledge-base search, sources, agent configuration and workflows answer an end user's token with `403`.

> [!WARNING]
>
> **Multi-user projects: AI resources are project-wide.**
>
> Every knowledge base, agent and workflow in a project is visible to anything holding the Service Role key, and an agent's configured knowledge bases are searched the same way for every user who talks to it. If end users shouldn't see each other's documents or search results, enforce that in your backend (for example, one knowledge base per tenant, or tenant filters your backend adds to every search). For hard isolation between customers, give each customer its own project.

## Your own tables

Tables you create in `public` work the normal way: PostgREST exposes them at `/rest/v1/*` and Row Level Security with `auth.uid()` / `auth.jwt()` protects them. See the [RLS Model](https://docs.powabase.ai/concepts/rls-model.md) page and the [RLS Cookbook](https://docs.powabase.ai/guides/rls-policies.md).

## Tables in the ai schema

For reference, the main tables:

| Domain | Tables |
| - | - |
| **Sources** | `sources`, `indexed_sources` |
| **Knowledge bases** | `knowledge_bases`, `chunks`, `embeddings`, `enrichment_configs` |
| **Strategy-specific item tables** | `page_index_toc`, `page_index_nodes`, `full_documents`, `doc2json_documents`, `graph_index_toc`, `graph_index_nodes` |
| **Agents** | `agents`, `agent_sessions`, `agent_runs`, `agent_tools`, `agent_knowledge_bases`, `agent_mcp_servers`, `hooks` |
| **Orchestrations** | `orchestrations`, `orchestration_entities`, `orchestration_sessions`, `orchestration_runs` |
| **Workflows** | `workflows`, `workflow_blocks`, `workflow_edges`, `workflow_executions`, `workflow_block_logs` |
| **Tools** | `tools` |
| **Context** | `context_handlers`, `tool_call_events`, `message_citations` |
| **Copilot** | `copilot_sessions`, `copilot_messages` |
| **Settings** | `project_settings`, `ai_provider_keys` |

The schema grows as the platform adds features. Treat it as the platform's internal storage, not a stable API.

## Next steps

> [card] [Agents Reference](https://docs.powabase.ai/api-reference/agents.md)
>
> The typed endpoints for agents, runs and sessions.

> [card] [Knowledge Bases Reference](https://docs.powabase.ai/api-reference/knowledge-bases.md)
>
> The typed endpoints for knowledge bases, indexing and search.

> [card] [RLS Model](https://docs.powabase.ai/concepts/rls-model.md)
>
> How roles, JWT claims, and auth.uid() compose to gate access to your own tables.

> [card] [Database Access](https://docs.powabase.ai/concepts/database-access.md)
>
> The ways into your project's Postgres: typed API, PostgREST, direct connection.


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