Skip to main content
The Adaline SDK is the recommended way to integrate your AI application with Adaline. Beyond sending traces and spans, the SDK gives you deployment management with automatic caching, smart buffering with batched flushes, built-in retries with exponential backoff, and health monitoring — all production-ready out of the box.

What the SDK gives you

Install

Initialize the client

Set the ADALINE_API_KEY environment variable and omit the apiKey parameter to avoid hardcoding secrets. The SDK reads from this variable automatically.

Manage deployments

The SDK can fetch deployed prompt configurations — including the model, provider settings, messages, tools, and variables — so your application always uses the latest version without redeploying code.

Fetch a specific deployment

Fetch the latest deployment for an environment

Auto-refresh deployments in production

For long-running services, use initLatestDeployment to set up a cached deployment that refreshes automatically (default every 60 seconds) in the background. When you deploy a new prompt version in Adaline, your application picks it up without a restart.

Initialize the monitor

The monitor manages the lifecycle of traces and spans — buffering them in memory, batching them together, and flushing them to the Adaline API on a timer or when the buffer fills up.

Create a trace

A trace represents a single end-to-end request flow — for example, one user message that triggers an LLM call, a tool execution, and a final response.

Add spans

Each operation inside a trace is a span. Spans carry a content type that tells Adaline what kind of operation it represents — an LLM call, a tool execution, a vector retrieval, and more.

Create a span

Update and end a span

After performing the operation, update the span with the result and end it:

Nested spans

Spans can contain child spans to model hierarchical workflows — an agent span containing tool call spans, or a RAG span containing embedding and retrieval sub-spans:

Span content types

The content.type field tells Adaline what kind of operation a span represents. Each type carries input and output as JSON strings, plus type-specific fields.

Model

LLM chat completions and text generation. Captures the provider, model, cost, and optionally expected output for evaluation. For the best experience, stringify the exact request payload you send to your AI provider as input and the full response as output. When you use a supported provider, Adaline automatically extracts token usage, calculates cost, and surfaces model metadata. See Span content: input and output for full details and examples. You can also use Adaline’s own content schema for input and output, although this is more advanced and requires custom transformations.

ModelStream

Streaming LLM responses. Captures both the raw stream chunks and an aggregated output.

Tool

Function or tool call execution.

Retrieval

Vector search, document retrieval, or any RAG retrieval step.

Embeddings

Embedding generation.

Function

Custom business logic, data transforms, or any application-specific operation.

Guardrail

Safety checks, content filters, PII detection, or compliance rules.

Other

Any operation that doesn’t fit the types above.
All content types share type, input (JSON string), and output (JSON string).

End the trace and flush

Always end the trace and flush remaining data. Calling end() on a trace recursively ends all child spans that haven’t been ended yet.
Traces and spans that are never ended will never be flushed. Always call end() — use try/finally blocks to guarantee it runs even when errors occur.

Attach variables for evaluation

Attach variable values to spans so they flow into continuous evaluations and can be captured into datasets. Variables are set on the span’s content object (specifically on Model or ModelStream content types), not on logSpan() directly:
Variables support text, image, and pdf modalities. See Log attachments for full details on attaching variables, attributes, and tags.

Buffering, batching, and retries

The SDK handles reliability so you don’t have to.

How the buffer works

  1. When you call logTrace() or logSpan(), entries are added to an in-memory buffer.
  2. A background timer flushes the buffer every flushInterval seconds.
  3. If the buffer reaches maxBufferSize, it flushes immediately.
  4. Each flush sends a batch of entries in a single API call.

Retry behavior

Health monitoring

Inspect the monitor’s flush status at runtime to detect issues:

Graceful shutdown

In production, handle process signals to flush remaining data before the process exits:
Serverless environments (AWS Lambda, Vercel Functions, Cloudflare Workers, etc.): The SDK flushes buffered traces and spans on a background interval, but serverless functions can exit before the next flush fires. Always call await monitor.flush() (TypeScript) or await monitor.flush() (Python) explicitly before your handler returns to ensure nothing is lost.

Next steps

Advanced Tracing Patterns

Multi-step workflows, tool-calling agents, session tracking, and error handling patterns.

Log User Feedback

Attach thumbs up/down, ratings, and comments to traces.

Log Attachments

Attach attributes, tags, variables, and metadata to traces and spans.

SDK Reference

Complete class and type reference for the TypeScript and Python SDKs.