> ## Documentation Index
> Fetch the complete documentation index at: https://www.adaline.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# LiteLLM

> Observe LiteLLM calls with Adaline.

# LiteLLM

Use the Adaline LiteLLM logger to send LiteLLM calls into Adaline. The integration attaches through LiteLLM's callback system and works with the model/provider routing you already use.

## Prerequisites

Before you start, make sure you have:

* An [Adaline account](https://app.adaline.ai/sign-up?utm_source=adaline.ai).
* A **workspace API key** — create one under **Settings → API keys**.
* Your **project ID** — copy it from **Monitor → Copy Project ID**.

See [Integrate your AI Agent](/get-started/integrate-your-ai-agent) for a full walkthrough.

Set both as environment variables before running the examples on this page:

```bash theme={null}
export ADALINE_API_KEY="your-api-key"
export ADALINE_PROJECT_ID="your-project-id"
```

## Install

```bash theme={null}
pip install adaline-client adaline-litellm litellm
```

Install LiteLLM itself alongside the Adaline integration package.

## Initialize Adaline

Create an Adaline client, then initialize a monitor for the target project.

```python theme={null}
import os

from adaline import Adaline

adaline = Adaline(api_key=os.environ["ADALINE_API_KEY"])
monitor = adaline.init_monitor(project_id=os.environ["ADALINE_PROJECT_ID"])
```

<Note>
  For production guidance — buffering, batching, retries, serverless flushing, and graceful shutdown — see [Instrument with the Adaline SDK](/instrument/with-adaline-sdks).
</Note>

## Attach the LiteLLM logger

Create an `AdalineLiteLLMLogger` and register it in `litellm.callbacks`.

```python theme={null}
import litellm

from adaline_litellm import AdalineLiteLLMLogger

logger = AdalineLiteLLMLogger(monitor=monitor)
litellm.callbacks = [logger]
```

## Basic example

This example keeps the integration intentionally small: one LiteLLM completion with the Adaline logger attached.

```python theme={null}
import asyncio
import litellm

from adaline_litellm import AdalineLiteLLMLogger

async def main():
    parent_trace = monitor.log_trace(
        name="litellm-run",
        reference_id="litellm-run-1",
    )

    logger = AdalineLiteLLMLogger(
        monitor=monitor,
        parent_trace=parent_trace,
        tags=["litellm"],
    )

    litellm.callbacks = [logger]
    try:
        response = await litellm.acompletion(
            model="gpt-4o-mini",
            messages=[{"role": "user", "content": "Say hello in one word."}],
            max_tokens=20,
        )
    finally:
        litellm.callbacks = []

    parent_trace.end()
    await monitor.flush()


asyncio.run(main())
```

## Use an existing parent trace or span

If you already created a trace or span in Adaline, pass it to the logger so LiteLLM work is attached underneath it.

* `parent_trace`
* `parent_span`

Pass one or the other, but not both.

## What the logger captures

The LiteLLM integration is designed to capture LiteLLM completion activity, including:

* model and provider metadata
* input and output payloads from the logged completion
* token usage when the provider response includes usage fields
* nested spans under an Adaline parent when provided

This page focuses on how to attach the logger. The exact span shape depends on the LiteLLM calls your application makes.

## Next steps

<CardGroup cols={2}>
  <Card title="Instrument with the Adaline SDK" icon="code" href="/instrument/with-adaline-sdks">
    Monitor lifecycle, buffering and batching, retries, serverless flushing, and graceful shutdown.
  </Card>

  <Card title="SDK reference" icon="braces" href="/reference/sdk/v2/overview">
    Full class and type reference for the TypeScript and Python SDKs.
  </Card>

  <Card title="All integrations" icon="layout-grid" href="/integrations/introduction">
    Browse every framework and AI-provider integration Adaline supports.
  </Card>

  <Card title="View your logs" icon="line-chart" href="https://app.adaline.ai">
    Open Adaline to see traces and spans land in your project.
  </Card>
</CardGroup>
