Setup
The right kind of key, and an id that makes the agent remember who it was talking to.
- 1
Add the dependency
pubspec.yaml — once it is publisheddependencies: tigerbase: ^0.1.0 - 2
Take the publishable key
Dashboard → your agent → Settings → Embed. It starts
tb_. This is the key that is meant to be in a client — it is guarded by the agent's allowed domains, not by being secret. - 3
Create the client once
lib/tigerbase.dartimport 'package:tigerbase/tigerbase.dart'; /// One per app, not one per screen. Each instance holds its own HTTP /// client and its own cached config. final tigerbase = Tigerbase(key: 'tb_your_key_here'); - 4
Give each person a stable id
dartfinal chat = tigerbase.conversation(visitorId: await visitorId());The section below is about getting this one right.
CarefulNever ship a tb_live_ key in an app
TigerbaseErrorCode.secretKey, rather than letting it reach a release.The options
| key | Required. The publishable key. Empty throws invalidKey; tb_live_ throws secretKey. |
|---|---|
| apiUrl | Optional. Defaults to https://api.tigerbase.cloud. A trailing slash is fine. |
| client | Optional. An http.Client to use instead of a fresh one — the seam a test replaces, and the place to add your own logging or timeouts. |
import 'package:http/http.dart' as http;
import 'package:http/testing.dart';
final fake = MockClient((request) async => http.Response(
'{"settings": {"botName": "Pine", "starterQuestions": []}}',
200,
));
final tigerbase = Tigerbase(key: 'tb_test', client: fake);
expect((await tigerbase.config()).botName, 'Pine');The visitor id
This is who the conversation belongs to. Make it stable across launches. A fresh id every time the app starts is a fresh person every time, and the agent will not remember yesterday — which looks fine in testing, because you are testing one session.
Choosing one
| Your own customer id | The best answer when people sign in. The conversation follows them to a new phone. |
|---|---|
| A value in shared_preferences | Generate one once and keep it. Survives relaunches, lost on reinstall, and needs no permissions. |
| A device identifier | device_info_plus. Be careful: on iOS it changes when the app is uninstalled, and some identifiers carry privacy obligations you do not want for a chat id. |
A realistic one
import 'dart:math';
import 'package:shared_preferences/shared_preferences.dart';
/// Harbor & Pine: the signed-in customer's chat id when there is one,
/// otherwise an id made once per install.
Future<String> visitorId({String? customerChatId}) async {
if (customerChatId != null) return 'hp-$customerChatId';
final prefs = await SharedPreferences.getInstance();
final existing = prefs.getString('tigerbase.visitor');
if (existing != null) return existing;
final random = Random.secure();
final made = 'app-${List.generate(16, (_) => random.nextInt(16).toRadixString(16)).join()}';
await prefs.setString('tigerbase.visitor', made);
return made;
}TipDo not use an email or a phone number
Where it points
Tigerbase(
key: 'tb_your_key_here',
apiUrl: 'https://api.tigerbase.cloud', // the default
);Only set apiUrl for a self-hosted install or a local backend. On Android, localhost inside the emulator is the emulator — use 10.0.2.2 for the host machine.
The allowed-domains check
The publishable key is safe to ship because the server checks where a request came from, using its Origin or Referer header, against the agent’s Allowed Domains.
| Flutter web | The browser sends Origin. Add your site's domain to the list, exactly as for the web widget. |
|---|---|
| Android, iOS, desktop | package:http sends neither header. The hosted API refuses a request with no Origin or Referer. |
| A local backend | Outside production the check is relaxed, which is why this does not show up in development. |
WarningTest a release build against the hosted API
invalidKey and status 403 — the domain refusal’s message names no domain, so the package cannot tell it apart from a bad key. Find this out before the store review, not after.Closing it
tigerbase.close() releases the HTTP client. An app with a single long-lived instance never needs it; something that creates one per screen does, and that is a reason to create one per app instead.
NoteA client you passed in is closed too
close() closes whatever http.Client the instance holds, including one you gave it. Do not call it if that client is shared with the rest of your app.