One endpoint,
every model.
Tare is an OpenAI-compatible gateway in front of every model you use — ours and the ones you bring yourself. One base URL, one key, and every token accounted for.
Errors
What this solves: When a call fails, how to locate the cause in a fixed order; and how to explain a failure to an end user without misleading them.
When a call fails, locate the cause in the order below. When you need to relay the cause to an end user, use the same set of judgments.
What you need to know first: The error body has the OpenAI shape ({"error": {"message": …, "type": …}}), and that is the shape SDKs read. With any other shape, your client logs degrade to an undefined line.
Triage order: status code first, then code / type, then refusal_reason
Don't look at the HTTP status code alone. The same 403 can come from key type, quota, source IP, DLP, budget, and other reasons, so you have to look two levels deeper.
| Order | Which cell to look at | What it answers |
|---|---|---|
| 1 | HTTP status code | Which broad category the failure belongs to (credential / permission / not found / rate limit / upstream / platform) |
| 2 | error.code / error.type | code is always identical to the status code, so branching on it is safe; type (same value as metadata.error_type) is always present, and it separates the different reasons behind the same status code, such as the two kinds of 503 |
| 3 | metadata.refusal_reason | Within "refusal-class" errors, pin down exactly which kind of refusal it is (quota, budget, arrears, IP) |
If you finish these three steps and still aren't sure, then check Call Traces, the audit log, and Model Health (see Routing).
What to judge first by status code
| Status | What to judge first |
|---|---|
| 400 | Request shape, DLP, whether the provider filter emptied out the candidates |
| 401 | Whether the key exists, is expired, or is disabled |
| 402 | Whether the account balance is insufficient |
| 403 | Key type, quota, budget, source IP, DLP |
| 404 | Whether the model route exists, or whether the generation has not been written yet |
| 429 | Rate limit; handle it per Retry-After |
| 503 | Whether all upstream candidates are unavailable |
Status code meanings and handling
| Status code | Meaning | How to handle |
|---|---|---|
| 401 | Key missing, malformed, or revoked | Check the header. 401 is only about the credential itself |
| 403 | The credential is valid, but this call isn't allowed through | Key type doesn't match the endpoint, quota is used up, or the source IP isn't on this key's allowlist; check metadata.refusal_reason |
| 404 | No route is configured for this model | Change the model name, add a route, or add a catch-all |
| 402 | Account arrears (the only meaning) | Top up; recovery is automatic |
| 429 | Requests per minute exceeded | Back off per Retry-After, see Rate limits and quotas |
| 502 | Tare couldn't get a usable response from the upstream provider (including problems with Tare's own credential at that provider, which aren't your concern) | Retry; if it keeps happening, look into this channel |
| 503 | The same status code has two different causes behind it, and the status code alone can't tell them apart — look at error.type. provider_overloaded: the route is configured, but all its channels are currently failing. provider_unavailable: Tare's billing service is currently unreachable, unrelated to the model | Retry with backoff for both; the first is a route-configuration problem, the second is unrelated to your model and routes |
| 504 | The upstream didn't respond within the timeout | Retry; a consistently slow channel should have its timeout shortened or a backup route added |
| 500 | A service failure on Tare's side | Retry; include the request ID when you contact support |
Distinguishing the three kinds of "insufficient balance"
An exhausted quota returns 403; don't confuse it with 402. 402 only means account arrears. The division of labor between the two codes is about "whose problem this is": 402 is money the account owes the platform, while 403 is stopped by a governance threshold (key quota, monthly budget).
The table below is the only authoritative statement:
| Case | HTTP | error.type / metadata.error_type | metadata.refusal_reason |
|---|---|---|---|
| This key's cumulative quota is used up | 403 | token_limit_exceeded | key_credit_exhausted |
| The account's monthly budget is maxed out | 403 | token_limit_exceeded | budget_exhausted |
| Account arrears | 402 | payment_required | account_balance_insufficient |
| The call source isn't on this key's IP allowlist | 403 | permission_denied | source_ip_not_allowed |
What to say when relaying to an end user
When a platform-type customer needs to relay the cause to an end user, look at refusal_reason; don't read the copy verbatim:
refusal_reason | Meaning | What to tell the end user |
|---|---|---|
key_credit_exhausted | This key's cumulative quota is used up | "Your quota is used up"; topping up fixes it |
budget_exhausted | The account's monthly budget is maxed out | Not their concern; don't steer them to top up |
account_balance_insufficient | Account arrears | Not their concern; don't steer them to top up |
source_ip_not_allowed | The source address isn't on this key's list | Nothing to do with money: retry from a machine that is on the list, or ask the key's holder to add this machine to the list |
If you describe the middle two as "your quota is used up", the user will pay for something that isn't their concern; if you describe the last one as a quota problem, they'll go top up an account that isn't short of money at all.
{"error":{"code":403,"type":"token_limit_exceeded","message":"...","metadata":{
"error_type":"token_limit_exceeded",
"refusal_reason":"key_credit_exhausted"}}}
The two response envelopes
Different endpoints return different envelopes, so when you integrate, first recognize which kind you're hitting:
| Endpoint | Success | Failure |
|---|---|---|
/v1/chat/completions, /v1/embeddings, /v1/images, /v1/videos/generations*, /v1/keys/*, /v1/models, /v1/generation | OpenAI shape | HTTP non-2xx + {"error":{…}} |
/v1/integration/*, /v1/content-settings*, /v1/alerts/*, /v1/mocks/* | {"code","message","data","success"} | HTTP non-2xx, and the body is still this envelope (not 200 + success:false) |
When you reach the reconciliation endpoints through the api.jamerly.dev gateway, the gateway doesn't unwrap the upstream envelope, so the business data is nested two levels deep (data.data); a direct connection to tare.jamerly.ai has only one level. The test is whether a code/success is nested inside data again, regardless of deployment location. This holds under both deployments.
The shape of the error body
{"error":{
"code": 403,
"type": "token_limit_exceeded",
"message": "...",
"metadata": {
"error_type": "token_limit_exceeded",
"refusal_reason": "key_credit_exhausted",
"provider_code": "503",
"provider_raw": "{\"error\":{\"code\":\"model_not_found\",\"message\":\"...\"}}"
}}}
| Field | Guarantee |
|---|---|
error.code | Always equals the HTTP status code; branching on it is safe |
error.type | Always present; the OpenAI SDK reads this cell |
metadata.error_type | Same value as error.type; some SDKs read only this cell |
metadata.refusal_reason | Present only for the three kinds of refusal above |
metadata.provider_code | The upstream's raw status code, forwarded as-is, may be missing |
metadata.provider_raw | Not guaranteed. On a BYOK channel (your own provider key) it may carry the upstream's raw response; on platform and Token Market channels it is not included |
error.message is generated by Tare: it states which class of failure this is.
When the failure stems from this request itself (a malformed tool schema, an out-of-range parameter), message is the upstream's one-line explanation, taken from error.message in the upstream's error body; the body's other fields are not returned.
The top-level type and metadata.error_type are the same value, deliberately duplicated: the two ecosystems don't read the same cell.
If you only provide the latter, a client written against the OpenAI SDK gets undefined, without an error — it just displays a clear refusal as an "unknown error".
The values of error_type stay unchanged; the finer breakdown is added on refusal_reason.
Distinguishing 404 from 503
"No route configured" is fixed by changing the config; "all upstreams failed" is fixed by waiting. Merging them into one status code would point people in the wrong direction, which is why the catch-all route only covers the 404 side and not the 503 side.
Here we use 404 rather than 402: 402 means "you can continue after paying", whereas this error won't get better no matter how much you pay. Otherwise you'd top up first, then check the balance, and only at the end find out the model name was misspelled.
There's another easy-to-confuse pair of 404 and 503, on endpoints like embeddings (for details see the Endpoint list):
- 503: All candidate channels are in the circuit-breaker state. It means "not right now", and the fix is to wait a bit and retry. This is recorded as an incident of type
UPSTREAM_ALL_DOWN, visible on the model's health timeline. - 404: This model has no pricing on platform channels. It means "a configuration problem", and the fix is to switch to your own channel, or contact us to price this model. On platform channels, tokens are bought from upstream by the platform, and when the price list is missing this row the pricing computes to 0. Better to fail clearly than to serve silently for free.
Both are reported the same way as other endpoints: UPSTREAM_ALL_DOWN is a distinct incident type.
model_not_found is an upstream error code, meaning the upstream doesn't have this model. It's not the same thing as the 404 for "Tare has no route configured for this model".
Has a route but the modality doesn't match
Returns 404, but with a different message: the configured upstream doesn't accept images (or audio, or video). The fix is to tick that input in the model's Capabilities on the Routing page, or switch to a model that supports that input.
A successful call with no text
If a reasoning model returns no text, the output limit (max_tokens) was likely used up by reasoning before it started answering. Raise max_tokens.
Next steps
- To test one error branch over and over: read Drills (Mock).
- To understand how the "source IP allowlist" in 403 is configured: read API Key.
- To understand how to tune the rate-limit tier: read Rate limits and quotas.