Skip to content

Build your own chat client

The User Portal uses no private back door. Every screen in it calls a public route on the Core Proxy (:8100), with the end user’s own session token. Anything that can hold a token and read Server-Sent Events can do the same: a branded web chat, an internal Slack-style tool, a mobile app or a kiosk. Each call your client makes passes the same checks and leaves the same audit trail as a call from the stock portal: resource-group access, limits, guardrails, approvals, run ledger and evidence.

This section is the walkthrough. Every endpoint and field is listed in the Portal API reference and the LLM Proxy API reference.

Your chat client ──HTTPS──► Core Proxy :8100 ──► LLM providers
(browser / app) │ ──► MCP servers (tools)
│ ──► Qdrant (knowledge bases, injected server-side)
└─ PostgreSQL (shared with the Control Plane)

Your client talks to one base URL, the Core Proxy, through two route families:

Family Prefix What it is for
Portal API /v1/portal/* Sign-in and 2FA, profile, workspaces, catalogs (models, MCP servers, knowledge bases), notifications, the approvals inbox, run feedback, the AI-interaction notice
Proxy routes /v1/proxy/* The traffic itself: chat (/v1/proxy/llm/chat/completions, /v1/proxy/llm/responses), tool calls (/v1/proxy/mcp/{server_id}), images, audio, video, files, batch jobs

Two unauthenticated routes help before sign-in: GET /v1/public/tenants/{tenant_id}/theme (the tenant’s colours and logo, for the login screen) and GET /health.

Every call carries the same three things: the tenant, the end user’s portal JWT, and the workspace (resource group) the user is working in. The shipped portal sets them in one place (GatewayApiClient.request() in brutor-gateway-portal/src/lib/gatewayApiClient.ts). Copy that pattern:

Terminal window
export BRUTOR=http://localhost:8100
export TENANT=default
export JWT=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9... # from /v1/portal/auth/login
export GROUP=group-01M61N376V2RR6J2TV7Q7EVRET # the active workspace
curl -s "$BRUTOR/v1/portal/notifications/unread-count" \
-H "X-Tenant-ID: $TENANT" \
-H "Authorization: Bearer $JWT" \
-H "X-Gateway-Authorization: Bearer $JWT" \
-H "X-Resource-Group: $GROUP"

Response for the example call:

{"unread_count": 0}
Header Direction Example Purpose
X-Tenant-ID → default Tenant context. Send on every call, including login
Authorization → Bearer eyJ0eXAiOiJKV1Qi... Portal JWT. Portal routes copy it to X-Gateway-Authorization when that header is absent
X-Gateway-Authorization → Bearer eyJ0eXAiOiJKV1Qi... Portal JWT, read first by the proxy routes. The shipped portal sends both
X-Resource-Group → group-01M61N376V2RR6J2TV7Q7EVRET The workspace a proxy call is scoped to. Falls back to the user’s primary_group_id
X-Brutor-Run-Id → 01JZ8Q4W6V3G1R2T5Y7U9I0P1A Your id for one user turn, asserted on every call the turn makes. See Conversations
X-Brutor-Session-Id → chat-01JZ8Q2N4K The conversation the run belongs to (LLM routes)
X-Brutor-Conversation-Handle → 01JZ8Q2N4KX6M3B7C9D1E5F0GH Fresh ULID per conversation, ties turns to the sealed notice
X-Approval-Token → q3V9n0...Xw (86 characters) One-time retry of an approved tool call
x-brutor-run-id ← 06GSDAPWJY4T107B1PKHEY4HT1 The run the gateway derived for this turn. Use it for feedback
X-Brutor-AI-Generated ← true Label the answer as AI-generated
X-Usage-Warning ← Daily budget at 85%: $4.25 / $5.00 A budget or quota is close: warn the user before the hard 429
Retry-After ← 27 Seconds to wait after a 429
WWW-Authenticate ← Bearer realm="brutor", error="invalid_token" Sent with every 401

The full grammar of the X-Brutor-* request headers is in Agent headers.

Portal routes answer errors as a flat object:

{"error": "Invalid username or password"}

Proxy routes (chat, tools) use richer envelopes, described in LLM API error handling.

Status Where you see it What your UI should do
400 Validation, e.g. “Username already taken”, unknown filter value Show the message inline
401 Missing, expired or logged-out token (WWW-Authenticate: Bearer) Drop the token, return to login
403 Inactive account; not a member of the group; guardrail block on chat (error.code: "guardrail_blocked"); invalid approval token Explain; do not retry the same content
404 Not found, or not visible in the user’s groups Treat as absent
409 Approval already resolved; 2FA already enabled Refresh the item
410 Approval expired before it was decided Mark it expired
428 Interactive tool call held for approval Route into the approval flow
429 Login throttled, rate or usage limit; honour Retry-After Back off, show a limit notice
503 Database or evidence store unavailable Retry with backoff
5xx Gateway or upstream error Retry with backoff