ai schema is backend-only (see The ai schema). It isn’t exposed through PostgREST, so /rest/v1/* requests with Accept-Profile: ai or Content-Profile: ai are rejected whichever key you use. Earlier versions of this page queried ai.* that way; those examples no longer work.
These recipes do the same jobs through the typed /api/* endpoints. Where the typed surface has no equivalent, the recipe says so.
All examples assume the Service Role (Secret) Key from the Connect modal and these headers:
Call these from a trusted backend with the Service Role key. They touch project-wide data, and the routes they use (knowledge bases, sources, agents) answer a signed-in user’s JWT with
403. If you expose any of this to end users, put it behind your own API. See Which key for which route.Recipe 1: Search across several knowledge bases
POST /api/knowledge-bases/{id}/search searches one knowledge base. To search several, call it once per KB and merge the results. Each call can narrow its results with filter_metadata (fields from the KB’s enrichment config) and source_ids.
chunk_id, text, score, source_id and meta. Scores are only comparable across knowledge bases when every call uses the same retrieval_method, so set it explicitly rather than relying on each KB’s default. To search inside specific documents, pass their source ids in source_ids.
Recipe 2: Agent usage summary
GET /api/agents returns, for each agent, total_runs, session_count and last_run_at. It pages at up to 100 agents per request, and you can sort by last_run_at.
/api/* surface has no endpoint that aggregates runs or token usage over a time window; for that, use the Studio’s Observability page (see Observability). Defining your own SQL function in ai and calling it through /rest/v1/rpc/* doesn’t work either, because PostgREST doesn’t expose that schema.
Recipe 3: Bulk-tag sources
There’s no bulk update endpoint for sources. CallPATCH /api/sources/{id} once per source.
metadata in the PATCH body replaces the source’s whole metadata object; it doesn’t merge. To add one key without losing the others, read the current metadata with GET /api/sources/{id} first. The reserved keys extraction_model, source_type and source_url are dropped from the body, because the platform keeps those in auto_metadata.
Recipe 4: Per-KB source report
For a “what’s in this knowledge base and is it healthy” report,GET /api/knowledge-bases/{id}/sources joins each indexed source with its source row. Each item carries index_status, indexed_at, error_message, source_name and file_type. It pages at up to 200 rows and filters by status and name substring (q).
/api/* equivalent.
Next steps
The ai schema
Why ai.* is backend-only, and what the typed surface enforces.
Knowledge Bases Reference
Search, source listing, enrichment and metadata filters.
Sources Reference
Upload, update and re-extract sources.
Agents Reference
Agents, runs and sessions.