> ## Documentation Index
> Fetch the complete documentation index at: https://moonshotfactory.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Installation

> Install the AgentVista Python SDK and initialize it in your application.

## Install the package

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

<CodeGroup>
  ```bash Base theme={null}
  pip install agentvista
  ```

  ```bash With Anthropic adapter theme={null}
  pip install agentvista[anthropic]
  ```

  ```bash With OpenAI adapter theme={null}
  pip install agentvista[openai]
  ```
</CodeGroup>

## Initialize the SDK

Call `agentvista.init()` once at the start of your application — before any agents run.

```python theme={null}
import agentvista

agentvista.init(api_key="av_xxxxx")
```

<Note>
  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.
</Note>

<Tip>
  Load your API key from an environment variable rather than hardcoding it:

  ```python theme={null}
  import os
  import agentvista

  agentvista.init(api_key=os.environ["AGENTVISTA_API_KEY"])
  ```
</Tip>

## Parameters

<ParamField path="api_key" type="str" required>
  Your AgentVista API key. Keys start with `av_`. Find yours in the AgentVista
  dashboard under **Settings → API Keys**.
</ParamField>

<ParamField path="endpoint" type="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.
</ParamField>

<ParamField path="flush_interval" type="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.
</ParamField>

## 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.

```python theme={null}
import agentvista

agentvista.init(api_key="av_xxxxx")

# ... run your agent ...

# Ensure events are delivered before the script exits
agentvista.flush()
```

### `agentvista.shutdown()`

Flushes all queued events and stops the background transport thread. Call this on application exit in long-running servers.

```python theme={null}
import atexit
import agentvista

agentvista.init(api_key="av_xxxxx")
atexit.register(agentvista.shutdown)
```

<Warning>
  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.
</Warning>
