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

# LiteLLM integration

> Use LiteLLM with The Context Company custom instrumentation for Python

The LiteLLM integration automatically captures steps from your LiteLLM calls and associates them with your TCC runs.

## Prerequisites

* A TCC API key set as `TCC_API_KEY` environment variable
* The `contextcompany` package installed

## Setup

### Step 1: Install dependencies

<CodeGroup>
  ```Title pip theme={null}
  pip install contextcompany[litellm]
  ```

  ```Title poetry theme={null}
  poetry add contextcompany[litellm]
  ```
</CodeGroup>

### Step 2: Initialize the callback

Import and register the `TCCCallback` with LiteLLM:

```python theme={null}
import litellm
from contextcompany.litellm import TCCCallback

litellm.callbacks = [TCCCallback()]
```

### Step 3: Create a run with LiteLLM steps

Create a run and use LiteLLM inside your agent loop. You must pass the run ID in the `metadata` parameter to associate the step with your run:

```python main.py theme={null}
import contextcompany as tcc
import litellm
from contextcompany.litellm import TCCCallback

# Initialize the callback
litellm.callbacks = [TCCCallback()]

r = tcc.run()
r.prompt("What is the weather in London?")  # required

# --- Your agent loop ---
response = litellm.completion(
    ...,
    metadata={"tcc.runId": r.run_id},  # required
)
# --- End of agent loop ---

r.response(response.choices[0].message.content)  # optional
r.end()  # required
```

That's it! Your agent run and LiteLLM steps will now be tracked and viewable in the dashboard.

## Custom metadata

You can pass additional metadata alongside the required `tcc.runId`:

```python theme={null}
response = litellm.completion(
    ...,
    metadata={
        "tcc.runId": r.run_id,  # required
        "userId": "550e8400-e29b-41d4-a716-446655440000",  # you can pass any metadata here
    },
)
```

## What gets captured

The LiteLLM integration automatically captures:

* **Model**: Both the requested and used model
* **Messages**: Input and output messages
* **Token usage**: Prompt and completion tokens
* **Finish reason**: Why the LLM stopped generating
* **Tool calls**: Any tool calls made by the model

This data is associated with your run and visible in the TCC dashboard.
