OpenBat supports four integration methods. Choose the one that fits your stack.
Never expose your API key in client-side code. Always use environment variables and keep your key on the server.
Installation
Vercel AI SDK
TypeScript
Python
REST API
The Vercel AI SDK integration wraps your existing chat handler to automatically capture conversations.npm install @openbat/vercel-ai
import { openBat } from '@openbat/vercel-ai';
const analytics = openBat({
apiKey: process.env.OPENBAT_API_KEY,
});
export const POST = analytics.wrapHandler(async (req) => {
// your existing AI SDK chat handler
});
This method automatically captures all messages, user metadata, and session context without changes to your existing code. The TypeScript SDK gives you full control over what conversations and metadata you send.import { OpenBat } from '@openbat/sdk';
const client = new OpenBat({
apiKey: process.env.OPENBAT_API_KEY,
});
await client.conversations.create({
messages: [
{ role: 'user', content: 'How do I upgrade my plan?' },
{ role: 'assistant', content: 'You can upgrade from Settings > Billing.' },
],
metadata: {
userId: 'user_123',
email: 'user@example.com',
organization: 'Acme Corp',
plan: 'pro',
mrr: 99,
},
});
import os
from openbat import OpenBat
client = OpenBat(api_key=os.environ["OPENBAT_API_KEY"])
client.conversations.create(
messages=[
{"role": "user", "content": "How do I upgrade my plan?"},
{"role": "assistant", "content": "You can upgrade from Settings > Billing."},
],
metadata={
"user_id": "user_123",
"email": "user@example.com",
"organization": "Acme Corp",
"plan": "pro",
"mrr": 99,
},
)
Use the REST API from any language or platform.curl -X POST https://api.openbat.dev/v1/conversations \
-H "Authorization: Bearer $OPENBAT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{"role": "user", "content": "How do I upgrade my plan?"},
{"role": "assistant", "content": "You can upgrade from Settings > Billing."}
],
"metadata": {
"userId": "user_123",
"email": "user@example.com",
"organization": "Acme Corp",
"plan": "pro",
"mrr": 99
}
}'
You can send custom metadata with each conversation. Common fields include:
| Field | Type | Description |
|---|
userId | string | Your internal user identifier |
email | string | User’s email address |
organization | string | User’s organization name |
plan | string | User’s subscription plan |
mrr | number | Monthly recurring revenue |
industry | string | User’s industry |
OpenBat automatically discovers metadata fields sent from the SDK. You can track or deny discovered fields from the Analysis Config > Metadata tab.
Session context
The SDK automatically captures session context when running in a browser environment:
- Browser and device type
- Operating system
- Page URL and referrer
- Language
- Country (via IP geolocation)
This data appears in the conversation detail sidebar under Session info.
Next steps
SDK reference
Full SDK documentation and advanced usage.
Manage metadata
Track and filter by custom metadata fields.
View conversations
Browse and filter your analyzed conversations.