BFF Proxy Routes

Every browser request goes through one of these routes. Most are a 4-line delegation to proxyGet / proxyPost / proxyPut / proxyPatch / proxyDelete / proxySse from src/lib/api/proxy.ts. No business logic lives here — the proxy exists only to keep credentials off the browser and collapse two upstreams to one origin (see ARCHITECTURE.md).

Exception: the two manifest routes below use proxyGetVerified, not proxyGet. They forward the upstream body unchanged but run it through the aitp SDK server-side first, attaching the result as a sibling _verification key ({checked, ok, code} / {checked: false, reason}) — never re-serializing the upstream bytes, so the response the browser sees is byte-identical to what was verified. Both (well-known/aitp-manifest, registry/agents/[aid]/manifest) verify with verifyManifestJson. This is the one case in this table with real logic in the proxy layer: rendering a CP-signed artifact as trusted without checking it is exactly the defect plans/cp-signed-artifact-verification.md exists to fix. See ARCHITECTURE.md.

This table is the console's routing contract: console route → upstream path. The meaning of each upstream endpoint is owned by its service — follow the links to the playground and CP API docs for request/response semantics.

Status codes and bodies pass through unchanged. On connection failure the proxy synthesizes a 502 (Upstream unreachable) and on timeout a 504 (Upstream timeout), both with shape { error, target, upstream_status }. target is the upstream path and query only (e.g. /api/health): the upstream origin never reaches the browser. Raw error detail and the full upstream URL are logged server-side, never sent to the browser.

