Skip to content

Customer portal

Last updated: 2026-11-26T23:07:44-03:00 (UTC-3)

The customer portal is for an operator that sells AI usage to its own customers. The operator registers customer organizations, their customer teams and members under one of its gateway teams, gives them budgets, and its backend calls the gateway with one of that team’s keys plus headers that name the customer. The gateway charges the organization, the customer team and the member in the same quota reservation as every other budget, refuses a request that would pass any of their hard ceilings before the provider is called, raises a customer_budget_crossed alert and reports usage per customer. Flag: customer_portal (default false).

Customers are not console users, gateway teams or end users: they never sign in, own no keys and get no access to anything. They are financial subjects that the operator’s backend names on each request.

features:
budget_limits: true # required (a restart flag)
durable_usage: true # required by budget_limits
usage_analytics: true # required
customer_portal: true
customer_portal_credentials: true # optional: scoped backend credentials
customer_self_service: true # optional: read-only customer view links
customer_budget_windows: true # optional: several budgets per level (a day and a month)
customer_portal:
trusted_keys:
- key_id: backend-prod # a YAML or managed key ID
require_identity: true # optional; default false
require_override_approval: false # optional; see override approval requests
override_request_ttl_hours: 168 # optional
auto_register_members: false # optional; see auto-registration
view_token_max_minutes: 1440 # optional; see the self-service view
auto_register_organizations: false # optional; see auto-registration
max_auto_organizations: 100 # optional; per operator team
auto_organization_profile: # required with auto_register_organizations
id: default
budget_usd: "5" # each member's ceiling
budget_period: month
organization_budget_usd: "200" # the organization's own ceiling
organization_budget_period: month

The flag is an operator control, changes at runtime and applies on the next request. It needs PostgreSQL for both the store and the quota ledger: migration 160 creates the customer tables and adds the captured customer to usage events and durable receipts. Without PostgreSQL an inference request that would resolve a customer answers 503 customer_unavailable and the API answers 503.

Customer traffic is budgeted traffic: every request that names a customer reserves USD, so its model needs an approved quota rate (budgets and TPM), exactly as for a team budget. A request without one is refused with 422 quota_profile_unsupported.

Only a trusted key may name a customer, and only a customer of the key’s own team. A key is trusted when it is listed in customer_portal.trusted_keys (read-only in the console) or when an administrator trusts it through the API or the console. The team is always the key’s own: it is never taken from the request or from the administrator’s input, and a stored trust entry never moves to another team.

Field Default Meaning
customer_portal.trusted_keys[] none Up to 256 entries, unique key_id.
customer_portal.trusted_keys[].key_id required A YAML or managed key ID, 1-128 characters.
customer_portal.trusted_keys[].require_identity false Refuse that key’s inference requests that name no customer organization (422 customer_identity_required).

Revoking trust takes effect on the next request: a request of that key that names a customer is refused. Trust is checked live in PostgreSQL on every request when the key is not trusted in the YAML.

Header Required Meaning
X-Gateway-Customer-Org yes, to name a customer The organization ID.
X-Gateway-Customer-Team no A customer team of that organization.
X-Gateway-Customer-Member no A member of that organization. A member registered in a customer team charges that team too; a different team header is refused.
Terminal window
curl https://gateway.example/v1/chat/completions \
-H "Authorization: Bearer $BACKEND_KEY" \
-H "X-Gateway-Customer-Org: acme-co" \
-H "X-Gateway-Customer-Member: [email protected]" \
-H "Content-Type: application/json" \
-d '{"model":"fast-chat","messages":[{"role":"user","content":"hi"}],"max_completion_tokens":256}'

The headers are resolved once per request, after authentication and before the durable receipt, the quota reservation or any provider call. Every refusal below happens before the provider is called:

Answer When
422 customer_portal_disabled A customer header is present while the flag is off. The headers are never silently ignored.
403 customer_identity_not_trusted The key is not trusted to assert customer identity.
422 customer_identity_required The key requires identity and the request names no organization.
422 customer_org_required A team or member header without an organization header.
422 customer_unknown The organization, team or member is not registered under the key’s team (also when it is deleted while the request is admitted).
422 customer_team_mismatch The team header differs from the member’s registered team.
403 customer_disabled A named level is disabled.
429 quota_exceeded A hard ceiling would be passed. X-Gateway-Quota-Policy is customer:org, customer:team or customer:member, and X-Gateway-Quota-Dimension is the period of the window that ran out. A level with several budget windows names the window in the policy too: customer:member:day, customer:org:month.
422 customer_budget_windows_disabled A named level holds several budget windows and customer_budget_windows is off. The stored windows are never reduced to one.

Chat and the other inference routes, native Messages and Gemini, passthrough, video and each Realtime response are resolved. A call the gateway makes while serving a client request of the same team (a moderation guardrail) inherits that request’s customer, and the embeddings of a vector store upload or search carry the client’s customer headers, so they are resolved and charged like the client’s own request. An auto-routing helper (the embedding or classifier call that picks the target) runs after the customer is checked but is not charged to it.

Batches. POST /v1/batches from a trusted key may carry the customer headers, resolved exactly like a client request’s: every line is charged to that customer and recorded with it (the batch stores customer_org, customer_team, customer_member). Each line is admitted on its own, so a line is refused (and reported in the error file) when the customer’s ceiling is reached, when the customer is deleted or disabled, or when the key loses its trust while the batch runs. A key with require_identity must name a customer to create a batch (422 customer_identity_required).

