Skip to Content
Baseera Docs

BaseeraProvider

Every prop of BaseeraProvider, and what it does on mount.

BaseeraProvider creates one Baseera client and one chat controller, and shares them with every hook and component under it. Mount it once, near the root of your app.

app/providers.tsx
"use client";
import { BaseeraProvider } from "@baseera/react";

export function Providers({ children }: { children: React.ReactNode }) {
  return (
    <BaseeraProvider
      publishableKey={process.env.NEXT_PUBLIC_BASEERA_KEY!}
      baseUrl={process.env.NEXT_PUBLIC_BASEERA_URL!}
      getUserToken={() => fetch("/api/baseera-token", { method: "POST" }).then((r) => r.json()).then((b) => b.token)}
      theme="system"
      onError={(error) => console.warn("Baseera error", error.code)}
    >
      {children}
    </BaseeraProvider>
  );
}

Props

Prop

Type

BaseeraErrorEvent is { code: ClientErrorCode; retryAfterMs?: number }. See Errors for the codes.

What it does when it mounts

  1. It creates the client with your key, URL and token function.
  2. It resumes the session stored in sessionStorage, including a turn that was waiting for tool results. If storage is blocked, the chat starts fresh.
  3. It fetches the theme and logo the agent's owner published in the console, with the publishable key. A failure leaves the SDK's own look.

The provider reads getUserToken and onError through refs, so passing a new function on every render does not recreate the client. The client is created once. Changing publishableKey or baseUrl after mount does not rebuild it, so remount the provider (with a key) if you need to switch agents.

Keys and tokens

Never pass a secret key (sk_) to the provider. It throws if the key starts with sk_, and it also refuses a key that is not pk_ plus 48 hex characters.

The user token is sent only as a request header. The SDK never logs it, and never stores it in chat state.

Reading provider state

Two hooks read what the provider holds:

import { useBaseeraTheme, useBaseeraAgentTheme } from "@baseera/react";

const theme = useBaseeraTheme(); // the `theme` prop, or undefined
const { theme: agentTheme, logoUrl } = useBaseeraAgentTheme(); // set in the console; null until loaded

Next steps

On this page