Skip to main content
Supported Versions: Vercel AI SDK v3, v4, v5, and v6. Works with generateText, streamText, generateObject, and streamObject.

What Gets Tracked Automatically

LLM Calls

Model, provider, prompt, messages, system prompt — captured per call.

Responses

Full generated text, finish reason, and structured objects.

Token Usage

Prompt tokens, completion tokens, and total — per session.

Tool Calls

Every tool execution with input args, output result, duration, and errors.

Cost

Auto-calculated per provider (OpenAI, Anthropic, Google).

Errors

Caught, recorded with type and message, then re-thrown — nothing swallowed.

Installation

Quick Start

3 lines of setup. Then use generateText and streamText exactly like you normally would.

Configuration Options

Fail-Safe by Default — With failSilently: true (the default), any Sentrial API errors are logged but never crash your app. Your AI calls always go through. Set to false during development to see full errors.

Dynamic User & Conversation IDs

userId and convoId accept functions for per-request resolution. This is essential for apps using Clerk, NextAuth, or any auth system where the user changes per request.
Functions are called at session creation time (every generateText/streamText call), so they always get the current request’s values. You can also set them per-instance via wrapAISDK:

Automatic Tool Tracking

When you pass tools to generateText or streamText, every tool’s execute function is automatically wrapped. Each execution is recorded with input args, output, duration, and any errors. Zero changes to your tool code.
In your Sentrial dashboard, each tool call appears as a child event under the session — with the tool name, input, output, and execution time.

Conversation Threading

Use convoId to link multiple AI SDK calls into a single conversation thread. Set it globally in configureVercel() or per-instance in wrapAISDK().
You can also pass a custom SentrialClient instance if you need full control:

Multi-Step Agentic Calls

When using maxSteps for agentic loops, each step is automatically tracked as a separate event with its own token usage, tool calls, and finish reason. The session aggregates totals across all steps.

Streaming

Streaming works transparently. The wrapper intercepts the text stream, accumulates the full response, and records the session when the stream completes.

Structured Output

generateObject and streamObject are also wrapped. The output JSON is stored as the session response.

Multiple Providers

Cost is auto-calculated per provider. The wrapper detects the provider from the model ID and applies the correct pricing.

Next.js Chat Route (Full Example)

A complete Next.js API route with streaming, tool calls, dynamic user tracking, and Sentrial:
No Clerk? Replace auth().userId with whatever your auth system provides — session.user.id, req.headers['x-user-id'], getServerSession().user.id, etc. Any function that returns a string works.

What You See in the Dashboard

Each AI SDK call creates a session in Sentrial with:

Session Overview

Agent name, user ID, status (completed/failed), duration, cost.

Input / Output

The user prompt and the full generated response, displayed as a conversation.

Events Timeline

Tool calls shown as events with input, output, and execution time.

Token & Cost Breakdown

Prompt tokens, completion tokens, total tokens, estimated cost in USD.

Error Handling

If an AI call or tool execution throws, the error is recorded and the session is marked as failed. The original error is always re-thrown so your app’s error handling works normally.

Next Steps

TypeScript SDK Reference

Full SDK documentation with all methods and options.

Custom Agents

Framework-agnostic integration for non-Vercel AI SDK setups.