Evaluations. POST /api/v1/admin/evals/runs takes an optional customer ({"org": "acme-co", "member": "alice"}; team optional): the run’s model calls and its evaluators’ judge calls are charged to that registered, enabled customer of the dataset’s team, reserved and settled on the same ledger; a call that would pass a ceiling is refused (a refused judge call is not retried, and the item keeps no score). Because customer traffic is budgeted, the run’s model calls are sent with max_completion_tokens: 4096. The session needs customers:manage for that team (403 team_forbidden); an unknown customer is 422 customer_unknown.

Every record is keyed by IDs the operator chooses: 1-64 characters of A-Z a-z 0-9 . _ @ : -, starting with a letter or digit, so an email or a UUID fits. They live under the operator’s gateway team, so two teams may use the same customer IDs without sharing anything.

Kind Fields
Organization name, budget, profile_id (the default profile of its new members), limits, disabled
Customer team name, budget, profile_id (the default profile of its new members, before the organization’s), limits, disabled
Member name, customer_team, profile_id, budget, limits, override, disabled
Budget profile name, budget (required), limits

Limits are the token ceilings and per-model allowances of a level.

The budget fields are shared:

Field Default Bounds and meaning
budget_usd none Positive decimal string, up to six decimal places, up to 1,000,000. Omitted: no ceiling, but spend is still counted, so a budget set later starts from the real spend.
budget_period month day or month (UTC); week, quarter and year need calendar_budget_periods; lifetime needs lifetime_budget_limits.
soft_budget false true alerts without refusing.
alert_thresholds [80, 100] Up to five unique percentages 1-100; [] disables alerts.
budgets[] none Up to four budget windows with distinct periods; see several budget windows. More than one needs customer_budget_windows.
budgets[].budget_usd required As budget_usd.
budgets[].budget_period month As budget_period, unique within the level.

A member’s ceiling is, in order: an unexpired override, its own budget, then its profile. A new member that names neither a profile nor a budget gets its customer team’s default profile, else its organization’s, once, at creation. A member follows its profile live: raising the profile raises every member that uses it. Up to 10,000 teams, members and profiles fit in one organization.

An override replaces a member’s ceiling (higher or lower) until expires_at, at most 366 days ahead. On a member with several budget windows it replaces the window its budget_period names, or the first (shortest) window when it names none; the other windows stay enforced. An override (or an override request) that names a period none of the member’s windows has is refused with 422 invalid_customer; when the window is removed afterwards, the override changes nothing. On a member without a budget the override is its one hard ceiling, counted in the period it names (default: the member’s budget_period). Each reservation decides it after locking its counters, by the database clock, and the captured ceiling is the one its settlement and alerts use. An override never resets spend: when it expires, the member’s own or profile ceiling applies to what was already spent in the window.

A level may hold up to four budgets with distinct periods, for example 1 USD a day and 5 USD a month, so that a customer neither spends its month in one day nor passes its month. Flag: customer_budget_windows (default false, an operator control that needs customer_portal and applies on the next request).

Terminal window
curl -X PUT "$API/organizations/acme/acme-co/members/[email protected]" -d '{
"budgets": [
{"budget_usd": "1", "budget_period": "day"},
{"budget_usd": "5", "budget_period": "month"}
]}' ...
  • All together. Every window is reserved in the same transaction as the level’s other budgets: the request fits all of them or none, concurrent requests on any number of replicas never pass any of them, and settlement moves all of them by the same measured amount.
  • The refusal names the window. 429 quota_exceeded carries X-Gateway-Quota-Policy: customer:member:day (the level and the period) and X-Gateway-Quota-Dimension: day, and Retry-After is when that window resets. A level with one window keeps the policy ID customer:member. Budget alerts are deduplicated by policy ID, so a level that goes from one window to several (or back) may alert once more for a threshold it already crossed in the current window.
  • One budget is one window. budget_usd with budget_period is the same as a budgets list of one entry, with or without the flag, and existing records and clients are unchanged. A record is returned with both: budgets lists its windows, shortest period first, and budget_usd and budget_period are the first one.
  • Writing. Send one spelling: budgets, or budget_usd with budget_period. A client that reads a record and writes it back sends both, so the gateway settles them:
    • several budgets entries are the whole list, and a budget_usd beside them must be the shortest window’s, exactly as a read returns it;
    • one budgets entry beside the same budget_usd and budget_period is one window;
    • one budgets entry beside a different budget_usd: the side that still equals the stored record is what the client read, and the other side is the change. So changing budget_usd of a record with one budget works as it always did, and so does reducing several windows to one by sending the one entry;
    • anything else (two budgets that are both new, also on a create, or a budget_usd that disagrees with several entries) is refused with 422 invalid_customer: a ceiling is never dropped by guessing.
  • Profiles. A profile’s windows apply to every member that follows it, live.
  • Soft budgets and alerts. soft_budget and alert_thresholds belong to the level and apply to each of its windows: each window alerts on its own thresholds, and the customer_budget_crossed event names the window in budget_period.
  • Status. effective.windows[] lists every effective window with its budget_usd, budget_period, committed_usd, window_start and source (override, own or profile).
