Skip to main content
The OpenBat SDK is a lightweight TypeScript client that captures conversation data from your AI chatbot and sends it to OpenBat for analysis. One function call is all it takes — add recordMessages to your response handler and conversations start flowing into the dashboard.
import { OpenBat } from 'openbat';

const client = new OpenBat();

await client.recordMessages({
  conversationId: "conv_123",
  messages: [
    { role: "user", content: "How do I reset my password?" },
    { role: "assistant", content: "Go to Settings > Account > Reset password." }
  ]
});

Design principles

Fire-and-forgetrecordMessages catches all errors internally and never throws. If the OpenBat API is unreachable, the SDK logs the error and moves on. Your chatbot is never affected.
Non-blocking — capturing runs in the background. Streaming latency is unaffected whether you call recordMessages directly or use the withOpenBat wrapper.
Deduplication — pass a message id on each message and safely call recordMessages on every turn. Duplicate message IDs are ignored server-side, so you never insert the same message twice.
Configurable — disable the SDK in test or CI environments with a single environment variable. No code changes needed.
# .env.test
OPENBAT_ENABLED=false

What you can capture

Every call to recordMessages accepts a conversation ID, an array of messages, and optional metadata objects. The more metadata you provide, the more powerful your filtering and segmentation becomes in the dashboard.
DataDescription
Conversation messagesUser, assistant, and system messages with optional timestamps
User metadataName, email, plan, MRR, industry, account creation date
Organization metadataCompany name, plan, MRR, industry
Session metadataPage URL, referrer, device type, country
Custom fieldsAny key-value pairs matching your chatbot’s metadata schema

Next steps

Installation

Install the SDK and configure your API key.

Recording messages

Full reference for the recordMessages method and all metadata options.

Vercel AI SDK

Use the withOpenBat wrapper for streaming responses.