OpenAPI 3.1 Reference: Data API, Billing Kit & 11 Core Services
Complete OpenAPI 3.2.0 endpoint reference for Data API (/v1/db/tables/*), Project Billing Kit (/v1/billing/*), Unified Gateway, and standard error codes.
Last updated: 2026-11-24
1. Authentication & Key Separation (hb_pk_* vs hb_sk_*)
Send X-Habify-Key on all tenant requests to https://{projectSlug}.habifybase.app. Publishable keys (hb_pk_*) are browser-safe and enforce PostgreSQL RLS (falling back to role 'anon' when no JWT is present). Secret keys (hb_sk_*) are server-only and return 403 SECRET_KEY_BROWSER_FORBIDDEN when sent with a browser Origin header.
GET https://{projectSlug}.habifybase.app/v1/db/tables/orders?status=eq.paid&limit=20
X-Habify-Key: hb_pk_live_...
Authorization: Bearer <end_user_jwt>2. BaaS Data API (/v1/db/tables/{table})
Supports GET, POST, PATCH, DELETE (with full /v1/* CORS for browser apps using hb_pk_*) against public-schema tables enforcing ENABLE + FORCE ROW LEVEL SECURITY and at least one policy, plus read-only GET queries on public SQL Views WITH (security_invoker = true). System schemas (habify_sys, pg_catalog) are blocked. Includes operators eq..is, $or / $and filter groups, RLS-scoped pagination via count=exact (meta.total_count), and UPSERT via ?on_conflict=col1,col2 (&ignore_duplicates=true).
GET /v1/db/tables/products?count=exact&limit=20&filter={"$or":[{"name":{"ilike":"%áo%"}},{"sku":{"eq":"SP01"}}]}
POST /v1/db/tables/products?on_conflict=sku
Authorization: Bearer <end_user_jwt>
X-Habify-Key: hb_pk_live_...3. Project Billing Kit (/v1/billing/*)
Pre-built end-user billing endpoints inside habify_sys: GET/PUT /v1/billing/plans (carrying tax_rate & invoice_type), GET /v1/billing/wallet, POST /v1/billing/topups, GET/POST /v1/billing/subscriptions, and POST /v1/billing/subscriptions/{id}/cancel.
4. Unified Gateway (11 Core Services + ERP) & Error Codes
All 11 service proxies (/v1/{payment,invoice,storage,zalo,sms,email,ai,places,notification,chat,link}/*) and /v1/erp/events automatically inject owner_ref = project_id and strict_owner_only = true. Key error codes: OWNER_REF_REQUIRED (400), RLS_POLICY_REQUIRED (403), SECRET_KEY_BROWSER_FORBIDDEN (403), VIEW_SECURITY_INVOKER_REQUIRED (403), VIEW_READ_ONLY (405), STORAGE_QUOTA_EXCEEDED (413), RATE_LIMIT (429), and CIRCUIT_BREAKER_OPEN (503).
5. Public Forms & Anonymous Uploads (BFF Pattern)
For unauthenticated public forms (job CV uploads, clinic appointment booking, or anonymous support tickets), browsers cannot call /v1/storage/* directly with hb_pk_* alone. Submit to your Next.js Route Handler or backend server (protected with Turnstile/CAPTCHA), use HabifyServerClient (hb_sk_*) to upload private files or issue a presigned upload URL, and insert the record into PostgreSQL.
// Next.js Route Handler (server-only, hb_sk_*)
const path = `cv/${jobId}/${crypto.randomUUID()}.pdf`;
await habifyServer.storage.upload({
path,
file,
visibility: "private",
});
await habifyServer.db.from("applications").insert({ job_id: jobId, cv_path: path });6. Live Chat & Notification Realtime (/v1/chat/me/*, /v1/notification/me/*)
When end-users call /v1/chat/me/* (conversations, messages, typing, reactions, realtime/auth) or /v1/notification/me/* (inbox, mark read, preferences, realtime/auth) with hb_pk_* + an End-User JWT, the Gateway automatically namespaces the user identity per project and mints short-lived recipient tokens scoped to owner_refs = [project_id]. For unauthenticated guest live chat, proxy through your BFF with hb_sk_* and X-Participant-Ref.
// Browser (hb_pk_* + End-User JWT)
const cfg = await habifyPublic.chat.getRealtimeConfig();
await habifyPublic.chat.sendMessage(conversationId, { body: "Xin chào, tôi cần hỗ trợ!" });
const inbox = await habifyPublic.notification.getMyInbox({ status: "unread" });7. BYO One-Off Payment Webhook Relay (/api/webhooks/payment-byo)
Every POST /v1/payment/payments or /v1/payment/subscriptions call through the Unified Gateway automatically routes upstream callbacks to /api/webhooks/payment-byo/{project}. Habify Base verifies the upstream payment signature and relays the event to your project's webhook_url signed with your HABIFY_WEBHOOK_SECRET.