Playground (PLAYGROUND_URL, default http://localhost:8000)

MethodConsole routeUpstreamAccess
GET/api/playground/health/healthzpublic
GET/api/playground/capabilities/capabilitiespublic
GET/api/playground/agents/agentspublic
GET/api/playground/metrics/metricsadmin
GET/api/playground/packs/packspublic
GET/api/playground/scenarios/scenariospublic
GET/api/playground/scenarios/[...ref]/scenarios/<pack>/<scenario>@<version>public
GET/api/playground/scenario-templates?ref=…/scenarios/<pack>/<scenario>@<version>/templatespublic
GET/api/playground/runs/runspublic
POST/api/playground/runs/runs (accepts template, variant, fault_injection)public (launch)
GET/api/playground/runs/[id]/runs/:idpublic
GET/api/playground/runs/[id]/status/runs/:id/statuspublic
POST/api/playground/runs/[id]/cancel/runs/:id/canceladmin
GET/api/playground/runs/[id]/narrate/runs/:id/narratepublic
GET/api/playground/runs/[id]/cp-audit/runs/:id/cp-auditpublic
GET/api/playground/runs/[id]/cp-sessions/runs/:id/cp-sessionspublic
GET/api/playground/runs/[id]/deliveries/runs/:id/cp-deliveriespublic
SSE/api/playground/runs/[id]/events/runs/:id/eventspublic (stream)
GET, POST/api/playground/hosted-agents/hosted-agentsGET public · POST admin
GET, DELETE/api/playground/hosted-agents/[id]/hosted-agents/:idGET public · DELETE admin
POST/api/playground/hosted-agents/[id]/invoke/hosted-agents/:id/invokeadmin
POST/api/playground/hosted-agents/[id]/resolve-and-handshake/hosted-agents/:id/resolve-and-handshakeadmin

Why scenario-templates is a query-param route, not a child of /scenarios/[...ref]: Next.js does not allow child segments under a catch-all route. The console keeps a flat /api/playground/scenario-templates?ref=<pack>/<scenario>@<version> route and forwards it to the nested upstream /templates path.

Control Plane (CP_URL, default http://localhost:4000)

MethodConsole routeUpstreamAccess
GET/api/cp/health/api/healthpublic
GET/api/cp/readyz/api/readyzpublic
GET/api/cp/dashboard/api/dashboard/overviewpublic
GET/api/cp/dashboard/agents/api/dashboard/agentspublic
GET/api/cp/registry/agents/api/registry/agentspublic
POST/api/cp/registry/enroll/api/registry/enrolladmin
GET/api/cp/registry/agents/[aid]/api/registry/agents/:aidpublic
DELETE/api/cp/registry/agents/[aid]/api/registry/agents/:aidadmin
GET/api/cp/registry/agents/[aid]/manifest/api/registry/agents/:aid/manifest (verifying — see note above)public
SSE/api/cp/events/stream/api/events/stream (cap-aware)public (stream)
GET/api/cp/events/history/api/events/historypublic
GET/api/cp/sessions/api/sessionspublic
GET/api/cp/sessions/[sessionId]/api/sessions/:sessionIdpublic
GET/api/cp/sessions/[sessionId]/replay/api/sessions/:sessionId/replaypublic
GET/api/cp/sessions/[sessionId]/export/api/sessions/:sessionId/exportpublic
GET/api/cp/audit/api/audit (admin-action log; the Audit screen uses events/history above)admin
GET/api/cp/metrics/api/metricsadmin
GET/api/cp/tcts/api/tctspublic
GET/api/cp/delegations/api/delegationspublic
POST/api/cp/revocation/entries/api/revocation/entries (POST-only; the body carries iss)admin
GET/api/cp/revocation/issuers/api/revocation/issuers (issuers that have entries, with counts)public
GET/api/cp/revocations/api/revocations?iss=<aid> (one issuer's entries, unsigned)admin
GET, POST/api/cp/trust-anchors/api/trust-anchorsGET public · POST admin
GET, PATCH, DELETE/api/cp/trust-anchors/[id]/api/trust-anchors/:idGET public · PATCH, DELETE admin
GET, POST, DELETE/api/cp/pinned-keys/api/pinned-keys (DELETE takes ?namespace=&aid=)GET public · POST, DELETE admin
GET, POST/api/cp/webhooks/api/webhooksadmin
PUT, DELETE/api/cp/webhooks/[id]/api/webhooks/:idadmin
GET, POST/api/cp/webhooks/[id]/circuit-breaker/api/webhooks/:id/circuit-breakeradmin
POST/api/cp/webhooks/[id]/circuit-breaker/reset/api/webhooks/:id/circuit-breaker/resetadmin
GET/api/cp/well-known/aitp-manifest/.well-known/aitp-manifest (verifying — see note above)public

Adding a new proxy

  1. Create the file under src/app/api/<service>/<path>/route.ts.
  2. Pick the right helper:
    import { NextRequest } from 'next/server';
    import { proxyGet } from '@/lib/api/proxy';
    
    export const runtime = 'nodejs';
    export const dynamic = 'force-dynamic';
    
    export async function GET(req: NextRequest) {
      return proxyGet('cp', '/api/your/path', req);
    }
  3. For routes with path params, await params (Next 16 passes it as a Promise) and encodeURIComponent user-controlled segments.
  4. For SSE, use proxySse and make sure the upstream sets Content-Type: text/event-stream. The proxy auto-rewrites Cache-Control and X-Accel-Buffering. 4a. If the route serves a CP-signed artifact, use proxyGetVerified instead of proxyGet, passing a verify(bodyText) => Verdict function. Never verify in the browser — write the verify function in a small dedicated module the route imports (see src/lib/api/verify-manifest.ts), not inline in the route, so unit tests under jsdom (which cannot load a native addon) never transitively import it.
  5. Add a row to this table.
  6. Add a hit to src/test/proxies.integration.test.ts (live services) and a mock-upstream case to src/test/bff-routes.integration.test.ts (runs in CI) so the contract is exercised end-to-end.

The full "add a route end-to-end" recipe (proxy → types → hook → component → page → tests) lives in the repo's contributor docs: internal_docs/DEVELOPMENT.md (not published here).

Auth

The route handlers build every upstream request's headers from scratch; nothing the browser sends (Authorization, x-api-key, Cookie, X-AITP-Client-IP) is forwarded. The keys never reach the browser — they live only in the route-handler process.

UpstreamCredentialWhen
Playgroundx-api-key: <PLAYGROUND_API_KEY>every call, when set
Control plane, keyless routes (/api/health, /api/readyz, the manifest)nonealways
Control plane, read routes (registry, sessions, events, trust, revocation issuers, …)Authorization: Bearer <CP_READ_API_KEY>when set; otherwise CP_API_KEY
Control plane, admin routes (audit, webhooks, metrics, every write)Authorization: Bearer <CP_API_KEY>always

Which class a route is in comes from the allowlist in src/lib/server/allowlist.ts; a path not in it is treated as admin.

Access column. With AITP_CONSOLE_PUBLIC_MODE off (the default), every route needs an operator session, whatever the column says. With it on, public routes also serve anonymous visitors, charged against the per-IP limits (read; launch adds the 5-per-10-minutes run budget; stream takes one of 4 concurrent stream slots per IP); admin routes still need an operator session (anonymous → 403 CONSOLE_OPERATOR_SESSION_REQUIRED). See ARCHITECTURE.md § Access model.

Read-key fallback. With public mode on, an operator's read routes use CP_API_KEY directly, so operators never share the read key's budget with visitors. With it off, for an operator, a read route falls back to CP_API_KEY, retrying once, when CP_READ_API_KEY is unset, when the CP answers 401, or when it answers 403 with {"code":"READ_ONLY_KEY"}. Each fallback reason logs one console.warn line at most every 10 minutes. Any other 403 is relayed unchanged. An anonymous caller (only possible with AITP_CONSOLE_PUBLIC_MODE=on) never gets the admin key: an unset or rejected read key answers 503 cp_read_key_unavailable.

Client IP. Every upstream call carries X-AITP-Client-IP when the console knows the caller's IP (on Vercel, from x-real-ip; elsewhere, from the header named by CONSOLE_CLIENT_IP_HEADER). When it doesn't, the header is omitted rather than guessed.

Error metadata. A non-2xx upstream response is relayed with its status, body, Content-Type and Retry-After, including on the SSE routes, so a playground 429 reaches the browser intact.

Leave both blank for local development; both services accept unauthenticated requests when their own API_KEYS are unset.

SSE behaviour

proxySse streams the upstream Response.body straight back to the browser with three header overrides:

  • Content-Type: text/event-stream
  • Cache-Control: no-cache, no-transform
  • X-Accel-Buffering: no (disables nginx response buffering if a proxy ever fronts the console)

There is no per-frame parsing in the proxy — frames are forwarded as opaque bytes. Browser-side parsing happens in useSse.

CP SSE capacity handling

The control plane caps live SSE listeners and returns 503 when at capacity. The client useSse hook takes an optional capacityProbePath — when supplied it issues a quick GET to that path before opening the EventSource. A 503 surfaces as a distinct at-capacity state so the UI can display a "control plane at capacity" banner rather than the generic "reconnecting" state, with a longer backoff. The CP-side cap and its 503 behaviour are documented in the CP operations docs.

Enrollment-token flow

POST /api/cp/registry/enroll takes a signed AITP manifest envelope and returns a short-lived, single-use bearer token. The console surfaces this in Registry → New enrollment with an expiry countdown and a reveal/copy control — see FEATURES.md. The token's lifetime, JTI single-use semantics, and redemption against POST /api/registry/agents are the control plane's; see the CP API.