Setup
Install it, create one file, and put the right key in the right place.
- 1
Install
bashnpm i @tigerbase/clientNo dependencies. The one exception is optional: handing a conversation to a person needs a socket, so that feature uses
socket.io-client— install it only if you use it.bash — only for handoffnpm i socket.io-client - 2
Take the publishable key
Dashboard → your agent → Settings → Embed. It is the same key the script tag carries. It starts
tb_and does not starttb_live_. - 3
Create the client once
One file, imported everywhere. A client built inside a component is a new client on every render, and each one re-fetches the configuration the last one already had.
lib/tigerbase.tsimport { Tigerbase } from "@tigerbase/client"; export const tigerbase = new Tigerbase({ // Publishable. It is meant to be in your page source — the agent's // allowed-domains list is what protects it, not secrecy. key: process.env.NEXT_PUBLIC_TIGERBASE_KEY!, }); - 4
Allow your domain
Add the site the chat runs on to the agent’s Allowed Domains. In production a request from a domain that is not on the list — or from an agent with an empty list — is refused, and that includes
localhost: to test on your own machine against production, addlocalhostto the list. Only a development server lets local pages through on their own.
The options
| key | Required. The agent's publishable key. An empty key throws invalid_key; a tb_live_ key throws secret_key_in_browser — both at construction, before any request. |
|---|---|
| apiUrl | Optional. Defaults to https://api.tigerbase.cloud. Set it only for a self-hosted deployment or a local backend. |
There is no option to choose an agent: the key is the agent. An account with three agents has three keys, and a page talks to whichever one it was given.
// The shop's sales assistant on product pages…
export const sales = new Tigerbase({ key: process.env.NEXT_PUBLIC_TB_SALES_KEY! });
// …and the after-sales agent on the order-tracking page.
export const aftercare = new Tigerbase({ key: process.env.NEXT_PUBLIC_TB_AFTERCARE_KEY! });The two keys
| tb_… (publishable) | Goes in the browser. It is meant to be visible — the agent’s allowed-domains list is what protects it. This is what @tigerbase/client takes. |
|---|---|
| tb_live_… (secret) | Acts as the whole account, from anywhere, with no domain check — a server has no domain to check. It belongs in @tigerbase/server, on your own machine, and nowhere a browser can reach. |
CarefulThe client package refuses a secret key
tb_live_ key to @tigerbase/client throws at construction rather than letting it become your problem after deploy. It is three lines and it prevents the single most expensive mistake available here.Next.js
Install both and use each in its own environment. That is the intended shape — but one detail decides whether it is safe.
The browser half
"use client";
import { Tigerbase } from "@tigerbase/client";
const tb = new Tigerbase({ key: process.env.NEXT_PUBLIC_TIGERBASE_KEY! });The server half
import { TigerbaseServer } from "@tigerbase/server";
const tb = new TigerbaseServer({ apiKey: process.env.TIGERBASE_SECRET! });
// ↑ no NEXT_PUBLIC_ prefixNoteTwo packages, two option names
key; the server client takes apiKey. Different on purpose — copying one constructor into the other environment does not compile.CarefulNEXT_PUBLIC_ is the trap
Any variable prefixed NEXT_PUBLIC_ is written into the browser bundle literally. Name a secret key NEXT_PUBLIC_TIGERBASE_SECRET out of habit and your account credential is in your page source.
Next will not warn you. It will work perfectly.
NoteSo the server package refuses to run in a browser
@tigerbase/server checks for window and document when it is constructed and throws secret_key_in_browser if it finds them — at construction, not at the first request, so the mistake surfaces in development rather than in the one code path nobody exercised.Where each one belongs
| The chat itself | A "use client" component. It has to receive an answer as it is written, which a server component cannot do. |
|---|---|
| Reading the account | A Route Handler or a Server Action, with the secret key. Conversations, usage, agent management. |
TipCheck it works before building anything
One call from your running site tells you the key and the domain are right:
await tigerbase.config(); // an object: you are set up
// a TigerbaseError: read its code — see Errors