Skip to content

API options

The keys of the API, at the top level of protobase.config.ts. The API itself is described in REST API.

  • Type: string
  • Default: /api/v1

The path of the REST API on the app’s origin. A bundle serves only /api/v1: protobase serve, the serve runtime and protobase worker refuse a config with another path, so another one works in protobase dev and in a server of the app’s own around createAdmin.

export default defineConfig({ apiPath: '/api/v2' })
  • Type: { publishable_key?: string; secret_key?: string } | false
  • Default: PROTOBASE_PUBLISHABLE_KEY and PROTOBASE_SECRET_KEY
  • Environment variables: PROTOBASE_PUBLISHABLE_KEY, PROTOBASE_SECRET_KEY

The app’s two keys, for clients that call it the way they call Supabase: with one, the app serves the PostgREST-compatible /api/sb/rest/v1, the Realtime-compatible /api/sb/realtime/v1 and the Storage-compatible /api/sb/storage/v1. The publishable key is safe in a browser and makes a request anonymous or its signed-in user’s; the secret key stays on servers and makes a request the app’s own. A publishable key that looks like a secret one, the other way round, or both the same stop the app at start. Without either, or with false, the app serves none of them. See Supabase client API.

export default defineConfig(({ env }) => ({
apiKeys: { publishable_key: env.PUBLISHABLE_KEY, secret_key: env.SECRET_KEY },
}))
  • Type: '*' | string[]
  • Default: PROTOBASE_CORS_ORIGINS, * or comma separated, when set
  • Environment variable: PROTOBASE_CORS_ORIGINS

