Setup

The right kind of key, and an id that makes the agent remember who it was talking to.

  1. 1

    Add the dependency

    pubspec.yaml — once it is published
    dependencies:
      tigerbase: ^0.1.0
  2. 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. 3

    Create the client once

    lib/tigerbase.dart
    import '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. 4

    Give each person a stable id

    dart
    final chat = tigerbase.conversation(visitorId: await visitorId());

    The section below is about getting this one right.

CarefulNever ship a tb_live_ key in an app

That is a server key and it is the whole account. In a mobile app this matters more than on the web, not less — the binary is on the device and anybody can read the strings out of it. The package refuses one at construction, with TigerbaseErrorCode.secretKey, rather than letting it reach a release.

The options

keyRequired. The publishable key. Empty throws invalidKey; tb_live_ throws secretKey.
apiUrlOptional. Defaults to https://api.tigerbase.cloud. A trailing slash is fine.
clientOptional. 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.
A test, with no network
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 idThe best answer when people sign in. The conversation follows them to a new phone.
A value in shared_preferencesGenerate one once and keep it. Survives relaunches, lost on reinstall, and needs no permissions.
A device identifierdevice_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

lib/visitor_id.dart
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

It travels with every message and ends up in logs on both sides. An opaque id you can map back to a person on your own side does the same job without putting the person in it. Keep it to 64 characters or fewer.

Where it points

dart
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 webThe browser sends Origin. Add your site's domain to the list, exactly as for the web widget.
Android, iOS, desktoppackage:http sends neither header. The hosted API refuses a request with no Origin or Referer.
A local backendOutside production the check is relaxed, which is why this does not show up in development.

WarningTest a release build against the hosted API

A native build that worked against your laptop fails against production with 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.