Skip to main content
Mastra is a TypeScript framework. This integration is for TypeScript/Node.js only. For Python agent frameworks, see LangChain or CrewAI.

What Gets Tracked Automatically

Sessions

One session per generate() or stream() call — input, output, status, duration.

LLM Steps

Every LLM call within an agent step — model, tokens, finish reason.

Tool Calls

Each tool execution with input args, output result, and tool call ID.

Tokens & Cost

Prompt and completion tokens, auto-calculated cost per provider.

Multi-Turn

memory.thread maps to convoId, memory.resource maps to userId — zero config.

PII Redaction

Auto-redact emails, phone numbers, SSNs, and more from tracked inputs.

Installation

Quick Start

One function call. Then use your agent exactly like before.

Configuration Options

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

Multi-Turn Conversations

When you use Mastra’s memory system, conversations are automatically linked. No extra config needed.
In your Sentrial dashboard, both sessions appear linked under the same conversation ID. The mapping is:

Tool Tracking

When your agent calls tools, each execution is automatically recorded as an event — with the tool name, input args, and output result.

Streaming

Streaming works transparently. The wrapper intercepts the onFinish callback, records the full response, and completes the session when the stream ends.

PII Redaction

Enable PII redaction to automatically scrub sensitive data from tracked inputs before they reach Sentrial’s servers.
PII redaction happens client-side before data leaves your server. Configure which PII types to redact in your Sentrial dashboard under Settings > PII Redaction.

Per-Call Overrides

Override userId, convoId, or attach extra metadata on a per-call basis:

Error Handling

If an agent call throws, the error is recorded and the session is marked as failed. The original error is always re-thrown so your error handling works normally.

Full Production Example

A complete customer support agent with multi-turn, tools, streaming, and PII redaction:

Supported Models

Cost is auto-calculated per provider. The provider is detected from the Mastra model string (e.g., openai/gpt-4o).

What You See in the Dashboard

Each agent call creates a session in Sentrial with:

Session Overview

Agent name, user ID, status, duration, cost, conversation linkage.

Input / Output

User prompt (PII-redacted if enabled) and full agent response.

Events Timeline

LLM steps and tool calls as events with input, output, tokens, and cost.

Conversation View

Multi-turn sessions linked by convoId, displayed as a threaded conversation.

Next Steps

TypeScript SDK Reference

Full SDK documentation with all methods and options.

Vercel AI SDK

Alternative integration for Vercel AI SDK users.