Answer When
422 feature_disabled A write with more than one window while customer_budget_windows is off, or with a period whose flag is off.
422 invalid_customer More than four windows, two windows of one period, an amount that is not a positive decimal, or a budget_usd and budgets that name different budgets (see Writing).
422 customer_budget_windows_disabled A request that names a level with several stored windows while the flag is off. Turn the flag on again, or give those levels one budget, before turning it off.

Every write needs customers:manage for the record’s operator team and is audited (customer.<kind>.put, .delete, customer.member.override, customer.trusted_key.put); a cookie session also sends its CSRF token from the same origin. Reads need customers:read. See who manages customers for which sessions hold them. A create omits version and is refused with 409 customer_exists when the record exists; a replace sends the current version and is refused with 409 version_conflict when it changed.

Terminal window
API=https://gateway.example/api/v1/admin/customer-portal
# Organization with a monthly 100 USD ceiling and a default member profile.
curl -X PUT "$API/organizations/acme/acme-co/profiles/starter" -d '{"budget_usd":"5","budget_period":"month"}' ...
curl -X PUT "$API/organizations/acme/acme-co" -d '{"name":"Acme","budget_usd":"100","profile_id":"starter"}' ...
# Customer team and member (the member gets the starter profile).
curl -X PUT "$API/organizations/acme/acme-co/teams/eng" -d '{"name":"Engineering"}' ...
curl -X PUT "$API/organizations/acme/acme-co/members/[email protected]" -d '{"customer_team":"eng"}' ...
# Temporary override for one week, at the member's version.
curl -X PUT "$API/organizations/acme/acme-co/members/[email protected]/override" \
-d '{"version":1,"budget_usd":"20","expires_at":"2026-11-22T00:00:00Z","reason":"launch week"}' ...
# Trust a managed key; its team is the key's.
curl -X PUT "$API/trusted-keys/key_backend" -d '{"require_identity":true}' ...
Route Purpose
GET /customer-portal Trusted keys (YAML and stored), header names, default thresholds, periods
PUT, DELETE /customer-portal/trusted-keys/{key_id} Trust or revoke a key
GET /customer-portal/organizations?team= Organizations with their effective ceiling and committed spend
GET, PUT, DELETE /customer-portal/organizations/{team}/{org} One organization; delete removes its teams, members and profiles. The read takes member_q, member_sort and member_order (search and sort)
PUT, DELETE /customer-portal/organizations/{team}/{org}/{teams|members|profiles}/{id} Customer teams, members and profiles
PUT, DELETE /customer-portal/organizations/{team}/{org}/members/{id}/override Set or clear an override
GET, POST /customer-portal/credentials, POST /customer-portal/credentials/{id}/revoke Backend credentials (people only)
GET /customer-portal/override-requests, POST .../organizations/{team}/{org}/members/{id}/override-requests List and file override requests
POST /customer-portal/override-requests/{id}/approve, .../deny Decide a request (people only, never the requester)
GET /customer-portal/usage?team=&org=&from=&to=&by=&format= Usage per customer and date range
GET /customer-portal/organizations/{team}/{org}/export, POST /customer-portal/organizations/{team}/import Export and import an organization
POST /customer-portal/organizations/{team}/{org}/view-tokens, POST /customer-portal/view-tokens/{team}/{id}/revoke Mint and revoke a self-service view link

A customer team with members, or a profile that a member, team or the organization still names, cannot be deleted (409 customer_in_use). Deleting a record keeps its counters and its usage events; deleting a member or an organization also deletes its view links and override requests.

GET /customer-portal/organizations/{team}/{org}/export returns one organization as a portable customer-portal/v1 document: the organization, its profiles, customer teams and members with their budgets, limits and allowances, without versions, timestamps, spend or overrides. POST /customer-portal/organizations/{team}/import?mode=merge|create writes such a document into that operator team (the document’s own team is ignored), so an export of one team or gateway imports into another unchanged.

Terminal window
curl "$API/organizations/acme/acme-co/export" ... > acme-co.json
curl -X POST "$API/organizations/acme-staging/import?mode=create" --data-binary @acme-co.json ...
# {"team":"acme-staging","org":"acme-co","mode":"create","created":42,"replaced":0}
Field Default Meaning
mode merge merge creates missing records and replaces existing ones at their current version; create refuses the import (409 customer_exists) when any record exists.

A level’s budget windows travel in budgets, so an export of an organization with several windows imports with all of them. The import is one transaction, written in order (organization, profiles, customer teams, members) and validated as a whole first: any invalid record, missing reference, period, limit or number of budget windows whose flag is off, or more than 10,000 records refuses it and writes nothing. The body is at most 8 MiB. Overrides are never imported: they follow their own approval flow. Import needs customers:manage for the team (a team administrator only into its own teams), export customers:read; an import is audited as customer.import.<mode> with its record count.

Both kinds are off by default, apply only to requests of a trusted key and only inside that key’s own team.

With customer_portal.auto_register_members: true (default false), a trusted key’s request that names an unknown member of a registered, enabled organization registers that member before it is admitted: in the named customer team when the request names one, with the default profile of that customer team, else of the organization. Without a default profile, or with a disabled organization or team, the member stays unknown (422 customer_unknown). Concurrent first requests of one member register it once; each registration is audited as customer.member.auto_register by system:customer-auto-register, and counts toward the organization’s 10,000 records.

