Model Gateway — Mode E: Verified Subscriber Passthrough
Status: implemented behind two independent switches, both default OFF. No org
is served until both are on.
Artefacts: PRD #2644 v1.7 Slice 6 (MG-SUB.1–.25) · HLD #3692 · LLD #3698 ·
ADR-0021 Amendment 1 §A1 · S0 measurement
docs/architecture/model-gateway-mode-e-s0.md
Mode E lets a developer point Claude Code at the Model Gateway and keep using their own Anthropic subscription. The organisation supplies no key and pays nothing for the tokens; what it gets is governance and a ledger.
This page is for the operator and the org admin. It is deliberately short on architecture and long on the two configuration lines, the error contract, and what each party can and cannot see.
1. The two switches, and why there are two
They are not redundant and neither can substitute for the other.
| Switch | Owner | Where | Default |
|---|---|---|---|
MODEL_GATEWAY_SUBSCRIBER_ADMISSION | the operator of this deployment | process environment / ConfigMap | disabled |
the org's platform-managed llm_endpoints row | the org's L5 admin | EnableSubscriptionMode RPC | absent |
The first says does this build run the Mode E admission at all. The second is the tenant's own kill-switch. Collapsing them would mean a tenant's kill-switch could be defeated by a ConfigMap, or an operator's rollout gate could be defeated by a tenant.
Reading the live state. One boot line, model gateway controls wired, carries
all of it:
subscriber_admission=disabled
subscriber_surface_allowlist="3 entries, 2 forwardable: POST /v1/messages, POST /v1/messages/count_tokens"
capture_policy=off
capture_never_classes=map[subscription:...]
subscription_accounts=*subscriberauth.AccountGate
subscriber_admission is printed unconditionally and in both positions: on a
fleet where the variable is unset, this line is the only thing that distinguishes
"the operator has not switched Mode E on" from "this build has no subscriber
admission at all".
To turn the admission on:
MODEL_GATEWAY_SUBSCRIBER_ADMISSION: "enabled" # the only other legal value is "disabled"
An unrecognised value is a startup failure, deliberately: answering a typo
with a default is how the typo becomes a policy, and here it would silently
become disabled — a mode an org has paid for, switched on, and that quietly
refuses every request.
2. What a subscriber configures (the two lines)
The subscriber gets these from their own Model Subscriptions page, after accepting the disclosure. Nobody else ever sees the credential — not their Manager, not an operator, not a log.
export ANTHROPIC_BASE_URL="https://<model-gateway-host>"
export ANTHROPIC_CUSTOM_HEADERS="X-UpsQuad-Subscriber: uq_sub_…"
With more than one team grant, a third line selects which team the usage is attributed to:
export ANTHROPIC_CUSTOM_HEADERS="X-UpsQuad-Subscriber: uq_sub_…
X-UpsQuad-Team: <unit-id>"
X-UpsQuad-Subscriber is not an Anthropic credential. It identifies the
member to their organisation's gateway and authorises exactly one thing: being
identified. It cannot be used to sign in anywhere. The subscriber's actual
Anthropic bearer never leaves their machine except as a byte-for-byte relay to
api.anthropic.com.
ANTHROPIC_API_KEY must be unset. A shell that still exports one produces
subscription_shape_invalid — the gateway refuses rather than guessing which of
two credentials was meant. That refusal is visible on the subscriber's own page,
which is where a misconfiguration should surface.
3. The consent text (MG-SUB.10 / OQ-18, ratified)
The subscriber accepts this, verbatim, before a credential is minted. It is reproduced here so an operator answering a question gives the same answer the screen does:
Your organisation's gateway reads each prompt and response as it passes, to apply content and PII policy. It does not store them — capture is off for Model Subscribers and cannot be turned on without your agreement. It records the model you used, how many tokens, when, and whether a request was refused. It never sees your Anthropic password, your login, your bill, or your plan. Your subscription credential passes through and is never stored or logged. You can see everything your organisation sees about you, on your own page, and you can leave at any time.
A posture-text change refuses until re-consent. When the platform publishes a
new consent_version, every active registration whose stored version is older is
refused subscriber_consent_required on the next request — there is no
serving window. The alternative would leave traffic flowing under an agreement to
text that no longer describes what happens.
Capture is off, and it cannot be switched on
capture_policy=off and capture_never_classes on the boot line are the
machine-readable form of the sentence above. Enabling capture for Mode E needs
four things — the deployment flag, an L5 action, re-consent from each affected
subscriber, and an audit row — and v1 has no per-subscriber consent column,
so the third cannot be recorded, so capture cannot be enabled. It is stricter
than MG-2b.5's on-prem default, by requirement.
Guardrail and PII inspection in flight is not capture. It happens, it is disclosed in the first sentence of the consent text, and it is the reason the text leads with "reads".
4. What each party can see
| the subscriber | their Manager | an operator | |
|---|---|---|---|
| requests, tokens by class, model mix | yes | yes | aggregate |
| refusals and their reasons | yes | yes | aggregate by reason |
account binding state (unbound / bound / mismatch) | yes | yes | no |
| prompts and completions | — | never | never |
| the subscription credential | once, at mint | never | never |
| the subscriber's Anthropic plan, limits or bill | — | never | never |
| money spent by the organisation | ₹0 — "subscription-billed" | the same fixed words | — |
A subscriber always sees exactly what their Manager sees about them. That is MG-FE.9 and it is a requirement rather than a courtesy.
There is no money figure. A Mode E ledger row carries
cost_basis = 'subscription_billed' and cost_usd IS NULL, and every surface
renders the fixed words "subscription-billed — not metered to this
organisation". Never $0.00: a zero is a claim that the organisation paid
nothing, and the truth is that the question does not apply to it.
The claim bound (NG-7)
Mode E governs what Claude Code sends and receives. It does not govern what Claude Code does on the developer's machine — files it reads, commands it runs, tools it invokes locally. Permitted wording: "every model call Claude Code makes through the gateway is governed and recorded". Not permitted: any form of "we govern Claude Code".
What the account binding detects (MG-SUB.10)
metadata.user_id is client-supplied and unsigned. The binding detects
accident and casual sharing — a pasted config line, a laptop with a former
teammate's credential — reliably, because neither changes what the CLI sends. It
does not detect a determined party. The column is named
observed_account_uuid so nothing in the schema reads as a verified fact, and
tenant-facing copy must not say the binding "verifies" anything.
5. The error contract
Every row below is credential_class='subscription',
cost_basis='subscription_billed', cost_usd NULL. A refused subscription call
is "refused — not metered to this organisation", never $0.00.
| Reason | HTTP | Step | Ledger row | What to do |
|---|---|---|---|---|
subscription_mode_disabled | 403 | 3/identity or 5/routing | only when the org is known | the org has not enabled Model Subscriptions, or an L5 disabled it. Ask the org admin. |
subscriber_identity_invalid | 401 | 3/identity | no (no org to attribute to) | the header matched no registration. Register on the portal. |
subscriber_identity_expired | 401 | 3/identity | yes | rotate the credential on the Model Subscriptions page. |
subscriber_revoked | 403 | 3/identity | yes | access is over. Ask the Manager. |
subscriber_suspended | 403 | 3/identity | yes | a Manager paused it; one click reinstates. |
subscriber_consent_required | 403 | 3/identity | yes | accept the current disclosure on the page. |
ambiguous_caller_identity | 401 | 3/identity | yes | a platform credential arrived beside the header. Remove one. |
subscription_shape_invalid | 401 | 3/identity | yes | unset the Anthropic API-key variable in the shell. |
subscriber_team_not_granted | 403 | 3/identity | yes | X-UpsQuad-Team names a team this subscription is not granted; check the value or remove the header. |
surface_not_allowed | 404 | 5/surface | yes | the path is not one Mode E relays. The message lists the ones it does. |
subscriber_account_unreadable | 400 | 5/account | yes | the request carried no readable Anthropic account id. |
subscriber_account_mismatch | 403 | 5/account | yes | the credential is bound to a different Claude account. Re-bind on the Model Subscriptions page. |
| every existing gate 4–7e reason | existing | existing | yes | unchanged. |
| Anthropic's own 401 / 429 / 5xx | upstream's | — | allow row | passed through verbatim (MG-SUB.19). |
Two of these are worth an operator's attention:
subscriber_identity_invalidandsubscriber_identity_expiredshare the status 401 by design. A status-only probe must not be able to tell a genuine expired credential from an unregistered one. The distinguishing field iserror.typein the body, which the legitimate holder reads.- An Anthropic 401 is relayed unchanged and marks nothing. We do not validate, refresh, interpret or retry a subscription authentication failure, and we never substitute our own error. A developer whose subscription lapsed must see Anthropic's answer, because ours would be a guess about a subscription we cannot see. A persistent 401 pattern may be surfaced to the subscriber as information, never as a governance state.
The allowed surfaces
subscriber_surface_allowlist on the boot line is the live answer. As measured
by the S0 spike against claude-cli 2.1.284:
| Method + path | Disposition | Carries an account id |
|---|---|---|
POST /v1/messages | forwarded | yes |
POST /v1/messages/count_tokens | forwarded | no (0 of 16 recorded bodies carried metadata) |
HEAD /api/hello | answered by the edge's 404 seal | no |
GET /v1/models is deliberately absent: claude-cli 2.1.284 never requested
it in any arm, including with the /model picker open. Re-measure on a CLI
upgrade before adding it.
6. Diagnosing a refusal
- Read the boot line first.
subscriber_admission=disabledexplains everysubscription_mode_disabledin one word, and no amount of registry inspection will add to that. - Then ask whether the ORG is enabled.
subscription_mode_disabledat gate5/routing(rather than3/identity) means the admission ran, the subscriber resolved, and the org has no live platform-managed endpoint row — an L5 either never ranEnableSubscriptionModeor has runDisableSubscriptionMode. deciding_gateon the ledger row says which control refused.3/identityis about the registration;5/surfaceand5/accountare about the request;7a–7eare the ordinary gate chain and behave exactly as they do for every other caller.model_gateway_subscriber_refusals_total{org_id,reason}carries the whole closed reason vocabulary, pre-created at zero on first sight of an org — so a quiet org and an unwired build are distinguishable, and an alert over the series can fire.model_gateway_subscriber_account_events_total{org_id,event}countsboundandmismatch. Amismatchis the one worth paging a Manager about. A subscriber's own re-bind is NOT counted — it is visible in the audit trail (llm_subscriber_account_rebound) and in the row's clearedaccount_state, so it is uncounted rather than unobservable. #3744 adds thereboundseries; until it lands, do not look for one.
Label values are reason codes and ids only — never a header, a bearer, an e-mail or an account uuid.
7. Failure modes and what the gateway does
| Failure | Behaviour |
|---|---|
| Postgres unreachable at the subscriber lookup | 503, no cached verdict, no upstream dial |
| Postgres unreachable at the account bind | 503 governance_backend_unavailable at 5/account |
| Redis unreachable | the existing step-4 / 7d posture, unchanged |
| guardrail or PII backend unreachable | deny, retryable (MG-NFR.3) |
| Anthropic 401 / 429 / 5xx | relayed verbatim; the registration is not marked |
| the org's mode disabled mid-flight | the in-flight request completes; the next is refused |
| the member is offboarded | the cascade revokes every registration and grant; the next request is 403 |
| a stolen header, before any bind | the thief's account binds, and the member sees the bind audit row |
The last one is the binding's whole value: first-use is a tell-off-first event delivered to the member's own audit feed, with the observed account and the time.
8. Things an operator must not do
- Do not add an edge route for
HEAD /api/hello. S0 ran a controlled comparison and measured the CLI tolerant of the sealed 404 — identical request multisets, no retries, no diagnostics. A route would be a second surface on a sealed hostname with no measured need, andTestSurfaceEdge_EdgeAnsweredEntriesAgreeWithTheEdgefails on it. - Do not point a
caller_subscriptionendpoint row anywhere buthttps://api.anthropic.com. Three independent controls refuse it (a database CHECK, the dial guard, and a per-request target assertion), so the attempt fails rather than leaks — but it fails as an outage for that org. - Do not give the Model Gateway process an Anthropic key for Mode E. The vault is not read on this path at all. A key configured "to be safe" would be a second credential on a request whose entire contract is that nothing of the organisation's rides it.
- Do not enable capture for the subscription class. It is refused by construction; the point of this line is that an attempt will look like a configuration that silently did nothing.