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 istrailSecret key argument secrect_key— a preserved typo. The env varTRAIL_SECRET_KEYis spelled correctly
Get running
Installation
Requirements, pip install trailai, what gets pulled in, and how to verify.
Python Quickstart
Zero to a trace in five minutes, then guardrails, prompts, and a complete small application.
Configuration
Every argument and environment variable — including the two that cost people an afternoon.
Instrument
Auto-Instrumentation
40+ supported libraries across providers, agent frameworks, and vector databases — and how to disable individual ones.
Manual Tracing
@trail.trace, start_trace, the role model, agent context propagation, and what to trace.
Platform features
Reference
TypeScript SDK
Node instrumentation, prompt hub, vault — and the ways it diverges from Python.
Troubleshooting
"No data in the dashboard" and every other common failure, plus a diagnostic script.
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()returnsverdict: "yes"(blocked) rather than an error you might misread as a pass. How to handle itIt's OpenTelemetry underneath
Spans, attributes, and the
gen_ai.*semantic conventions are standard OTel. You can pass your owntracerandmetertoinit()and integrate with an existing telemetry pipeline.