With customer_portal.auto_register_organizations: true (default false), a trusted key’s request that names an unknown organization registers that organization before it is admitted, with a default member profile, so an operator whose backend already knows its tenants does not have to register each one first. The organization is always created in the key’s own team; only a trusted key can do it, and a request from any other key is refused as before.

Field Default Bounds and meaning
customer_portal.auto_register_organizations false Register an unknown organization named by a trusted key.
customer_portal.max_auto_organizations 100 1-10000. The most auto-registered organizations one operator team may hold. Organizations registered through the API, the console or an import do not count.
customer_portal.auto_organization_profile.id default The ID of the default member profile created in each such organization (a customer ID).
customer_portal.auto_organization_profile.budget_usd required The profile’s ceiling: a positive decimal, up to six places. There is no default, because a ceiling is your decision; the gateway refuses to start with auto-registration on and no amount.
customer_portal.auto_organization_profile.budget_period month As budget_period; calendar and lifetime periods need their flags.
customer_portal.auto_organization_profile.organization_budget_usd required The organization’s own hard ceiling, over all of its members together: a positive decimal, up to six places. Required whether or not members auto-register: the gateway refuses to start, and refuses a configuration change, with auto-registration on and no organization ceiling, so a request never creates an organization that can spend without limit.
customer_portal.auto_organization_profile.organization_budget_period month As budget_period.

The settings are read at startup, like the rest of customer_portal. What a registration does:

  1. The organization is registered with organization_budget_usd as its own hard ceiling and marked auto_registered: true.
  2. The default profile is created in it and set as the organization’s default profile, so its new members get that ceiling. Change the organization’s budget or the profile through the API or the console afterwards.
  3. The registration is audited as customer.org.auto_register by system:customer-auto-register.

A request registers an organization only when it would then be admitted: it names no customer team (a new organization has none), and it names a member only when auto_register_members is on too (the member is then registered with the default profile in the same request). Otherwise the answer is 422 customer_unknown and nothing is registered. Past max_auto_organizations the organization stays unknown (422 customer_unknown, logged as customer_auto_register_capped): raise the cap, or delete organizations you no longer serve. A registration that could not be written (storage trouble, or a timeout behind many first requests of one team) also answers 422 customer_unknown and is logged as customer_auto_register_failed; the next request tries again. Concurrent first requests of one organization register it once, and the cap holds under any load.

A member is erased through the end-user deletion API, by naming customer_org and customer_member instead of end_user (needs end_user_deletion and customer_portal; a live global administrator with retention:manage, refused while a legal hold is active):

Terminal window
curl -X POST https://gateway.example/api/v1/admin/end-user-deletions \
-d '{"team":"acme","customer_org":"acme-co","customer_member":"[email protected]","dry_run":true}' ...
curl -X POST https://gateway.example/api/v1/admin/end-user-deletions \
-d '{"team":"acme","customer_org":"acme-co","customer_member":"[email protected]","confirm":true}' ...

The request deletes the member record, its override requests and its view links at once and removes the member from batches and evaluation runs that name it, so no new request can charge it, and creates a durable job (subject customer_member) that the end-user deletion worker runs exactly like an end-user job: usage events and finalized receipts keep their tokens, costs and fingerprints with customer_member cleared (the organization and customer team stay); captured content, evaluation captures and annotations and client addresses of those requests are deleted; the member is redacted ("erased") from the details of customer alert events. Budget counters, reservations and budget alerts keyed by the member are financial evidence and stay until their windows age out; the dry run reports them. Jobs never return the member ID. With auto-registration on, a later request that names the member registers it again: stop sending it first.

Anyone who manages a team’s customers (a global administrator, a team administrator of the team, a managing backend credential) may request a member override instead of setting it. A person other than the requester (and, for a request filed with a backend credential, other than the person who issued that credential) who administers the team (a global administrator or another team administrator of the team) approves or denies it; a backend credential never decides. Approval writes the override on the member at its current version in the same transaction, so the decision and the ceiling never diverge.

Field Default Meaning
customer_portal.require_override_approval false true: team administrators and backend credentials cannot set or clear an override directly (403 approval_required); global administrators keep the direct write.
customer_portal.override_request_ttl_hours 168 1-8784. How long a pending request may be decided, captured when it is filed; after that it is expired.
Terminal window
# The backend (or a team administrator) files the request.
curl -X POST "$API/organizations/acme/acme-co/members/[email protected]/override-requests" \
-H "Authorization: Bearer $CUSTOMER_CREDENTIAL" \
-d '{"budget_usd":"20","expires_at":"2026-11-30T00:00:00Z","reason":"launch week"}'
# {"id":"cor_5b1e...","state":"pending","requested_by":"cpc_3f9a...","decide_by":"2026-11-23T...",...}
# Another administrator of the team decides.
curl -X POST "$API/override-requests/cor_5b1e.../approve" -d '{"note":"approved for the launch"}' ...
curl -X POST "$API/override-requests/cor_5b1e.../deny" -d '{"note":"not this month"}' ...
Answer When
409 request_pending The member already has a pending request (one per member; up to 1,000 pending per team).
403 self_approval The requester tries to decide its own request.
403 team_forbidden The decider does not administer the request’s team.
409 request_closed The request was already decided, has lapsed (expired), or the requested override expiry has passed.

