When a gateway sits in front of thirty upstream sellers, every failed request has two possible authors: the gateway, or the vendor behind it. If your logs do not say which, every incident starts with thirty minutes of guessing.
This is the error taxonomy we use, and the one thing that makes it usable in practice.
Four classes, not one "error"
| Class | Who produced it | What you should do |
|---|---|---|
| Gateway-side 4xx | us: bad model id, malformed body, key issue | fix the request, never retry |
| Upstream-side 4xx | the vendor: quota, content policy, bad parameter for their tier | surface it, do not retry |
| Upstream 5xx / timeout | the vendor, transiently | retry with a bounded budget |
| Gateway 5xx | us: bug or capacity | page someone, do not hide it |
The distinction that matters most is between the two 4xx classes. They look identical — both are 400-family responses with a JSON body — but one is your bug and one is the vendor's rule, and they need different owners.
Preserve the upstream body verbatim
The single most useful habit: when the upstream returns an error, forward its message, type, and code unchanged, plus a gateway-supplied upstream field naming the seller.
Friendly rewriting destroys the one artefact a support engineer can act on. Compare:
{"error": {"message": "Invalid API key", "type": "invalid_request_error"}}
with
{"error": {
"message": "Invalid API key",
"type": "invalid_request_error",
"code": "invalid_api_key",
"upstream": "seller-17",
"request_id": "req_8f3c..."
}}
The second tells you whose key, at whose end, on which request. The first tells you a sentence.
Do not launder 429s
A 429 from an upstream seller is a scheduling fact, not an outage. If the gateway re-labels it as a 500, clients escalate, retry storms start, and the actual fix — slow down for eleven seconds — never gets applied. Keep 429, keep Retry-After if the vendor sent one, and add the upstream name.
Make retries visible
If the gateway retried before giving up, the response must say so ("retries": 1) and the log must name the upstream that failed and the one that eventually answered. Silent failover is a debugging tax paid by everyone downstream.
The rule for when to retry at all: only before the first byte, only on a different upstream when the failure is a vendor-side 4xx/5xx, never on a request the client aborted.
What this buys
Support becomes a lookup: request_id maps to the upstream, the upstream's error code maps to a known cause, and the answer is either "your parameter" or "their quota" — in one step. Without attribution, the same question takes a screenshot, a log search, and a call.
The probe that checks an endpoint's error envelope, along with the other three, is described in the integration docs. Upstream incident history and current per-model behaviour are on the status page.
I maintain LONG AI, a gateway over 109 models across many upstream sellers - which is why error attribution had to become a design rule rather than a logging convention.
Top comments (0)