API reference
REST endpoints on the same origin as the site. All requests and responses are JSON unless noted.
Base URL & proxying
https://kinetic-4g1.pages.dev/api/...
Cloudflare Pages Functions (/functions/_middleware.js)
proxy /api/* to the EC2 backend with the same origin — no
CORS configuration is needed for browser apps served alongside it.
Authentication methods
| Method | Credential | Used by |
|---|---|---|
| Admin session | Cookie: admin_token=… | Admin API (/api/admin/*) |
| Tenant session | Cookie: kinetic_tenant_session=… (set by POST /api/portal/login; HttpOnly, signed) | Portal, verticals, inbox, leads, BI, payments, members, approvals |
| Developer key | x-developer-api-key: <DEVELOPER_API_KEY> | Developer API (/api/developer/*) — CI/CD and programmatic access |
| Copilot key | Authorization: Bearer <COPILOT_API_KEYS> or x-copilot-key: … | Machine-facing Developer Copilot API (/api/copilot/*) |
| Webhook secret | x-telegram-bot-api-secret-token | Telegram webhook verification |
| WhatsApp verify token | ?hub.verify_token=… | WhatsApp webhook handshake |
Core endpoint groups
| Group | Prefix | Purpose |
|---|---|---|
| Health | /api/health | Liveness for load balancers and monitors (public). |
| Inbox | /api/inbox | Unified threaded inbox across CX/LG/BD; per-participant threads; replies. |
| Copilot | /api/portal/copilot | Agent-loop chat with tool use and progress streaming. |
| Leads | /api/leads | Lead discovery, scoring, pipeline stages, pause flags. |
| Verticals | /api/portal/verticals | Per-tenant vertical activation state. |
| BI | /api/bi, /api/portal/roi | Dashboards, ROI metrics, market briefs. |
| Payments | /api/payments | Wallet top-ups and callbacks (signature-verified). |
| Admin | /api/admin | Tenants, harnesses, incidents, activity, dashboard data. |
| Developer | /api/developer | Health checks, cost intelligence, overview, infrastructure. |
| Developer Copilot | /api/copilot | Scoped read-only senses surface for the Developer Copilot; Alertmanager ingestion; gated self-heal. |
| Offline sync | /api/sync | Offline batch upload (/batch) and status (/status) for Business Centre Everywhere. |
Unified inbox (highlights)
GET /api/inbox/unified?vertical=cx|lg|bd&channel=&status=all|needs_you|in_progress|resolved
GET /api/inbox/unified/:vertical/:id/messages
POST /api/inbox/unified/:vertical/:id/reply { "message": "..." }
# Legacy per-participant endpoints remain available:
GET /api/inbox
GET /api/inbox/:participantId/messages
POST /api/inbox/:participantId/reply { "message": "...", "channel": "whatsapp" }
The unified reply endpoint routes automatically: a CX reply goes out on
the customer's channel; an LG reply uses the lead's active WhatsApp; a BD
reply uses the partner's WhatsApp. A thread without a sendable channel
returns 400 with an explanatory error — the API never fakes a
send.
Copilot message
POST /api/portal/copilot/message
{ "message": "Find plumbers in Lusaka", "sessionId": null } // sessionId: null starts a new session
B2C commerce endpoints (tenant-scoped)
| Group | Prefix | Purpose |
|---|---|---|
| Catalog | /api/catalog | Products and categories shown to customers in chat; WhatsApp-formatted catalog view. |
| Ecommerce | /api/ecommerce | Store connections, two-way product sync, sync log, platform webhooks. |
| Marketing | /api/marketing | Draft marketing campaigns and social content (approval-first). |
| Supply chain | /api/supply-chain | Landed cost, exchange-rate checks, supplier/logistics discovery, supply-chain monitoring. |
| B2C compliance | /api/compliance/b2c | Import/export requirements and cross-border labour checks from jurisdiction config. |
Developer Copilot API (senses)
A machine-facing, scoped surface at /api/copilot for the
Developer Copilot. Every route requires the copilot key (see
authentication); if COPILOT_API_KEYS is unset the entire
surface is disabled and every request is rejected with 503.
GET /api/copilot/health-check # orchestrator + MCP + Redis pings with response times
GET /api/copilot/cost-intelligence # same logic as GET /api/developer/cost-intelligence
GET /api/copilot/infrastructure # container/service infrastructure view
GET /api/copilot/mesh-health # harness mesh health
GET /api/copilot/status # persisted copilot heartbeat document
POST /api/copilot/alerts # Alertmanager ingestion: {"alerts":[...]} or a single alert object
POST /api/copilot/remediate # gated self-heal scaffold (see below)
- Alerts: accepts either the Alertmanager envelope or a single alert object. Only alerts actually received are stored, each stamped with
receivedAt. An empty payload returns400. - Remediation: exactly one action is supported —
{"action":"restart-container","container":"<name>"}. It runs only whenCOPILOT_HEAL_ENABLED=true, only for containers on theCOPILOT_HEAL_ALLOWED_CONTAINERSallowlist, and always reports what it did afterwards.
Admin control plane APIs
The admin control plane exposes tenant lifecycle and platform health via
/api/admin (admin session cookie) and the developer-side
control-plane views under /api/developer (developer key):
tenant list and detail, incidents, activity, usage summaries, pricing,
and ingestion/profiling statistics.
Backup & restore
- Nightly encrypted backups run from
scripts/backup/nightly-backup.shinside the backup Compose stack (docker-compose.backup.yml). - Restore drills are scripted and repeatable:
scripts/backup/restore-drill.sh. Run them on a schedule — a backup you have never restored is a hypothesis. - Activation, scheduling, and capacity reporting live in
scripts/backup/; operational procedure is in docs/runbooks/disaster-recovery.md.
Units consumption
- AI-consuming endpoints deduct units from the calling tenant's wallet atomically per request.
- Consumption events are recorded with model, tokens, and cost for the tenant's usage views.
- A wallet at zero returns an explicit insufficient-units error; no partial work is billed.
- BYOK tenants draw against their own provider keys instead of platform units.
Error semantics
| Status | Meaning |
|---|---|
| 400 | Invalid input, or an operation that cannot be honestly performed (e.g. replying on a channel with no connection). |
| 401 | Missing/expired credentials. |
| 404 | Resource does not exist in this tenant's scope. |
| 503 | A required dependency (DB, harness) is starting or unavailable. |