The websites whose browser code may call the API (/api/* but /api/auth/*) besides the app’s own origins: a list of origins, or * for any. A mobile section adds the app’s Capacitor origins. With none, the API sends no CORS headers for other websites. See CORS.

export default defineConfig({ cors: ['https://shop.example.com'] })
  • Type: 'allow' | 'deny'
  • Default: without roles, allow; with roles, the capability check

What an operation without an access rule does, over the capability check of the roles in config/roles.ts. allow together with roles opens such operations to every user, and the app warns about it at start. See Access.

export default defineConfig({ defaultAccess: 'deny' })
  • Type: boolean | { except: string[] }
  • Default: true

Whether list items carry their permissions (update, delete), or { except: [...] } for the resources that leave them out. See Record permissions.

export default defineConfig({ rowPermissions: { except: ['events'] } })
  • Type: number
  • Default: 1000

How long a query of an API request may run, in milliseconds; a query that runs longer answers 504 and names the request. A query that needs longer wants an index or a simpler filter, or belongs in a function or a job with longQueries. See Safety.

export default defineConfig({ statementTimeoutMs: 3000 })
  • Type: { mode?: 'reject' | 'warn' | 'off' }
  • Default: { mode: 'reject' }

What the API does with reads that filter, sort or count by a column no index serves: refuse them, let them through with a warning, or let them through. See Safety.

export default defineConfig({ scanGuard: { mode: 'warn' } })
  • Type: { dsn?: string; environment?: string } | false
  • Default: the DSN in PROTOBASE_SENTRY_DSN, when set
  • Environment variable: PROTOBASE_SENTRY_DSN

Where the app’s errors go: the server’s 500s, stopped queries and crashes, and the admin app’s errors in the browser. dsn is a project’s DSN in Sentry or a tracker that speaks its protocol, such as Bugsink or GlitchTip; environment names the deployment there. false turns it off. A DSN without a public key or a project id stops the app at start. See Error reporting.

export default defineConfig(({ command }) => ({
errorReporting: command === 'dev' ? false : { environment: 'staging' },
}))
  • Type: string[]
  • Default: none

The write hooks by name, run in this order inside each create’s, update’s and delete’s transaction, with that transaction. Each is the default export of hooks/<name>.ts, loaded on the first write; a name without its file stops the app at start with an error that names the file. A hook does database work only: while it waits on anything else, such as an HTTP call, the row stays locked, so it enqueues a job for such work. Enqueueing shows a hook that does. A hook sees the row as written; values the server makes before the write, such as a generated key, come from a resource’s .prepare().

export default defineConfig({ writeHooks: ['queue-sent-invoice'] })

A token made on create, by contrast, goes in the resource, so its not null column is written with the record:

resource('api_tokens')
// ...
.prepare((values, { operation }) => (operation === 'create' ? { ...values, token: randomBytes(24).toString('base64url') } : values))
  • Type: { sql?: boolean; writes?: boolean | { resources?: string[]; rolesWithoutApproval?: string[] }; instructions?: string } | false
  • Default: the read tools only: list_resources, describe_resource, list_records, count_records and get_record, then the tools of mcp/tools.ts

The MCP endpoint’s tools; auth.mcp turns the endpoint on. sql: true also offers admins and the ai role run_read_only_query, which reads the whole database outside the access rules. writes: true offers create_record, update_record, delete_record and batch_write through the REST API’s rules, each approved by the person in their client; writes.resources limits them to the resources named, and writes.rolesWithoutApproval lets holders of those roles, such as a service account, write without the approval. instructions is the app’s own text clients read when they connect, after the framework’s, within 2,691 characters: see The app’s instructions. false is for a host that serves its own MCP endpoint at auth.mcp.path, in front of this app. See MCP. The app’s own tools are the default export of mcp/tools.ts, an array of defineTool(...), offered after these; with extensions, the extensions’ come first. See The app’s own tools.

export default defineConfig({ auth: { mcp: true }, mcpEndpoint: { writes: { resources: ['tasks'] } } })
  • Type: { url: string; label: string; resources: string[]; roles?: string[] }[] | false
  • Default: those PROTOBASE_SOURCES lists
  • Environment variable: PROTOBASE_SOURCES, a JSON list of the same objects, added after the config’s

Other Protobase APIs whose resources the admin app draws as its own. url is the other API’s resources API, such as https://other.example.com/api/v1; label names it to people when it cannot be reached; resources are the ones drawn from it; with roles, only callers holding one of them see it. false turns off both the config’s and the variable’s. See Remote resources.

export default defineConfig({
remoteResources: [{ url: 'https://crm.example.com/api/v1', label: 'CRM', resources: ['contacts'] }],
})
  • Type: { url?: string } | false
  • Default: PROTOBASE_RUNTIME_URL, when set
  • Environment variable: PROTOBASE_RUNTIME_URL

The endpoint that reports the app’s runtime version and updates it, such as a hosting platform’s; the top bar shows an update button to admins from what it answers. false turns it off. See Runtime updates.

export default defineConfig({ runtimeUpdates: false })
  • Type: { processes?: 'one' | 'many', sqlSends?: boolean, relay?: { url, app, apiKey, ticketKey, channels, presence? } }
  • Default: { processes: 'one', sqlSends: false }

How channels and Supabase Realtime are served. With 'one', one process serves the app, and broadcasts and presence go between its channels in memory. Set 'many' when several processes serve the app behind one address: broadcasts and presence then go between the processes through the realtime_relay schema of the app’s database, which protobase migration writes and the server checks at start. See Several processes. Set sqlSends: true to let SQL in the app’s database broadcast to channels with channels.send(), from the channels schema that protobase migration writes and the server checks at start. See From SQL. With relay, the app also hands its realtime connections to a relay, so it can sleep while people stay connected; see Realtime relay.

export default defineConfig({ realtime: { processes: 'many', sqlSends: true } })
  • Type: { backend: { kind: 'livekit', url: string, apiKey: string, apiSecret: string } | { kind: 'peer', iceServers?: { urls: string[], username?: string, credential?: string }[] } }
  • Default: none: no calls

The media plugin that carries the audio and video of the calls API functions admit members to with calls.join: a LiveKit server, or the members’ browsers peer to peer. Without it, calls.join rejects and the app loads no calls code. See Calls.

export default defineConfig(({ env }) => ({
calls: { backend: { kind: 'livekit', url: env.LIVEKIT_URL!, apiKey: env.LIVEKIT_API_KEY!, apiSecret: env.LIVEKIT_API_SECRET! } },
}))
  • Type: boolean
  • Default: false

true keeps the tables the app’s users add in its own database, in the table_definitions and user_tables schemas that protobase migration writes, and serves each one like a resource in code. With organizations, each organization keeps its own tables; an API that trusts the organization tokens of an auth server elsewhere (authenticate.organizations without auth.organizations) cannot turn it on. See User tables.

export default defineConfig({ userTables: true })

Two files of the project’s own change what the API does, each its default export, with no key in the config:

  • hooks/error.ts: called with every error the API answers 500 for, every query stopped at its statement timeout and every request that found all database connections busy, and the request it failed, so the app can report it. See Errors.
  • audit/queue.ts: the AuditQueue that receives an event for every reveal of a sensitive field; without it, each is printed to the console and nothing is kept. See Sensitive fields and audit.
hooks/error.ts
export default (error: unknown, request?: Request) => {
console.error(request?.url, error)
}