Filing, approving and denying are audited (customer.override_request.create, .approve, .deny, plus customer.member.override for the applied override) and write the alert events customer_override_requested and customer_override_decided: subscribe an alert channel to be notified. Their operational.detail carries team, org, member, request, budget_usd, expires_at, state, requested_by, decided_by (decisions) and request_id. GET /customer-portal/override-requests?team=&org=&state= lists the requests of the session’s teams, newest first.

Every level (organization, customer team, member, profile) may also carry:

Field Default Bounds and meaning
tpm 0 (none) Tokens per minute of the level, up to 10^12; needs tpm_limits.
tpd 0 (none) Tokens per UTC day of the level; needs tpd_limits and tpm_limits.
model_allowances[] none Up to 16 allowances, one per model alias.
model_allowances[].model required A configured model (not an alias_of name); requests for it under any of its client names count.
model_allowances[].budget_usd required Positive decimal, up to six places: a hard ceiling.
model_allowances[].budget_period month As budget_period; calendar and lifetime periods need their flags.
model_allowances[].fallback_model none A cheaper configured alias used when the allowance is exhausted.

A member without its own tpm/tpd, or without its own allowances, follows its profile’s, live. An organization or team allowance is shared by every member of that level; a member allowance is the member’s own. Token ceilings and allowances are part of the same quota reservation as the budgets: the request fits all of them or none, concurrent requests never pass them, and they settle with the measured amount. A write naming an alias that is not configured, or a limit whose flag is off, is refused with 422, so a stored limit is never silently unenforced.

Terminal window
curl -X PUT "$API/organizations/acme/acme-co/members/[email protected]" -d '{
"tpm": 20000,
"model_allowances": [
{"model": "smart-chat", "budget_usd": "10", "budget_period": "month", "fallback_model": "fast-chat"}
]}' ...

When an allowance is exhausted:

  • With fallback_model, a request of the chat pipeline (Chat Completions, and Messages or Responses requests translated through it to another provider’s protocol) is answered through the fallback alias once, in the client’s own dialect, with the same machinery as the semantic fallbacks: the destination is admitted like a client request of the same key (its allowed models, team policy, flags, rate limits and the same customer’s budgets and its own allowance), the client’s attribution headers are carried, and the answer carries X-Gateway-Fallback: allowance:<alias>. The answer is recorded under the request ID <id>.fallback, charged to the same organization, team and member; the relayed outer request names no customer, so customer usage counts it once. When the destination refuses before a provider answers (the key may not use it, its own allowance or budget is exhausted), the client gets the original 429 with X-Gateway-Fallback-Refused: allowance:<code>.
  • Without it, or on a native route (native Messages, Responses or GenerateContent to a provider of the same protocol, embeddings, media), which have no fallback machinery, the request is refused with 429 quota_exceeded and X-Gateway-Quota-Policy: customer:model:<org|team|member> before any provider call.

The fallback is one hop: the fallback alias’s own allowance or budget is checked, but an exhausted fallback never falls back again, so a chain or a loop of allowances can never multiply sends or hide where a request was answered; the client gets the original refusal instead. The allowance is counted in its own counter (customer_model), so changing it never resets the level’s budget, and raising it to what was already spent keeps it exhausted. Allowances raise no threshold alert; the level budgets do.

With customer_self_service (default false, an operator control that needs customer_portal), the operator’s backend mints a short-lived, read-only view link for one customer organization or one member and hands it to that customer. The link opens /customer-view, which shows only that scope: its ceiling and committed spend in the current window and its usage by UTC day over the last 30 days. It never shows the operator team, keys, other members or any record.

Terminal window
curl -X POST "$API/organizations/acme/acme-co/view-tokens" \
-H "Authorization: Bearer $CUSTOMER_CREDENTIAL" -d '{"member":"[email protected]","ttl_minutes":30}'
# {"view_token":{"id":"cvt_9c2d...","expires_at":"..."},"token":"gwcv_...","path":"/customer-view#token=gwcv_..."}
curl -X POST "$API/view-tokens/acme/cvt_9c2d.../revoke" ...
# The page reads the same data with the token:
curl https://gateway.example/v1/customer-view -H "Authorization: Bearer gwcv_..."
Field Default Meaning
member none Omitted: the whole organization’s view. Otherwise a registered member.
ttl_minutes 60 1 to customer_portal.view_token_max_minutes.
customer_portal.view_token_max_minutes 1440 1-10080 (YAML/API), the longest a link may live.

The token travels in the link’s fragment, so it is never sent to the server in a URL; the page removes it from the address bar and keeps it only in memory. Only its SHA-256 is stored; it expires by the database clock, can be revoked, and stops working when its organization or member is deleted. Minting needs customers:manage for the team (a managing backend credential, a team administrator or a global administrator); each mint and revocation is audited. Up to 1,000 live links per organization. Invalid links share the administrative Bearer failure limit.

