Skip to main content
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

pip install contextcompany[litellm]

Step 2: Initialize the callback

Import and register the TCCCallback with LiteLLM:
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:
main.py
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:
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.