HTTP API
For a backend, not a browser
Section titled “For a backend, not a browser”A queue consumer, a cron job or your own API server can read and write a workspace without holding a browser socket:
import { defineTapeDB } from "@tapedb/tapedb/worker";import schema from "./tapedb.schema";
export default defineTapeDB({ schema, http: { token: (env) => env.TAPEDB_API_TOKEN },});token is at least 32 bytes, the same rule TAPEDB_CLAIM_SECRET follows. A literal string is refused when the Worker is defined, so a mistyped secret fails at deploy; the function form is refused on the request that reads it (500 api_token_misconfigured). Store it as a secret and let the function read it:
bunx wrangler secret put TAPEDB_API_TOKEN # openssl rand -base64 32The variable’s name is yours to choose.
Off by default
Section titled “Off by default”Without http, these three paths answer 404, like any other unknown path — not 401. An API a deployment did not enable cannot be found by probing for it.
A caller sends authorization: Bearer <token>. The token is compared in constant time, before the body is read and before a workspace is addressed, and it never appears in an answer. A missing or wrong token is 401 unauthorized, and so is an engine claim presented in that header: the two secrets are different.
Routes
Section titled “Routes”| Route | Body | Answers |
|---|---|---|
POST /v1/query |
{ workspace, as: { sub, role }, query } |
{ ok, data, pageInfo } — the answer the same read gives over the socket |
POST /v1/transact |
{ workspace, as: { sub, role }, writes, clientTxId? } |
{ ok, result }; writes is the transaction’s ops array, and clientTxId makes a retry a replay rather than a second write |
POST /v1/claim |
{ workspace, as: { sub, role } } |
{ token, workspaceId, roleLevel, expiresAt, expiresIn } — an ordinary claim to hand to a client |
curl https://<worker-name>.<account-subdomain>.workers.dev/v1/query \ -H "authorization: Bearer $TAPEDB_API_TOKEN" \ -H "content-type: application/json" \ -d '{ "workspace": "0190a5b2-7c3d-4e8f-9a0b-1c2d3e4f5a6b", "as": { "sub": "nightly-report", "role": 3 }, "query": { "task": { "$": { "where": { "done": false }, "limit": 50 } } } }'workspace must be a workspace id (a UUID); anything else is 400 invalid_workspace_id, answered before a Durable Object is addressed. as is validated like any claim: sub non-empty and at most 256 characters (400 invalid_sub), role a whole level from 0 to 8 (400 invalid_role), and the object itself { sub, role } (400 invalid_as).
as is an identity, not a privilege
Section titled “as is an identity, not a privilege”Every request names who it acts as, and the engine evaluates the rules for that identity exactly as it does for a socket holding that claim: role levels, filter view rules, check write rules, file rules. Nothing is bypassed — a backend acting as admin still fails a rule that denies admins, and a filter rule still hides the rows that subject may not read.
That is deliberate. An admin claim that skipped the rules would make one leaked token read every row of every workspace, and turn the rules a deployment wrote into documentation instead of enforcement.
Writes go through the same pipeline
Section titled “Writes go through the same pipeline”Validation, rules, the limits.writes budget, the log, webhooks and live-query invalidation all happen once, in the place a client’s write happens. POST /v1/transact spends the budget like any other write, and a refusal is the same 429 rate_limited with Retry-After (and model, limit, windowSeconds, retryAfterMs in the body). The backend API is not a way around the limits, and a budget it exhausts refuses the socket path too.
The claim /v1/claim mints is ordinary: a client holding it reaches exactly the routes its role allows. Minting needs TAPEDB_CLAIM_SECRET and honours TAPEDB_CLAIM_ISSUER and TAPEDB_CLAIM_AUDIENCE when they are set.
The HTTP API is experimental.