Session Reads Writes
Global administrator every team every team: records, overrides, trusted keys, credentials
Viewer every team nothing
Team administrator (team_admin_console) the teams it administers records, overrides (or override requests), trusted keys of its own team’s keys, credentials, and decisions on other people’s override requests, all of those teams
Customer credential, access: read its own team nothing
Customer credential, access: manage its own team records, overrides (or override requests) of its own team; never decisions

A team administrator sees and changes only the customers of the teams it administers (with membership_roles, the memberships where it is an administrator). Another team’s organization, usage or credentials answer 403 team_forbidden, and the organization list is filtered before its page bound. Every write is checked again inside its database transaction against the live actor: a team administrator removed from the team, a disabled user or a revoked credential is refused on its next write even when the request was already admitted.

With customer_portal_credentials (default false, an operator control that needs customer_portal), a global administrator or a team administrator issues a customer credential for the operator’s backend. It is a server-side secret bound to one operator team and to customer management:

Field Default Meaning
team required The operator team; a team administrator only its own.
name required 1-120 characters, one line.
access manage read: the customer read routes of that team. manage: also its record, override and approval writes.
expires_at none Optional; in the future and at most 1095 days away.
Terminal window
API=https://gateway.example/api/v1/admin/customer-portal
# Issued from a console session; the secret is shown once (no-store).
curl -X POST "$API/credentials" -d '{"team":"acme","name":"billing-backend","access":"manage"}' ...
# {"credential":{"id":"cpc_3f9a...","team_id":"acme","access":"manage","state":"active",...},"secret":"gwcp_..."}
# The backend then calls the customer routes with it; no cookie or CSRF token.
curl -X PUT "$API/organizations/acme/acme-co/members/[email protected]" \
-H "Authorization: Bearer $CUSTOMER_CREDENTIAL" -d '{"customer_team":"eng"}'
curl -X POST "$API/credentials/cpc_3f9a.../revoke" ...

The credential reaches only the customer record, usage and approval routes of its own team. It never opens the console, never changes trusted keys, never issues or revokes credentials and is no session on any other route (401). It is checked live on every call: revocation and expiry (by the database clock) apply to the next call, and a write already holding the credential finishes first. A credential also lives only as long as its issuer administers its team: when the person who issued it is disabled or deleted, loses the team administrator (or global administrator) role, or leaves the team (with membership_roles, stops being its administrator), or when the team is deleted, its next call answers 401 and the credential is revoked at once (revoked_by: system:issuer-lost, audited as customer.credential.revoke_issuer_lost); a sweep once a minute revokes the ones nobody presents. Writes are audited under the credential’s ID (cpc_...); issuance and revocation are audited as customer.credential.create and customer.credential.revoke. Only the SHA-256 of the secret is stored, a team holds at most 100 active credentials, and a revoked credential stays listed as a tombstone. Failed attempts share the administrative Bearer limit (10 per client address per minute). Turning the flag off refuses every credential at once.

Each named level becomes one budget of the request, next to the quota policies that already apply to it:

  • One transaction. The organization, customer team and member counters are reserved in the same PostgreSQL transaction as every other policy, after the customer records are read in that transaction: the request fits all of them or none. Concurrent requests of many members serialize on the counters, so no member passes its own ceiling and the members together never pass their team’s or organization’s. The ceiling is checked against reservations, not after the fact.
  • Exact settlement. Settlement moves every customer counter by the same measured amount as the other budgets; an unknown outcome keeps the hold.
  • Windows. Each level is counted in every money window (UTC day, month, calendar periods, lifetime), so changing a period never resets spend.
  • Committed spend shown by the API and the console is the counter of the current window: settled spend plus open holds.

A level crossing one of its alert_thresholds writes a quota_budget_threshold alert and, in the same transaction, a customer_budget_crossed event, once per level, window and threshold, so a retried or concurrent request never repeats it. Subscribe an alert channel to customer_budget_crossed; the webhook’s operational.detail carries team, org, level (org, team or member), customer_id (team or member), threshold, budget_usd, committed_usd, budget_period, window_start, soft_budget, basis (reservation or settlement), quota_alert_id, request_id and trace_id. It holds no prompt, response or credential. A hard ceiling refuses a request that would pass it, so with hard budgets choose thresholds below 100 for an early warning.

GET /api/v1/admin/customer-portal/usage reads the usage events of one operator team’s customers over at most 366 days (default the last 30), optionally of one organization, grouped by org (default), team, member, UTC day, model or day,model. Each row has requests, input and output tokens, estimated_usd (known valuations priced from the price book with discounts and margins, an estimate, never a provider charge; with budget_charge_reports, budget_charge beside it is what the customer budgets took at the approved rates, the number the budget state counts, see budget charge beside the estimate), the counts of partial, unknown and not valued events, and tokens_unknown. Up to 1,000 rows; truncated says more exist. format=csv exports the same rows for billing.

By model. by=model gives one row per organization and served model alias, and by=day,model one row per organization, UTC day and model, newest day first (so a report cut at 1,000 rows keeps the recent days): what each customer used of each model, day by day. Add org= for one organization. The rows carry model (and day), and their CSV has a model column after day; the other groupings keep their columns. The numbers are the same as the structured usage query below grouped by customer_org and model (its calls, input_tokens and output_tokens).

