Skip to main content

Installation

Install the Trainly React SDK from npm:
Requires React 18+ and TypeScript 5.0+. The SDK is fully tree-shakeable.

Quick Start

Wrap your application with TrainlyProvider and start tracing AI calls in under five minutes.

TrainlyProvider

The root provider that initializes the SDK and manages connection state.

Props

useTrainlyObserve

The primary hook for AI observability. Returns functions to trace, wrap, span, and score your AI calls.

trace(input, output, options?)

Log a completed AI call manually.

wrap(fn, options?)

Wrap any async function for automatic tracing. The SDK captures input arguments, return values, latency, and errors.

startSpan(name, options?)

Create a manual span for fine-grained tracing of multi-step pipelines.

Span Methods

score(traceId, name, value, comment?)

Score a trace for evaluation and quality tracking.

TraceOptions

All tracing functions accept these options:

TrainlySessionProvider

Groups traces into sessions automatically. Useful for tracking multi-turn agent interactions or user workflows.

useTrainlySession()

V1 OAuth Authentication

For multi-user applications where each end-user should have isolated trace data, use V1 OAuth mode with your existing auth provider.
Supported identity providers: Clerk, Auth0, AWS Cognito, Firebase Auth, and any custom OIDC-compliant provider.

Pre-built Components

The SDK includes optional UI components for specific use cases:
Pre-built components are designed for gated features and require additional configuration. The observability features (useTrainlyObserve, sessions, scoring) work independently without these components.

TypeScript Support

The SDK ships with full TypeScript definitions. All hooks, components, and options are fully typed.