Errors
Codes, not sentences — and the code tells you whether to wait or to stop.
Every failure is a TigerbaseError with a code. Comparing message text breaks the moment the wording improves — and it makes an interface in another language a translation of our copy instead of your own.
import { TigerbaseError } from "@tigerbase/client";
err instanceof TigerbaseError; // true for everything the SDK throws
err.code; // "rate_limited" | "monthly_limit" | … — branch on this
err.retryAfterSeconds; // number, on rate_limited only
err.limit; // the server's { kind, limit, used, … } on any 429
err.serverCode; // "AGENT_INACTIVE", "AGENT_UNAVAILABLE"… when the server sent one
err.status; // the HTTP status, when there was one — for logs
err.message; // a sentence for your logs, not your customersEvery code
| Code | What happened | HTTP | Retry? |
|---|---|---|---|
rate_limited | Too many messages in the last minute — for the account, or from this one visitor (20 a minute) or network address (60 a minute) on this agent. retryAfterSeconds is the server’s own measurement from a rolling window — 5 if the server did not say, which is the case for the per-visitor limit. | 429 | Yes, after retryAfterSeconds. |
too_many_conversations | The plan's ceiling on simultaneous conversations. A slot frees the moment any conversation finishes. | 429 | Yes, shortly, with a backoff. |
monthly_limit | The account's allowance for its billing period is spent. | 429 | No — not until the term rolls over. |
invalid_key | The key is wrong, or was regenerated. | 401 | No — a setting has to change. |
agent_inactive | The agent is switched off in the dashboard. | 403 | No — until someone switches it on. |
unavailable | Not the visitor’s doing and not yours to fix in code: the App’s plan is not active, or the server said AGENT_UNAVAILABLE mid-answer (no AI key, say). The owner is told the reason. | 403, stream | No — the owner has something to do. |
busy | The server hit a limit mid-answer (AGENT_BUSY). | stream | Yes, later. |
forbidden_origin | The page's domain is not on the agent's allowed list — or the list is empty, or the request carried no Origin at all. | 403 | No — a setting has to change. |
secret_key_in_browser | A tb_live_ key was given to the browser package. Thrown by the constructor. | none | No — fix the code. |
confirmation_expired | From confirm() only: that confirmation was already answered, or is older than ten minutes. The tool did not run. | 404 | No — ask the agent again for a new one. |
aborted | You cancelled it with an AbortSignal. Not a failure. | none | Nothing to retry — ignore it. |
network | The request never got a response — offline, DNS, a dropped connection, including one that dropped mid-answer. | none | Yes, a few times with a backoff. |
unknown | Anything else: a 400 or 5xx, any other error the server reported mid-answer, or a missing socket.io-client (delivered as an error event, not thrown). status says which, when there was one. | other | Once, by hand. Log it. |
NoteHow the SDK knows it was the domain
The server’s domain refusal is written for the visitor — “This assistant is not available right now.” — and carries a separate reason: no_domains_configured, domain_not_allowed or no_origin. The SDK reads that field, not the sentence, and turns it into forbidden_origin.
The reason never names the host that was turned away. That goes to the account owner, who is notified separately; the page it was refused on learns nothing about how the account is set up.
Wait, or stop
Most interfaces need exactly four reactions. The code picks one.
Minimal
try {
await chat.askOnce(question);
} catch (err) {
if (err.code !== "aborted") show("Something went wrong.");
}Realistic
Harbor & Pine show a countdown for a rate limit, an honest “unavailable” for the permanent ones, and never the server’s sentence.
import { TigerbaseError } from "@tigerbase/client";
export function sentenceFor(err: unknown): string | null {
if (!(err instanceof TigerbaseError)) return "Something went wrong.";
switch (err.code) {
case "aborted":
return null; // you cancelled it
case "rate_limited":
return `Lots of questions right now — try again in ${err.retryAfterSeconds}s.`;
case "too_many_conversations":
case "busy":
return "We are busy right now. Try again in a moment.";
case "network":
return "You seem to be offline.";
case "confirmation_expired":
return "This request expired. Ask again.";
case "monthly_limit":
case "invalid_key":
case "agent_inactive":
case "unavailable":
case "forbidden_origin":
case "secret_key_in_browser":
// The detail is for the account owner, who is told another way.
console.error(err.code, err.status, err.message);
return "The assistant is not available right now.";
default:
console.error(err.code, err.status, err.message);
return "Something went wrong.";
}
}Retrying, with a ceiling
import { TigerbaseError } from "@tigerbase/client";
const RETRYABLE = new Set(["rate_limited", "too_many_conversations", "network"]);
export async function withRetry<T>(run: () => Promise<T>, attempts = 3): Promise<T> {
for (let i = 1; ; i++) {
try {
return await run();
} catch (err) {
if (!(err instanceof TigerbaseError) || !RETRYABLE.has(err.code) || i >= attempts) {
throw err;
}
const wait = err.code === "rate_limited"
? (err.retryAfterSeconds ?? 5) * 1000 // the server's number, not a guess
: 500 * 2 ** i; // 1s, 2s, 4s…
await new Promise((r) => setTimeout(r, wait));
}
}
}
// const answer = await withRetry(() => chat.askOnce("Is the oak table in stock?"));CarefulA network error mid-answer already cost a message
askOnce() automatically if you like; for a streamed ask() that already showed text, offer a button instead.Errors inside a stream
A refusal comes back before the stream opens. A failure after it has started comes back as an error frame. Either way ask() throws from the loop — so one try covers both, and you cannot forget to check a field.
try {
for await (const ev of chat.ask(question, { signal })) {
if (ev.text) append(ev.text);
}
} catch (err) {
const sentence = sentenceFor(err);
if (sentence) show(sentence);
}NoteA limit is not an error in the agent
Nothing is lost when one is hit. The limits are checked before the stream opens, so the message was not answered and can be sent again — the right interface is a line of text and a retry, not a red failure state.
The account also sees it in their dashboard, once an hour rather than once per blocked message, so you do not need to tell them.
TipNever render err.message to a customer