Terminal window
curl "$API/usage?team=acme&org=acme-co&by=day,model" ...
# {"by":"day,model","rows":[{"org":"acme-co","day":"2026-11-25T00:00:00Z","model":"fast-chat","requests":412,"input_tokens":188000,"output_tokens":51200,"estimated_usd":"0.42",...}],"truncated":false}

By any grouping. The structured usage query takes customer_org, customer_team (org/team) and customer_member (org/member) as dimensions and filters with this flag on, across every team the reader sees: spend, requests, tokens, the cost of one request and, with evaluation metrics, pass rates by customer (group_by=customer_org&metrics=cost_usd,p95_cost_usd). Usage → Cost estimates shows the spend by customer organization, and Usage → Quality the results of an evaluation by the judged request’s customer organization.

GET /customer-portal/organizations/{team}/{org} takes three optional parameters that apply to its members (customer teams and profiles are returned as always):

Parameter Default Meaning
member_q none Up to 120 characters. Keeps the members whose ID or name contains the text, ignoring case.
member_sort id id, name, budget (the ceiling of the member’s first effective window), committed (the committed spend of that window) or utilization (the largest committed share among the member’s windows).
member_order asc asc or desc.

Members without the sorted value (no budget, no name) come last in either order, and ties keep the ID order. An invalid value answers 400 invalid_member_query. ?member_sort=utilization&member_order=desc lists the members closest to a ceiling first.

Access control → Customer portal (also shown to team administrators, scoped to their teams) lists the trusted keys (YAML entries without a revoke action), the organizations with their committed spend against the effective ceiling, and, for an opened organization, its customer teams, members and profiles with the ceiling source (override, own, profile or none) and overrides. Administrators create organizations and records, set overrides and trust keys; team administrators do the same for their teams; viewers read. Backend credentials issues a credential (the secret is shown once) and revokes it. Import organization takes a document (pasted or from a file) and a mode; the organization detail has Export and, for global administrators with end-user deletion on, Erase member with a dry run and an explicit confirmation. The organization detail also creates a view link for the organization or one member (shown once). Override requests lists the requests with Approve and Deny; the organization detail files a request (Request override) and, when direct overrides are allowed for the session, sets one (Set override). The usage panel groups by organization, team, member, day, model or day and model. The organization detail has Search members (by ID or name) with Sort members by ID, name, budget, committed spend or utilization, and Daily usage by model, the organization’s last 30 days per UTC day and model. With customer_budget_windows, the organization and record forms take Budget windows (1/day, 5/month), each level shows every window with its committed spend, and the override form chooses the Window it replaces. Portal settings shows whether unknown organizations are registered automatically, the cap and the default profile.

Migration 300 adds the budgets, override_period and auto_registered columns of gateway_customer_records (constant defaults, no rewrite), the budget_period column of gateway_customer_override_requests, and widens a reservation’s captured policies to 143 (NOT VALID, nothing is scanned). Upgrade step for budget windows: migrate and upgrade every replica, and only then turn customer_budget_windows on. An older replica knows one budget per level: it would enforce only the first window of a level that has several. To roll back, give those levels one budget first; with the flag off their requests are refused (422 customer_budget_windows_disabled), not admitted on one window.

Migration 165 adds the customer columns of gateway_batches and gateway_eval_runs (no default, NOT VALID shape checks: nothing is rewritten or scanned) and gateway_customer_view_tokens. Migration 164 adds the member erasure columns of gateway_end_user_deletions and two partial expression indexes on the usage events and durable receipts that name a member (built in the migration: on a large usage table, run it in a maintenance window). Migration 163 adds gateway_customer_override_requests. Migration 162 adds the tpm_limit, tpd_limit and model_allowances columns (constant defaults, no rewrite) and widens a reservation’s bounds to 182 charges and 134 captured policies (NOT VALID, nothing is scanned). Migration 161 adds gateway_customer_credentials (hashes only). Migration 160 adds gateway_customer_records, gateway_customer_trusted_keys, the customer_org, customer_team and customer_member columns of gateway_usage_events and gateway_durable_usage (no default and NOT VALID shape checks, so nothing is rewritten or scanned) and widens a reservation’s bounds to 158 charges and 131 captured policies. Upgrade step: migrate and upgrade every replica, then turn the flag on, and only then trust keys. An older replica does not know the headers: it would admit a trusted key’s request without the customer ceilings. To roll back, turn the flag off first (requests that still name a customer are then refused, not ignored).

Before migration 164 (operators): it builds two indexes on gateway_usage_events and gateway_durable_usage inside the migration transaction, which blocks writes to those tables while they build. On a large usage table, run gateway migrate in a maintenance window before upgrading the replicas.

Recorded 2026-11-16 against a running gateway (T158.007), separate from the in-process tests: the binary built with go build ./cmd/gateway, a postgres:16-alpine container, a mock OpenAI-compatible provider (10 input and 5 output tokens per answer, 50 ms latency) and a webhook receiver, all owned by the run and bound to 127.0.0.1. Synthetic customers only; no real provider was called (0 calls, 0 USD). The gateway ran with customer_portal, customer_portal_credentials, customer_self_service, end_user_deletion, alert_channels, team-scoped console users and customer_portal.require_override_approval: true, one YAML backend key trusted with require_identity, and a webhook channel subscribed to the three customer events (allow_loopback_http).

