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.
Architecture
Section titled “Architecture” 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.
The base client
Section titled “The base client”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:
export BRUTOR=http://localhost:8100export TENANT=defaultexport JWT=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9... # from /v1/portal/auth/loginexport 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"import requests
BASE = "http://localhost:8100"TENANT = "default"
class BrutorPortal: def __init__(self): self.jwt: str | None = None self.group: str | None = None self.http = requests.Session()
def headers(self) -> dict: h = {"X-Tenant-ID": TENANT, "Accept": "application/json"} if self.jwt: h["Authorization"] = f"Bearer {self.jwt}" h["X-Gateway-Authorization"] = f"Bearer {self.jwt}" if self.group: h["X-Resource-Group"] = self.group return h
def call(self, method: str, path: str, **kw): r = self.http.request(method, BASE + path, headers=self.headers(), timeout=30, **kw) if r.status_code == 401: self.jwt = None # session expired or logged out: back to the login screen r.raise_for_status() return r.json() if "json" in r.headers.get("content-type", "") else r.text
portal = BrutorPortal()const BASE = "http://localhost:8100";const TENANT = "default";
export const session = { jwt: null, group: null };
export function headers(extra = {}) { const h = { "X-Tenant-ID": TENANT, Accept: "application/json", ...extra }; if (session.jwt) { h.Authorization = `Bearer ${session.jwt}`; h["X-Gateway-Authorization"] = `Bearer ${session.jwt}`; } if (session.group) h["X-Resource-Group"] = session.group; return h;}
export async function api(path, { method = "GET", body } = {}) { const res = await fetch(BASE + path, { method, headers: headers(body ? { "Content-Type": "application/json" } : {}), body: body ? JSON.stringify(body) : undefined, }); if (res.status === 401) session.jwt = null; // back to the login screen if (!res.ok) throw Object.assign(new Error(`HTTP ${res.status}`), { res }); return res.headers.get("content-type")?.includes("json") ? res.json() : res.text();}Response for the example call:
{"unread_count": 0}What the walkthrough covers
Section titled “What the walkthrough covers”Headers cheat sheet
Section titled “Headers cheat sheet”| 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.
Error handling
Section titled “Error handling”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 |
Related
Section titled “Related”- Portal API reference: every portal endpoint and field
- LLM API: the chat surface in depth
- Approvals: configuring which tools need a human
- Resource groups: what a workspace grants
- Transparency: the AI-interaction notice

