Errors
Every failure is one error type with a code. Branch on the code; the message is for your log.
typescript
import { TigerbaseServerError } from "@tigerbase/server";
try {
const agents = await tigerbase.agents();
} catch (error) {
if (error instanceof TigerbaseServerError) {
switch (error.code) {
case "invalid_key":
// Wrong, revoked or expired. Nothing to retry.
break;
case "forbidden_scope":
// The key is fine; it was not granted this scope.
break;
case "rate_limited":
await sleep((error.retryAfterSeconds ?? 5) * 1000);
break;
case "monthly_limit":
// error.limit = { kind: "monthly", limit, used, resetsAt }
break;
case "plan_limit":
// error.serverCode = "PLAN_AGENT_LIMIT", error.params = { max: 3 }
break;
default:
logger.error(error.message, { status: error.status });
}
}
}NoteNever match on the message
The sentence is written for a human reading a log and will be improved without warning. The code is the contract — and it is also narrower than the HTTP status, which is the point.
The codes
| Code | HTTP | Meaning | Retry? |
|---|---|---|---|
| invalid_key | 401 | Wrong, revoked or expired — or missing when you constructed the client. Check the environment variable first: a trailing newline in a .env file is the usual cause. | No |
| forbidden_scope | 403 | The key is valid and was not granted the scope this route needs. Edit the key's scopes, or mint one with them. | No |
| forbidden_field | 403 | The key has the scope and the field is refused — updateAgent will not write a credential. Editing scopes changes nothing; the fix is the dashboard. The message names the fields. | No |
| bad_request | 400 | Something in the request itself: a date that cannot be read, a range that ends before it starts, a field the route does not accept, the wrong name on a delete, a reply to a resolved handoff. | No |
| not_found | 404 | No such agent, conversation or handoff — or it belongs to another App. These are deliberately indistinguishable. | No |
| rate_limited | 429 | Too many requests this minute. Carries retryAfterSeconds. | Yes, after retryAfterSeconds |
| monthly_limit | 429 | The account's allowance for this billing period is spent. error.limit has used and limit; usage() has the reset date. | No — not until the period rolls over |
| too_many_conversations | 429 | The plan's ceiling on simultaneous conversations. A slot frees when one ends. | Yes, shortly, with a backoff |
| agent_inactive | 403 | The agent is switched off. updateAgent(publicId, { isActive: true }) switches it on. | No |
| plan_limit | 403 | The plan does not include this, or its limit is reached. error.serverCode says which (PLAN_AGENT_LIMIT, PLAN_DOCUMENT_LIMIT…), error.params has the numbers. | No — a plan change |
| subscription_inactive | 403 | The App's plan is not active, or has expired. | No |
| unknown | any other | Anything else. Read status: 502 when the agent could not answer, 5xx for us, 403 when a route declared no scope (our bug). | 502 and 5xx: once, with backoff. 403: no |
| network | — | It never reached us. DNS, a dropped connection, a firewall. | Yes, with backoff |
| aborted | — | You cancelled it with a signal. Not a failure, and should not be reported as one. | No — it was yours |
| secret_key_in_browser | — | Thrown when you construct the client, before any request. Your import has reached code that ships to a browser. | No — move the import |
What an error body looks like
If you call the HTTP API directly, every refusal is JSON with statusCode, error and message. Some carry more: fields on a refused update, impact on a refused delete, limit on a 429, and a stable code (with params) on a switched-off agent, an inactive plan or a plan limit. The SDK keeps them on the error as limit, serverCode and params.
401 Unauthorized
{
"statusCode": 401,
"message": "That API key is not valid, has been revoked, or has expired.",
"error": "Unauthorized"
}The kinds of 403
The API returns 403 for different situations, and they need different actions.
| forbidden_scope | Your key lacks the scope this route needs. Edit the key, or mint one with it. |
|---|---|
| forbidden_field | The key is fine; the field is refused. No scope will ever grant it — change it in the dashboard. |
| agent_inactive, plan_limit, subscription_inactive | Not about the key at all: the agent is switched off, the plan stops it, or the plan is not active. The server says which with a code. |
| unknown, on a 403 | The route declared no required scope — which is our bug. Editing the key will not help. |
WarningWhy this distinction is in the SDK at all
Two of those messages contain the word “scope”. An earlier version of this package matched on that and reported our bug as your mistake — which would have sent somebody to edit a key that was already correct. The check that caught it runs before every release, and gained a case for each 403 as it appeared.
Retrying
Retry these
| rate_limited | Wait retryAfterSeconds and try again. The SDK falls back to 5 seconds when the server did not say. |
|---|---|
| network | Retry with a backoff. It may be transient. |
| unknown with status 502 or 5xx | Once or twice, with a backoff. A 502 from ask() means the model call failed this time. |
Never retry these
| invalid_key, forbidden_scope, forbidden_field, not_found, bad_request, monthly_limit, agent_inactive, plan_limit, subscription_inactive | These fail identically every time, and a retry loop on them is a loop. |
|---|---|
| aborted | Do nothing. It was your own cancellation. |
TipA spent monthly allowance is its own code
The monthly limit and the per-minute rate both answer 429; the server says which in
limit.kind, and the SDK reports a spent allowance as monthly_limit, never as rate_limited. Waiting will not bring it back: stop until period.resetsAt from usage().