SDK Guide

The TrailAI SDK instruments your AI application: it traces LLM and agent calls automatically, and gives you guardrails, versioned prompts, and secrets at runtime.

Python quickstart All configuration options Troubleshooting

The whole integration

import trail

trail.init(
    application_name="support-bot",
    environment="production",
    url="https://your-trail-host/api/sdk/v1",
    public_key="pk-trail-…",
    secret_key="sk-trail-…",
)

That's it for tracing. Everything below is optional.

Two spellings that catch everyone once

Thing Correct form
PyPI package trailai — the import is trail
Secret key argument secrect_key — a preserved typo. The env var TRAIL_SECRET_KEY is spelled correctly

Get running

Installation

Requirements, pip install trailai, what gets pulled in, and how to verify.

Installation

Python Quickstart

Zero to a trace in five minutes, then guardrails, prompts, and a complete small application.

Quickstart

Configuration

Every argument and environment variable — including the two that cost people an afternoon.

Configuration

Instrument

Auto-Instrumentation

40+ supported libraries across providers, agent frameworks, and vector databases — and how to disable individual ones.

Auto-Instrumentation

Manual Tracing

@trail.trace, start_trace, the role model, agent context propagation, and what to trace.

Manual Tracing

Platform features

Guardrails

guard.input() / .output(), verdict semantics, and fail-closed handling.

Guardrails

Prompts

get_prompt(), fetching by label or version, caching strategies, and fallbacks.

Prompts

Vault

get_secrets(), the should_set_env pattern, and rotation.

Vault

Reference

TypeScript SDK

Node instrumentation, prompt hub, vault — and the ways it diverges from Python.

TypeScript SDK

REST API Reference

The /api/sdk/v1/* endpoints, for runtimes without a TrailAI SDK.

REST API

Troubleshooting

"No data in the dashboard" and every other common failure, plus a diagnostic script.

Troubleshooting

What the SDK provides

Capability Entry point Guide
Auto-instrumentation of 40+ AI libraries trail.init() Auto-Instrumentation
Manual spans for your own code @trail.trace, trail.start_trace() Manual Tracing
Guardrail checks trail.guard.input() / .output() Guardrails
Versioned prompts trail.get_prompt() Prompts
Secrets trail.get_secrets() Vault

Design principles worth knowing

The SDK never crashes your application — so silence is the failure mode

trail.init() wraps its entire body in a try/except. Missing credentials, an unreachable server, or a failed instrumentation are logged and swallowed. Your app keeps running; it just stops sending telemetry.

That is correct behaviour for an observability library, but it means when data stops arriving, check your logs before assuming everything is fine. Turn on debug logging first:

import logging
logging.basicConfig(level=logging.DEBUG)

Guardrails fail closed

The one exception to the above. If the guardrail service is unreachable, trail.guard.input() returns verdict: "yes" (blocked) rather than an error you might misread as a pass. How to handle it

It's OpenTelemetry underneath

Spans, attributes, and the gen_ai.* semantic conventions are standard OTel. You can pass your own tracer and meter to init() and integrate with an existing telemetry pipeline.

Related

Platform Quickstart

The account-and-key half of setup, before you write any code.

Quickstart

Dashboard Guide

Reading what the SDK sends.

Dashboard