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.

What you catch
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 customers

Every code

CodeWhat happenedHTTPRetry?
rate_limitedToo 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.429Yes, after retryAfterSeconds.
too_many_conversationsThe plan's ceiling on simultaneous conversations. A slot frees the moment any conversation finishes.429Yes, shortly, with a backoff.
monthly_limitThe account's allowance for its billing period is spent.429No — not until the term rolls over.
invalid_keyThe key is wrong, or was regenerated.401No — a setting has to change.
agent_inactiveThe agent is switched off in the dashboard.403No — until someone switches it on.
unavailableNot 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, streamNo — the owner has something to do.
busyThe server hit a limit mid-answer (AGENT_BUSY).streamYes, later.
forbidden_originThe page's domain is not on the agent's allowed list — or the list is empty, or the request carried no Origin at all.403No — a setting has to change.
secret_key_in_browserA tb_live_ key was given to the browser package. Thrown by the constructor.noneNo — fix the code.
confirmation_expiredFrom confirm() only: that confirmation was already answered, or is older than ten minutes. The tool did not run.404No — ask the agent again for a new one.
abortedYou cancelled it with an AbortSignal. Not a failure.noneNothing to retry — ignore it.
networkThe request never got a response — offline, DNS, a dropped connection, including one that dropped mid-answer.noneYes, a few times with a backoff.
unknownAnything 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.otherOnce, 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.

Two codes clear on their own, one is yours to ignore, and the rest will fail the same way until somebody changes something.

Minimal

ts
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.

lib/chat-errors.ts
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

lib/with-retry.ts
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

If the connection drops after the answer started, the turn ran and was counted. Retrying automatically sends the question again — a second answer, a second message against the limit. Retry 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.

Streaming
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

It is written for whoever reads your logs and will be improved without warning. Your copy, keyed on the code, is the interface.