Skip to main content

Installation

Quick Start

Module Functions

sentrial.configure()

Configure the default Sentrial client.

Environment Variables & Transport

The SDK ingests over OTLP (/api/otel/v1/traces) — this is the sole ingestion path. The OTLP path requires the API key to carry both sessions:write and events:write scopes — dashboard-generated keys include both, but a manually-scoped sessions:write-only key will silently drop data. Add events:write to the key.

sentrial.begin()

Begin tracking an interaction. Returns an Interaction object.
string
required
External user ID.
string
required
Event type / agent name.
string
Input data.
string
Custom event ID (auto-generated if omitted).
string
Conversation ID for grouping.
dict
Additional metadata.

Interaction Class

Returned by sentrial.begin(). Provides methods to track events and finish the interaction.

interaction.finish()

Finish the interaction and record final metrics.
success defaults to None, which means “use the tracked state”: True normally, but if interaction.track_error() was called, the default flips to False (with failure_reason defaulting to the tracked error message). Pass success=True/False explicitly to override.

interaction.set_metadata() / interaction.set_model()

Update the session after begin() — both are merged into the session on finish() (the finalize re-post). set_metadata merges keys into the session metadata (incoming values win); set_model records the session-level model (an explicit finish()-time model still wins).
Also available client-level as client.set_session_metadata(session_id, metadata) and client.set_session_model(session_id, model). begin() additionally accepts name=... (session title override; auto-named {event}:{id} otherwise) and model=....

interaction.track_tool_call()

Track a tool call within the interaction.

interaction.track_decision()

Track an agent decision.

interaction.report_diagnostic(report)

Record an agent’s observation about missing context, a tool problem, a missing capability, or uncertain completion. Call this explicitly while the interaction is active. It does not call a model, change session success, or create a confirmed signal or training label.
Agent reports are included in the unreleased SDK changes. Staging acceptance is complete; package publication is pending. Use matching SDK, collector and trace UI builds to test this feature.
The client equivalents are client.report_diagnostic(session_id, report) and await async_client.report_diagnostic(session_id, report). Use the same client that created the active session. They return None, which is not a durable-delivery receipt. Check transport diagnostics and the retained trace. Finished or degraded interactions do not accept new reports. The dictionary uses the same camelCase field names as the TypeScript SDK, including reportId and relatedSpanIds: The SDK sets the report revision and origin; do not supply extra fields. Configured metadata PII redaction, batching, retry and fail_silently behavior apply. Each call creates a separate event; recovery does not overwrite the original report or prove business success. The trace UI labels these Agent report and Reported recovered. Older collectors retain generic metadata without the validated report presentation. Absence of a report does not establish success.

SentrialClient Class

For full control over session management.

Constructor

client.create_session()

Create a new tracking session. Returns the session ID, or None if creation failed and the client is configured with fail_silently (the default).

client.track_tool_call()

client.track_decision()

client.complete_session()

Complete a session with final metrics.

client.track_error()

LLM Auto-Wrappers

Automatically track all LLM calls with token counts, cost, and latency.
Also available: wrap_anthropic(client), wrap_google(model), wrap_llm(client) (auto-detect).

Decorators

Context Manager

Event Batching

Queue tracking calls and flush periodically to reduce HTTP overhead.
The module-level API supports the same options: sentrial.configure(api_key="...", batching=True).

PII Redaction

Automatically redact sensitive data before it leaves your infrastructure.
Auto-fetching (pii=True) requires the API key to have the pii-config:read scope. If the key lacks it the fetch is refused and the SDK falls back to the default redaction config (label mode, default fields, builtin patterns) — your org’s configured mode/fields/custom patterns are NOT applied. The SDK logs a one-time warning when this happens.

Cost Calculation Helpers

Static methods to calculate LLM API costs.

calculate_openai_cost()

calculate_anthropic_cost()

calculate_google_cost()

Async Support

All SDK classes have async equivalents for use with asyncio.

client.close()

The async client has no flush() / shutdown() — its only lifecycle method is close(). Call it before your process exits: it flushes any batched events, then closes the underlying HTTP client (and the Langfuse integration, if enabled).

LangChain Integration

Use SentrialCallbackHandler to automatically track all LLM calls, tool usage, and agent decisions in LangChain. Full LangChain Integration Guide →

Next Steps

LangChain Integration

Automatic tracking for LangChain agents.

Claude Code Integration

Auto-track Claude Agent SDK sessions and tool calls.

Mastra Integration

One-line setup for Mastra AI agents.

OpenAI Agents SDK

Mirror every Agents SDK run into a session — LLM calls, tools, handoffs, guardrails.

Sessions API

REST API reference.