Step Result
A team administrator (named user) issues a manage backend credential; the credential calls GET /api/v1/admin/config 201; 401 (no session outside customer routes)
The credential imports an organization (1 profile, 1 customer team, 6 members) with mode=create; into another team 200, 9 records created; 403
Export from the team, import into a second team, export again identical documents (9 records)
Organization hard cap set to 5.5 reservations above its spend; 30 concurrent requests from 6 members 5 admitted, 25 refused with 429, 5 provider calls; committed with open holds 0.005308 USD and after settlement 0.000090 USD, both under the 0.028796 USD cap; member counters sum to the organization’s
Member at its own ceiling; the team administrator sets an override directly 429 customer:member; 403 approval_required
The credential files an override request (25 s); the credential approves; the team administrator approves 201 pending; 401; 200 approved
The member’s request under the override; again after it expires 200; 429 customer:member (database clock)
Member allowance for public exhausted, fallback cheap 200 with X-Gateway-Fallback: allowance:cheap, one call to the cheap model, usage recorded on <id>.fallback for the same member
Webhook receiver customer_budget_crossed ×2 (50 % and 80 % of the cap, reservation basis), customer_override_requested ×1, customer_override_decided ×1
View token for one member; the view; after revocation 201; only that member (6 requests), no operator team or other member; 401
Member erasure (dry run, confirm) through POST /api/v1/admin/end-user-deletions; the member’s next request 5 usage rows found and cleared, record deleted, job waiting_receipts (receipt quiet period); 422 customer_unknown
Backend credential revoked; its next call 401

The gateway logged no error during the run. The run’s processes, database and secrets were removed afterwards.

  • Auto-routing helper calls are not charged to the customer.
  • An erased member’s ID stays in budget counters and budget alerts (financial evidence) until their windows age out. Prefer opaque IDs when that matters.
  • Override approval gates overrides only: a team administrator or backend credential can still change a member’s own budget_usd or import over it. Restrict who manages customers accordingly.
  • An allowance fallback answers chat-pipeline requests only, once (no chain); native routes keep the 429.
  • Usage is reported from usage events.
  • soft_budget and alert_thresholds are per level, not per budget window.

Every route below needs a console session or an admin Bearer token, the role’s permission and, for writes, the X-CSRF-Token header; the full contract is in the API reference.

Route What it does
GET /api/v1/admin/customer-portal The portal settings: trusted keys, request header names, default alert thresholds and budget periods, and the effective customer_portal object (require_override_approval, override_request_ttl_hours, auto_register_members, view_token_max_minutes, auto_register_organizations, max_auto_organizations, auto_organization_profile), which the console shows read-only under Portal settings, and max_budget_windows
GET /api/v1/admin/customer-portal/credentials Lists the server-side credentials issued for operator backends
POST /api/v1/admin/customer-portal/credentials Issues a credential for an operator backend, bound to one team and to customer management
POST /api/v1/admin/customer-portal/credentials/{id}/revoke Revokes a credential at once
GET /api/v1/admin/customer-portal/organizations Lists the customer organizations of the caller’s teams
POST /api/v1/admin/customer-portal/organizations/{team}/import Writes one customer-portal/v1 document (organization, profiles, teams, members) into the team in one transaction; mode=create refuses existing records
GET /api/v1/admin/customer-portal/organizations/{team}/{org} Reads one customer organization with its teams, members and profiles; member_q, member_sort and member_order search and sort the members
PUT /api/v1/admin/customer-portal/organizations/{team}/{org} Creates or replaces a customer organization
DELETE /api/v1/admin/customer-portal/organizations/{team}/{org} Deletes an organization with all its teams, members and profiles
GET /api/v1/admin/customer-portal/organizations/{team}/{org}/export Exports one organization in the import format
PUT /api/v1/admin/customer-portal/organizations/{team}/{org}/members/{id}/override Sets a member’s temporary budget ceiling
DELETE /api/v1/admin/customer-portal/organizations/{team}/{org}/members/{id}/override Clears a member’s override at its current version
POST /api/v1/admin/customer-portal/organizations/{team}/{org}/members/{id}/override-requests Asks for a member override, for at most 366 days, to be approved by someone else
POST /api/v1/admin/customer-portal/organizations/{team}/{org}/view-tokens Mints a read-only view token for the organization or one member, returned once
PUT /api/v1/admin/customer-portal/organizations/{team}/{org}/{kind}/{id} Creates or replaces a customer team, member or budget profile of an organization
DELETE /api/v1/admin/customer-portal/organizations/{team}/{org}/{kind}/{id} Deletes a customer team, member or profile
GET /api/v1/admin/customer-portal/override-requests Lists the override requests of the caller’s teams
POST /api/v1/admin/customer-portal/override-requests/{id}/approve Approves a pending request; never by its requester or the issuer of the credential that filed it
POST /api/v1/admin/customer-portal/override-requests/{id}/deny Denies a pending request, with the same rights as approving
PUT /api/v1/admin/customer-portal/trusted-keys/{key_id} Trusts a key to assert the identity of its team’s customers, or changes require_identity
DELETE /api/v1/admin/customer-portal/trusted-keys/{key_id} Revokes a stored trust entry
POST /api/v1/admin/customer-portal/view-tokens/{team}/{id}/revoke Revokes a view token at once

m7gtw[email protected]