Skip to main content

Install the package

Choose the install command that matches the LLM provider you use. If you use multiple providers, you can combine extras.

Initialize the SDK

Call agentvista.init() once at the start of your application — before any agents run.
Call init() once at app startup. All subsequent calls to record(), trace_agent, run(), and span() automatically use the initialized client. Calling init() a second time shuts down the existing client and starts a fresh one.
Load your API key from an environment variable rather than hardcoding it:

Parameters

str
required
Your AgentVista API key. Keys start with av_. Find yours in the AgentVista dashboard under Settings → API Keys.
str
default:"https://api.agentvista.dev/api/v1/traces/batch"
The telemetry ingestion endpoint. Override this only if you are self-hosting AgentVista or routing through a proxy.
float
default:"2.0"
Seconds between automatic batch flushes. Events are buffered in memory and sent in the background on this interval. Lowering this value reduces the maximum age of buffered events but increases the number of network requests.

Flushing and shutting down

The SDK batches events in memory and sends them asynchronously every flush_interval seconds. In long-running services this happens automatically. In short-lived scripts or serverless functions you need to flush explicitly before the process exits.

agentvista.flush()

Blocks until all queued events have been delivered to the AgentVista backend.

agentvista.shutdown()

Flushes all queued events and stops the background transport thread. Call this on application exit in long-running servers.
If your process exits without calling flush() or shutdown(), any events still buffered in memory will be lost. This is most likely to affect short-lived CLI scripts and serverless functions.