Connecting your agent to the UpsQuad Model Gateway
For: the developer of an agent that runs outside UpsQuad (your own process, service or agent framework) and must make LLM calls for an UpsQuad customer (a tenant) through UpsQuad's Model Gateway. Not for: the owner of an MCP server that a tenant connects to UpsQuad. That is a different handout: Integrating your MCP server with UpsQuad.
The handout describes what the gateway does on the wire today, and it says plainly where something is limited or not offered.
1. What the Model Gateway is to your agent
The Model Gateway is an HTTP proxy that speaks the providers' own APIs. Your agent calls it exactly as it would call an OpenAI-compatible or Anthropic API, with two differences: the base URL is UpsQuad's, and the bearer token is an UpsQuad token that identifies your agent.
For each call the gateway decides, in a fixed order, whether your agent may make it: who you are, whether you are within your rate limit, which of the tenant's provider endpoints serves the model you named, whether that endpoint is approved for your agent's team, whether your agent's clearance, its enabled models and the team's model list allow it, whether a budget is exhausted, and whether an input guardrail objects. Only then does it forward your request to the provider, with the tenant's provider key attached, and record what the call consumed against the tenant.
Your agent never holds a provider key, and the provider never sees your UpsQuad token. Your agent holds one UpsQuad client credential, which it exchanges for short-lived tokens. The tenant's provider keys stay in UpsQuad's vault.
Your agent is a full agent of the tenant. It belongs to one team, has a clearance level, a set of enabled models and budgets, and every rule that applies to the tenant's agents running inside UpsQuad applies to it in the same way. Every usage record it produces is marked as coming from an agent that runs outside UpsQuad.
2. Status at a glance
| Area | State today |
|---|---|
| Where | Gateway: https://model-gw-beta.upsquad.ai. Token issuer: https://auth-beta.upsquad.ai. Both are on the public internet, with no interactive sign-in in front of them. |
| What the service is offered for | Evaluation and end-to-end testing traffic. Ask your UpsQuad contact before you send production workloads. |
| Provider dialects | openai_compatible and anthropic. Native AWS Bedrock (SigV4 request signing) is not supported; a tenant can front Bedrock with an OpenAI-compatible endpoint instead. |
| Paths | Everything under /v1/ is relayed to the tenant's endpoint. Every call must carry a JSON body that names a model. There is no model-listing endpoint. |
| Streaming | Supported. Server-sent events are relayed as they arrive. |
| Translation between the two dialects | Off unless the tenant's team allows it and your request opts in (section 5.7). |
| Token grant | OAuth 2.0 client_credentials only, authenticated with private_key_jwt (preferred) or client_secret_post. Tokens last about 10 minutes. There are no refresh tokens. |
| Rate limits | At the edge: 120 gateway requests and 30 token requests per minute, each shared by every caller of the service. Per tenant, team and agent limits apply behind that (section 6.5). |
| Per-call time limit | A single call may run for at most 150 seconds, streamed or not (section 5.6). |
3. Before you start
3.1 What the tenant sets up
You cannot do these steps yourself. Your tenant contact does them in UpsQuad.
| # | Step | Who, at the tenant |
|---|---|---|
| 1 | Register the provider endpoint (its URL and dialect), and approve it | An administrator registers; a top-level administrator approves |
| 2 | Store the provider key for that endpoint | An administrator |
| 3 | Bind the endpoint to the team your agent will belong to, with the models the team may use, and approve the binding | An administrator and the team's manager |
| 4 | Register your agent as an external agent of that team, with its clearance level, and narrow its models if wanted | An administrator |
| 5 | Set budgets, if any, at organisation, team or agent level | An administrator |
The tenant must also be enabled for external agents. If it is not, every token request answers 401 invalid_client (section 4.6).
3.2 What you receive
Step 4 issues exactly one client credential for your agent:
- a
client_idof the formext_followed by 32 hex characters. It is stable for the life of the registration. - either nothing secret, because you gave the tenant your public key as a JWK (preferred: section 4.4), or a client secret of the form
uxe_…, generated by UpsQuad and shown once, at registration. UpsQuad stores only a hash of it and cannot show it again.
A private key is refused at registration: give the tenant only the public half. Rotation is done by the tenant: a new public key replaces the old one, or a new secret is generated and shown once; the client_id does not change. Revocation stops every further token request (section 4.6).
One client_id is one agent. If you run several agents for the tenant, each needs its own registration.
4. Getting a token
4.1 The issuer
| What | Value |
|---|---|
| Token endpoint | POST https://auth-beta.upsquad.ai/oauth/token, form-encoded, at most 64 KiB |
| Authorization-server metadata (RFC 8414) | https://auth-beta.upsquad.ai/.well-known/oauth-authorization-server |
| Signing keys (JWKS) | https://auth-beta.upsquad.ai/.well-known/jwks.json |
| Grant | grant_type=client_credentials only |
| Client authentication | private_key_jwt or client_secret_post, the two methods the metadata advertises |
The issuer hostname also serves UpsQuad's MCP team gateway, which you do not need for the Model Gateway. Any other path answers 404 with the code issuer_path_not_published.
4.2 The resource parameter: the one value you must get right
Send resource=https://auth-beta.upsquad.ai/llm with every token request. This RFC 8707 resource indicator is what makes the token valid at the Model Gateway.
- It is the issuer identifier (
issuerin the metadata) with/llmappended. It is not derived from the gateway's hostname:https://model-gw-beta.upsquad.ai/llmis refused with400 invalid_target. - It is matched exactly. A trailing slash, a different path or a prefix of it is refused with
400 invalid_target. - Without a
resourcethe issuer still grants a token, but for UpsQuad's MCP team gateway. The Model Gateway refuses that token with401and the message "this token was not issued for the Model Gateway". The same credential can obtain either token; onlyresourcediffers.
4.3 Request, with a client secret (client_secret_post)
curl -s -X POST https://auth-beta.upsquad.ai/oauth/token \
-d grant_type=client_credentials \
-d client_id="$UPSQUAD_CLIENT_ID" \
--data-urlencode client_secret="$UPSQUAD_CLIENT_SECRET" \
-d resource=https://auth-beta.upsquad.ai/llm
The secret goes in the form body. HTTP Basic client authentication is not accepted.
4.4 Request, with your own key (private_key_jwt, RFC 7523)
You sign a short-lived JWT, the client assertion, with your private key and send it instead of a secret. UpsQuad holds only your public key.
| Assertion | Rule |
|---|---|
| Signature algorithm | RS256, RS384, RS512, PS256, PS384, PS512, ES256, ES384 or ES512. Symmetric (HS*) and none are refused. |
iss and sub | both equal to your client_id |
aud | must contain https://auth-beta.upsquad.ai/oauth/token, the token endpoint's own URL |
exp | required; not in the past, and at most 5 minutes in the future (60 seconds of clock skew are tolerated either way) |
jti | required and unique: an assertion is accepted once, and a second use before it expires is refused |
| Form field | Value |
|---|---|
grant_type | client_credentials |
client_assertion_type | urn:ietf:params:oauth:client-assertion-type:jwt-bearer |
client_assertion | the signed assertion |
resource | https://auth-beta.upsquad.ai/llm |
A client_id form field is not needed: the client is read from the assertion. If a request carries both an assertion and a secret, the assertion is used.
4.5 Response
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
Pragma: no-cache
{"access_token":"<JWT>","token_type":"Bearer","expires_in":600}
There is no refresh_token. Treat the access token as opaque: send it as it is, and do not build logic on its claims. For reference, a decoded token looks like this (JWT header, then payload; values shortened):
{"alg": "RS256", "kid": "…", "typ": "JWT"}
{
"iss": "https://auth-beta.upsquad.ai",
"aud": ["https://auth-beta.upsquad.ai/llm"],
"azp": "agent-runtime",
"org_id": "…",
"unit_id": "…",
"agent_id": "…",
"runtime": "external",
"iat": 1763380000,
"exp": 1763380600
}
What the token is scoped to. One agent (agent_id), in one tenant (org_id) and one team (unit_id), at one surface: the Model Gateway. There is no sub, no scope and no list of models in the token. Your agent's clearance and its enabled models are read by the gateway on every call, and the tenant's endpoint and budget settings are re-read within 30 seconds, so a change the tenant makes takes effect almost at once, not when your token expires.
What a token outlives. The gateway checks the token's signature, issuer, audience and expiry. Revoking your client credential stops new tokens at once; a token already issued remains usable until it expires, at most about 10 minutes later.
Lifetime. exp is iat plus 10 minutes, and the gateway allows no clock skew past exp. Cache the token and request a new one shortly before it expires (for example after 8 minutes). Do not request a token per call: the issuer limits each client to 1 request per second with a burst of 5, and the edge allows 30 token requests per minute for all callers together.
4.6 What the issuer refuses
| You sent | Status | Body |
|---|---|---|
An unknown client_id, a wrong secret, a bad or expired assertion, a reused jti, an assertion whose aud is not the token endpoint, a revoked credential, a secret for a key-registered client (or the reverse), no client authentication at all, or a tenant that is not enabled for external agents | 401 | {"error":"invalid_client","error_description":"client authentication failed"}. Byte-identical for every one of these causes, by design, so that the response never reveals whether a client_id exists. For a client_id that exists, the true reason is written to the tenant's audit log, where your tenant contact can read it. |
A resource this issuer does not serve | 400 | {"error":"invalid_target","error_description":"the requested resource is not served by this authorization server"} |
A grant_type other than client_credentials | 400 | {"error":"unsupported_grant_type","error_description":"only client_credentials is supported"} |
| A body that is not a readable form, or larger than 64 KiB | 400 | {"error":"invalid_request","error_description":"malformed form body"} |
GET (or any method but POST) | 405 | {"error":"invalid_request","error_description":"POST required"}, with Allow: POST |
| Too many requests (section 4.5), or a lockout after 5 consecutive failures | 429 | {"error":"slow_down","error_description":"rate limit exceeded"} |
| Over the edge limit of 30 token requests per minute | 429 | a plain-text local_rate_limited body from the edge, with x-ratelimit-limit and x-ratelimit-remaining headers |
Lockout. After 5 consecutive failures for one client_id, or from one source address, further requests are refused with 429 slow_down for 1 second, doubling with each further failure up to 5 minutes. A success clears it. A misconfigured agent that retries in a loop therefore locks itself out: stop on a 401, fix the credential, then retry.
5. Making a call
5.1 The request
POST /v1/chat/completions HTTP/1.1
Host: model-gw-beta.upsquad.ai
Authorization: Bearer <access_token>
Content-Type: application/json
{"model":"<a model id your team may use>","messages":[{"role":"user","content":"hello"}]}
- Authentication is the
Authorizationheader, with exactlyBearer(capital B, one space) before the token. A token inx-api-keyor any other header is not read. - The path is the provider's own path under
/v1/:/v1/chat/completions,/v1/embeddingsor/v1/responsesfor an OpenAI-compatible endpoint,/v1/messagesfor an Anthropic endpoint. The gateway keeps no route table: the path you send is appended, as it is, to the URL the tenant registered for the endpoint, and an unknown path reaches the provider and is answered by it. - The body must be a JSON object with a non-empty
model. A request with no body, a body that is not JSON, or nomodelis refused before anything is forwarded. SoGET /v1/modelsis refused with400 invalid_request: ask your tenant contact which model ids your team may use. - The model decides where the call goes. It must be a model id that one of the tenant's approved endpoints serves, that the endpoint's binding to your team lists, and that is enabled for your agent. The endpoint's dialect then decides which request shape you must send (section 5.3).
5.2 What the gateway does to your request
| Removed before forwarding | Why |
|---|---|
Authorization, X-Api-Key, Api-Key, Proxy-Authorization, Cookie | Your credentials never reach the provider |
Every header beginning X-Upsquad- (after reading X-Upsquad-Translate, section 5.7) | UpsQuad's own control headers stay inside UpsQuad |
X-Forwarded-*, Forwarded, X-Real-Ip, True-Client-Ip, X-Request-Id, CF-*, X-Envoy-* | Network metadata about you is not disclosed to the provider |
Your traceparent, tracestate and baggage | The gateway sends its own trace context instead |
Hop-by-hop headers (Connection, Keep-Alive, Te, Trailer, Transfer-Encoding, Upgrade and any header Connection names) | HTTP rules for proxies |
| Added | Value |
|---|---|
| The tenant's provider key | Authorization: Bearer <key> for an openai_compatible endpoint, x-api-key: <key> for an anthropic endpoint |
Accept-Encoding | gzip |
Every other header you send, such as anthropic-version or anthropic-beta, is forwarded unchanged. Your body is forwarded byte for byte: the gateway adds nothing to it, removes nothing and rewrites nothing, unless you opted into translation. Your query string is forwarded unless the tenant's registered URL carries its own.
Do not send a header named X-UpsQuad-Subscriber. It selects a different way of calling the gateway, which does not accept an agent token.
5.3 Dialect: which request shape you must send
The gateway infers your request's dialect from its path and from the top-level keys of its JSON body:
| Dialect | Named by the path ending in | Named by any of these top-level body keys |
|---|---|---|
anthropic | /messages, /complete | anthropic_version, system, stop_sequences, top_k, thinking, max_tokens_to_sample |
openai_compatible | /chat/completions, /completions, /responses | max_completion_tokens, frequency_penalty, presence_penalty, logit_bias, logprobs, top_logprobs, response_format, seed, stop, n, functions, function_call, parallel_tool_calls, stream_options, user, store, modalities, audio, reasoning_effort |
A key whose value is null does not count.
- One dialect named, and it is the endpoint's: forwarded. This is the normal case.
- One dialect named, and it is not the endpoint's: refused with
400 dialect_mismatch, unless translation applies (section 5.7). The message names both dialects. - Both dialects named, for example a
/v1/messagesrequest that carriesstop: refused with400 dialect_ambiguous. The message lists the evidence it found. - Neither named, for example
/v1/embeddingswith onlymodelandinput: forwarded as it is.
5.4 The response
The provider's response is relayed to you: its status, its body, and its headers except hop-by-hop headers, Set-Cookie and any X-Upsquad-* header the provider sent. A provider error, such as the provider's own 400 or 429, reaches you unchanged, in the provider's format (section 6.6).
The gateway adds one header to every response it produces after authenticating you, including its own refusals:
X-Upsquad-Usage-Event-Id: 3b0c1f9e-…
It identifies the usage record the gateway writes for this call. Log it: it is the handle your tenant contact needs to find the call (section 7).
5.5 Streaming
Send "stream": true as the provider's API expects. The gateway relays each server-sent event as it arrives and does not buffer.
OpenAI-compatible endpoints: ask for usage. Add "stream_options": {"include_usage": true} to a streamed request. The gateway forwards your body unchanged and never adds this for you. Without it, most OpenAI-compatible servers send no token counts in a stream, and the call is recorded as unmetered: its cost is unknown and the tenant's token budget can only be stated as a lower bound. Worse, while a budget is in force, an endpoint whose last call reported no usage is closed to further calls with 403 endpoint_unmetered, apart from an occasional probe call, until a call reports usage again. One unmetered stream can therefore block every agent on that endpoint. Anthropic streams carry their usage without being asked.
5.6 Size and time limits
| Limit | Value | What you see |
|---|---|---|
| Request body | 32 MiB | 413 request_body_too_large. A body is refused, never truncated. |
| Receiving your request | the whole request, headers and body, within 60 seconds | the call fails and nothing is forwarded |
| Provider's first response, streamed call | within 30 seconds | 502 upstream_unavailable |
| Provider's response, non-streamed call (for which the response is the whole answer) | within 90 seconds | 502 upstream_unavailable |
| Whole call, streamed or not | 150 seconds | a stream still running at 150 seconds is ended there; you receive what was sent until then |
| Silence on an open stream | 300 seconds without a byte | the edge closes the connection |
If you need longer generations, split the work into several calls.
5.7 Translation between dialects (opt-in)
If your agent speaks one dialect and the endpoint serving your model speaks the other, the gateway can translate requests and responses in both directions, but only when both of these are true:
- the tenant's binding of that endpoint to your team allows translation, and
- your request carries the header
X-Upsquad-Translate: 1.
Translation is never inferred. X-Upsquad-Translate: 0 declines it explicitly; any other value is refused with 400 translate_opt_in_malformed. Opting in without the tenant's permission is refused with 403 translation_not_permitted.
A feature that has no equivalent in the other dialect is refused, never dropped. If your request uses something the other dialect cannot express, you receive 501 translation_unavailable before anything is sent to the provider. A body that does not parse as a request of your own dialect is 400 invalid_request. If, during a translated stream, the provider sends something that cannot be expressed in your dialect, the status has already been sent, so the gateway reports it in the stream as an error event in your dialect and stops. Treat such an event as a failed call.
6. What you will be refused for
6.1 Five response shapes, and how to tell them apart
| Who answered | Status | Body | Tell-tale |
|---|---|---|---|
| The issuer (section 4.6) | 400, 401, 405, 429 | {"error":"…","error_description":"…"} | OAuth 2.0 shape |
| The gateway, refusing your token | 401 | {"error":{"type":"invalid_token" or "invalid_api_key","message":"…"}} | a type field, no code; no X-Upsquad-Usage-Event-Id |
| The gateway, refusing the call | see the table in 6.4 | {"error":{"code":"…","message":"…", …}} | a code from the table in 6.4; X-Upsquad-Usage-Event-Id present |
| The edge, over the shared request limit | 429 | plain text local_rate_limited | retry-after: 60, x-ratelimit-limit: 120 |
| The provider | any | the provider's own | anything else |
6.2 Token refusals (401)
type | message | Cause | What to do |
|---|---|---|---|
invalid_api_key | missing or malformed Authorization header | No Authorization: Bearer … header | Send the header (section 5.1) |
invalid_token | this bearer token could not be validated | Expired, badly signed, from another issuer, or not a JWT. These cannot be told apart from the response. | Get a new token. If a fresh token is refused too, check that you send it unmodified. |
invalid_token | this token was not issued for the Model Gateway | The token was granted without resource, or for another resource | Request it with resource=https://auth-beta.upsquad.ai/llm (section 4.2) |
invalid_token | this token does not resolve to an organisation, … to an agent, … to a caller identity | The token lacks the claims of an agent token | Ask your tenant contact; the registration is incomplete |
An invalid_token refusal is always safe to answer with one fresh token and one retry. If that fails too, stop.
6.3 The call-refusal envelope
{"error":{"code":"budget_exceeded_team","message":"…","gate":"7d/budget","class":"quota","fleet":"agent"}}
| Field | Meaning |
|---|---|
code | The stable identity of the refusal. Key on it, never on message. |
message | Human-readable, names what to change. Wording may change without notice. |
gate | The step of the gate chain that refused (6.5). Absent when the refusal came after every step had allowed the call, for example when the provider could not be reached. |
class | What the status means for a retry (table below). Absent at 500 and 501, on purpose: there, no retry can succeed until UpsQuad deploys a different build. |
fleet | agent for every call made with an agent token. |
A 429 from the gateway always carries a Retry-After header, in seconds; no other gateway refusal does. Ignore fields you do not recognise: new optional fields may be added.
class | Statuses | What it tells your client |
|---|---|---|
quota | 402, 429 | A cap is exhausted. Retrying now cannot succeed; retrying after Retry-After (429), or after the budget period rolls over or the cap is raised (402), can. |
policy | 401, 403 | The tenant's configuration refuses this call. No retry can succeed until someone changes that configuration. |
request | 400, 404, 413 | The request is the problem. Change it. |
unavailable | 502, 503 | A control or the provider could not be reached. You did nothing wrong, and a retry with backoff may succeed. |
6.4 Every refusal code
This is the complete list the gateway can return in error.code. Ledger says how the tenant's records hold the refusal: deny is a governance denial, written to the tenant's tamper-evident audit log; allow means governance allowed the call and something after it failed, so no denial is recorded; unassessed means no governance decision was reached. Two producers can emit some codes, hence deny or allow.
The codes beginning subscriber_ or subscription_ belong to a different way of calling the gateway, in which a person forwards their own model subscription. An agent token never enters it; the only one of them an agent can receive is subscription_mode_disabled, when its model resolves to an endpoint the tenant reserved for that use.
| Code | Status | Class | Ledger | Retry-After |
|---|---|---|---|---|
agent_ambiguous | 403 | policy | deny | — |
agent_credential_required | 403 | policy | deny | — |
agent_enablement_malformed | 403 | policy | deny | — |
agent_enablement_unavailable | 503 | unavailable | deny | — |
agent_not_found | 403 | policy | deny | — |
agent_scoped_key_demoted | 403 | policy | deny | — |
agent_unresolved | 403 | policy | deny | — |
ambiguous_caller_identity | 401 | policy | deny | — |
auth_mode_unknown | 403 | policy | deny | — |
binding_kind_unknown | 403 | policy | deny | — |
binding_unit_corrupt | 403 | policy | deny | — |
binding_unit_unresolved | 403 | policy | deny | — |
binding_withheld | 403 | policy | deny | — |
budget_exceeded_agent | 402 | quota | deny | — |
budget_exceeded_member | 402 | quota | deny | — |
budget_exceeded_org | 402 | quota | deny | — |
budget_exceeded_team | 402 | quota | deny | — |
budget_unavailable | 503 | unavailable | deny | — |
capability_unconfigured | 403 | policy | deny | — |
clearance_unavailable | 503 | unavailable | deny | — |
content_filter | 400 | request | deny | — |
credential_missing | 403 | policy | deny | — |
credential_store_unbound | 503 | unavailable | deny | — |
dialect_ambiguous | 400 | request | deny | — |
dialect_mismatch | 400 | request | deny | — |
egress_destination_refused | 403 | policy | allow | — |
endpoint_disabled | 403 | policy | deny | — |
endpoint_not_enabled_for_agent | 403 | policy | deny | — |
endpoint_pending_approval | 403 | policy | deny | — |
endpoint_unmetered | 403 | policy | deny | — |
governance_backend_unavailable | 503 | unavailable | deny | — |
guardrail_input_unreadable | 400 | request | deny | — |
insufficient_clearance | 403 | policy | deny | — |
invalid_request | 400 | request | deny or allow | — |
model_allowlist_unavailable | 503 | unavailable | deny | — |
model_not_enabled_for_agent | 403 | policy | deny | — |
model_not_in_team_allowlist | 403 | policy | deny | — |
model_not_served_by_endpoint | 403 | policy | deny | — |
model_required | 400 | request | deny | — |
no_approved_binding | 403 | policy | deny | — |
no_matching_endpoint | 404 | request | deny | — |
rate_limit_unavailable | 503 | unavailable | deny | — |
rate_limited_agent | 429 | quota | deny | required |
rate_limited_member | 429 | quota | deny | required |
rate_limited_org | 429 | quota | deny | required |
rate_limited_team | 429 | quota | deny | required |
refusal_uncontracted | 503 | unavailable | deny | — |
request_body_too_large | 413 | request | deny or allow | — |
route_unresolved | 502 | unavailable | unassessed | — |
service_agent_budget_required | 403 | policy | deny | — |
service_governance_unavailable | 503 | unavailable | deny | — |
service_policy_required | 403 | policy | deny | — |
streaming_unsupported | 500 | (no class — declared omission) | allow | — |
subscriber_account_mismatch | 403 | policy | deny | — |
subscriber_account_unreadable | 400 | request | deny | — |
subscriber_consent_required | 403 | policy | deny | — |
subscriber_identity_expired | 401 | policy | deny | — |
subscriber_revoked | 403 | policy | deny | — |
subscriber_suspended | 403 | policy | deny | — |
subscriber_team_not_granted | 403 | policy | deny | — |
subscription_mode_disabled | 403 | policy | deny | — |
subscription_shape_invalid | 401 | policy | deny | — |
surface_not_allowed | 404 | request | deny | — |
translate_opt_in_malformed | 400 | request | deny | — |
translation_not_permitted | 403 | policy | deny | — |
translation_unavailable | 501 | (no class — declared omission) | allow | — |
unauthenticated | 401 | policy | deny | — |
unsupported_dialect | 501 | (no class — declared omission) | deny or allow | — |
upstream_unavailable | 502 | unavailable | allow | — |
6.5 The gate chain: which step refused, and who fixes it
The gateway checks a call in this order and stops at the first refusal, so the code you receive names the first problem, not necessarily the only one.
| Step | Refused because | The codes you will see | Where you fix it |
|---|---|---|---|
| 3 identity | No caller could be resolved from your token | unauthenticated | Get a new token (section 4) |
| 4 rate limit | Your tenant, team or agent is over its request rate. Checked before your body is read. | rate_limited_{org,team,agent}, rate_limit_unavailable | Wait for Retry-After |
| 5 request, routing, binding | No body, no JSON or no model; no approved endpoint serves the model; the endpoint is not bound to your team, its binding is pending or withheld | model_required, invalid_request, request_body_too_large, no_matching_endpoint, endpoint_disabled, endpoint_pending_approval, no_approved_binding, binding_withheld, binding_unit_unresolved, binding_kind_unknown | Your request, or the tenant's endpoint and binding (section 3.1) |
| 6 mode | Your request names two dialects, or the other dialect without translation, or opts into translation the binding does not allow | dialect_ambiguous, dialect_mismatch, translation_not_permitted, translate_opt_in_malformed | Your request (5.3, 5.7), or the tenant's binding |
| 6 metering | The endpoint's last call reported no token usage, while a budget is in force | endpoint_unmetered | Ask for usage in streams (5.5); the tenant |
| 7a clearance | Your agent's clearance is below what the endpoint or binding requires | insufficient_clearance, agent_not_found, clearance_unavailable | The tenant: your agent's clearance |
| 7b agent's models | The models enabled for your agent do not include this endpoint or model | endpoint_not_enabled_for_agent, model_not_enabled_for_agent, agent_unresolved, agent_ambiguous, agent_enablement_malformed, agent_enablement_unavailable | The tenant: your agent's model access |
| 7c team's models | The model is not on the team's list for that endpoint, or the endpoint does not serve it | model_not_in_team_allowlist, model_not_served_by_endpoint, binding_unit_corrupt, model_allowlist_unavailable | The tenant: the binding's models |
| 7d budget | A token budget is exhausted at organisation, team or agent level | budget_exceeded_{org,team,agent}, budget_unavailable | The tenant: the budget, or wait for the next period |
| 7e guardrail | An input guardrail refused the content, or could not read the body | content_filter, guardrail_input_unreadable | Your prompt |
| 8 credential | No provider key is stored where this binding needs one, or the key store could not be read | credential_missing, agent_credential_required, credential_store_unbound, unsupported_dialect | The tenant: the endpoint's provider key |
Rate limits behind the edge. Per second, sustained (burst in brackets): the tenant 200 (400), your team 100 (200), your agent 20 (40). Every call counts against all three. In practice the edge's 120 requests per minute, shared by every caller, is reached first.
Budgets. Budgets are monthly token caps that reset with the tenant's billing period. All token classes count, cache reads and writes included. The tightest of the organisation, team and agent caps decides, and the refusal code names the level that has no headroom left. The check runs before each call: a call already running when the cap is reached completes, and the next one is refused with 402. When some calls in the period could not be metered, the message says AT LEAST n of m tokens used and counts those calls, because the true figure is higher.
6.6 Errors from the provider
Once the gateway has forwarded your call, the provider's answer is yours, unchanged. OpenAI-compatible providers also put a code inside error, so do not assume every error.code is UpsQuad's: a code that is not in the table in 6.4 came from the provider. A provider's 429 carries the provider's own headers. The gateway does not retry a provider error.
6.7 What to retry
| You received | Retry? |
|---|---|
401 invalid_token | Once, with a fresh token |
| 429 from the gateway or the edge | After Retry-After |
502, 503 (class: unavailable) | Yes, with exponential backoff |
| 402, 403, 400, 404, 413 | No. Change the request or ask the tenant. |
500, 501 (no class) | No. Report it to your UpsQuad contact with the X-Upsquad-Usage-Event-Id. |
7. Where spend and usage show up
- Every call that passes authentication writes one usage record for the tenant (the one exception: a rate-limit refusal can go unrecorded while the gateway is shedding load). Refusals and failures are included, attributed to the tenant, your agent's team, your agent, the model and the endpoint, and marked as coming from an agent that runs outside UpsQuad. Its id is the
X-Upsquad-Usage-Event-Idof the response. - The tenant sees it, you do not. The tenant's members with access to usage see spend by organisation, team, agent and model in the UpsQuad portal, can export it as CSV, and see budget burn-down. There is no usage API for an agent token. Ask your tenant contact for figures, and quote the usage-event ids of the calls you mean.
- Tokens, not money, are the unit that is enforced. Cost is computed from the tenant's rate cards. A call whose cost is unknown, for example an unmetered stream (section 5.5), is shown in its own unknown bucket and is never counted as zero.
- Refusals are recorded too. A governance denial (ledger
denyin 6.4) is also written to the tenant's tamper-evident audit log. Token requests to the issuer are audited as well, granted or denied, with the true reason for a denial.
8. Worked examples
The examples keep your credential in shell variables or files. No real token or secret is shown, and ids are shortened with ….
8.1 Discover, then get a token with a client secret
curl -s https://auth-beta.upsquad.ai/.well-known/oauth-authorization-server
{"issuer":"https://auth-beta.upsquad.ai","jwks_uri":"https://auth-beta.upsquad.ai/.well-known/jwks.json","token_endpoint":"https://auth-beta.upsquad.ai/oauth/token","grant_types_supported":["client_credentials"],"response_types_supported":["token"],"token_endpoint_auth_methods_supported":["private_key_jwt","client_secret_post"]}
export UPSQUAD_CLIENT_ID=ext_…
read -rs UPSQUAD_CLIENT_SECRET && export UPSQUAD_CLIENT_SECRET # keep it out of shell history
TOKEN=$(curl -s -X POST https://auth-beta.upsquad.ai/oauth/token \
-d grant_type=client_credentials \
-d client_id="$UPSQUAD_CLIENT_ID" \
--data-urlencode client_secret="$UPSQUAD_CLIENT_SECRET" \
-d resource=https://auth-beta.upsquad.ai/llm \
| python3 -c 'import json,sys; print(json.load(sys.stdin)["access_token"])')
8.2 Get a token with your own key (private_key_jwt)
Python, with the public PyJWT and cryptography packages:
import time, uuid, jwt, requests # pip install pyjwt cryptography requests
CLIENT_ID = "ext_…"
TOKEN_URL = "https://auth-beta.upsquad.ai/oauth/token"
private_key = open("agent-private-key.pem").read() # the tenant holds only the public JWK
now = int(time.time())
assertion = jwt.encode(
{"iss": CLIENT_ID, "sub": CLIENT_ID, "aud": TOKEN_URL,
"iat": now, "exp": now + 120, "jti": str(uuid.uuid4())},
private_key, algorithm="RS256")
resp = requests.post(TOKEN_URL, data={
"grant_type": "client_credentials",
"client_assertion_type": "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
"client_assertion": assertion,
"resource": "https://auth-beta.upsquad.ai/llm",
}, timeout=10)
resp.raise_for_status()
token = resp.json()["access_token"]
A new jti for every request: an assertion is accepted once.
8.3 A call to an OpenAI-compatible endpoint
curl -s -D - https://model-gw-beta.upsquad.ai/v1/chat/completions \
-H "Authorization: Bearer $TOKEN" \
-H 'Content-Type: application/json' \
-d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"Say hello."}]}'
HTTP/2 200
content-type: application/json
x-upsquad-usage-event-id: 3b0c1f9e-…
{"id":"chatcmpl-…","object":"chat.completion","model":"gpt-4o-mini","choices":[{"index":0,"message":{"role":"assistant","content":"Hello."},"finish_reason":"stop"}],"usage":{"prompt_tokens":11,"completion_tokens":2,"total_tokens":13}}
The model id is an example: use one your team may use. The response body is the provider's.
8.4 A streamed call, metered
curl -sN https://model-gw-beta.upsquad.ai/v1/chat/completions \
-H "Authorization: Bearer $TOKEN" \
-H 'Content-Type: application/json' \
-d '{"model":"gpt-4o-mini","stream":true,"stream_options":{"include_usage":true},
"messages":[{"role":"user","content":"Count to three."}]}'
The last event before data: [DONE] carries usage. That is what lets the tenant's budget count this call exactly.
8.5 A call to an Anthropic endpoint
curl -s https://model-gw-beta.upsquad.ai/v1/messages \
-H "Authorization: Bearer $TOKEN" \
-H 'Content-Type: application/json' \
-H 'anthropic-version: 2023-06-01' \
-d '{"model":"claude-sonnet-4-20250514","max_tokens":256,
"system":"You are terse.","messages":[{"role":"user","content":"Say hello."}]}'
The token goes in Authorization: Bearer, not in x-api-key. The gateway puts the tenant's Anthropic key into x-api-key on the way out.
8.6 SDK configuration
from openai import OpenAI
client = OpenAI(base_url="https://model-gw-beta.upsquad.ai/v1", api_key=token) # sent as Authorization: Bearer
from anthropic import Anthropic
client = Anthropic(base_url="https://model-gw-beta.upsquad.ai", auth_token=token) # NOT api_key=
The Anthropic SDK sends api_key as x-api-key, which the gateway does not read: you would receive 401 invalid_api_key "missing or malformed Authorization header". auth_token sends Authorization: Bearer. Both SDKs need a new client, or a refreshed token, when the token expires.
8.7 A refusal
A call over the team's budget:
HTTP/2 402
content-type: application/json
x-upsquad-usage-event-id: 9d41…
{"error":{"code":"budget_exceeded_team","message":"the team token budget for the billing period beginning 2026-11-01 is exhausted (1000412 of 1000000 tokens used). Caps compose as the most restrictive across org, team and agent, and the team grain is the one with no headroom left — raising any other grain will not admit this call. The call in flight when the cap was reached was completed; this one is refused.","gate":"7d/budget","class":"quota","fleet":"agent"}}
A call with a token granted without resource:
HTTP/2 401
content-type: application/json
{"error":{"message":"this token was not issued for the Model Gateway","type":"invalid_token"}}
9. Verification checklist
9.1 Before you go further: your side
- Discovery.
curl https://auth-beta.upsquad.ai/.well-known/oauth-authorization-serverreturnsissuerhttps://auth-beta.upsquad.aiand lists your authentication method. - A token. Your grant (8.1 or 8.2) returns HTTP 200 with
access_tokenandexpires_in: 600. A401 invalid_clientmeans the credential, or the tenant's enablement, is wrong: stop and check with your tenant contact rather than retrying (section 4.6). - The right resource. A grant with
resource=https://model-gw-beta.upsquad.ai/llmreturns400 invalid_target, and yours does not. That proves you send the issuer-derived value. - No header.
curl -X POST https://model-gw-beta.upsquad.ai/v1/chat/completions -d '{}'returns401with"type":"invalid_api_key". That proves you reach the gateway. - A governed call. Example 8.3 (or 8.5, for an Anthropic endpoint) with a model your team may use returns
200and anx-upsquad-usage-event-idheader. - Streaming, if you stream: example 8.4 ends with a
usageevent. - Expiry. Your agent requests a new token before
exp, and requests at most one token per few minutes, not one per call. - Errors. Your client keys on
error.codeanderror.type, retries only as in 6.7, and logsX-Upsquad-Usage-Event-Id.
9.2 The UpsQuad side (the tenant's administrator)
- The provider endpoint is registered with the right dialect and approved, and its provider key is stored.
- The endpoint is bound to your agent's team, the binding is approved by the team's manager, and it lists the models you will call.
- Your agent is registered as an external agent of that team, with a clearance that meets the endpoint's and binding's requirement, and the models you will call are enabled for it.
- The tenant is enabled for external agents.
- Budgets are set, or deliberately not set, at organisation, team and agent level.
- The usage record for your call in 9.1 step 5 is visible in the tenant's usage views, attributed to your agent, and found by its usage-event id.
- Negative check: the tenant temporarily disables one of your agent's models; your next call to it is refused with
403 model_not_enabled_for_agent, without waiting for a new token.