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

# LiteLLM

> Add HoneyHive observability to your LiteLLM applications

[LiteLLM](https://docs.litellm.ai/docs/) provides a unified interface for calling 100+ LLMs using the OpenAI format. HoneyHive integrates with LiteLLM via the OpenInference instrumentor, automatically capturing all completion calls, token usage, and model metadata across providers.

## Quick Start

<Tip>
  **Add HoneyHive tracing in just 4 lines of code.** Add this to your existing LiteLLM app and all completion calls are automatically traced, regardless of the underlying provider.
</Tip>

<Tip>
  To see where to initialize the tracer for your environment, including AWS Lambda and long-running servers, see [Tracer Initialization](/v2/tracing/tracer-initialization).
</Tip>

<Note>
  Last tested with `litellm 1.82.4` (March 2026).
</Note>

```bash theme={null}
pip install "honeyhive[openinference-litellm]"

# Or install separately
pip install honeyhive openinference-instrumentation-litellm litellm
```

```python theme={null}
import os
import litellm
from honeyhive import HoneyHiveTracer
from openinference.instrumentation.litellm import LiteLLMInstrumentor

tracer = HoneyHiveTracer.init(
    api_key=os.getenv("HH_API_KEY"),
    project=os.getenv("HH_PROJECT"),
)
LiteLLMInstrumentor().instrument(tracer_provider=tracer.provider)

# Your existing LiteLLM code works unchanged
```

## What Gets Traced

The instrumentor automatically captures:

* **Completions** - `litellm.completion()` and `litellm.acompletion()` with inputs, outputs, and token usage
* **Embeddings** - `litellm.embedding()` and `litellm.aembedding()` requests
* **Image generation** - `litellm.image_generation()` and `litellm.aimage_generation()` calls
* **Multi-provider routing** - Model name and provider metadata for every call

No manual instrumentation required.

<Warning>
  **Use module-level calls.** The instrumentor patches `litellm.completion()`, not directly imported functions. Always use `litellm.completion()` instead of `from litellm import completion`.
</Warning>

***

## Example: Multi-Provider Completions

```python theme={null}
import os
import litellm
from honeyhive import HoneyHiveTracer
from openinference.instrumentation.litellm import LiteLLMInstrumentor

tracer = HoneyHiveTracer.init(
    api_key=os.getenv("HH_API_KEY"),
    project=os.getenv("HH_PROJECT"),
)
LiteLLMInstrumentor().instrument(tracer_provider=tracer.provider)

# OpenAI via LiteLLM
response = litellm.completion(
    model="openai/gpt-4o-mini",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What is the capital of France?"},
    ],
    max_tokens=50,
)
print(response.choices[0].message.content)

# Anthropic via LiteLLM - same interface, automatically traced
response2 = litellm.completion(
    model="anthropic/claude-haiku-4-5-20251001",
    messages=[
        {"role": "user", "content": "Tell me a fun fact about Paris."},
    ],
    max_tokens=100,
)
print(response2.choices[0].message.content)
```

***

## Avoiding Duplicate Spans

<Warning>
  **Avoid duplicate spans.** If you also use provider-specific instrumentors (e.g., `OpenAIInstrumentor`), LiteLLM calls to that provider may produce duplicate spans. Use only the LiteLLM instrumentor when routing calls through LiteLLM.
</Warning>

***

## Environment Configuration

```bash theme={null}
# HoneyHive configuration
export HH_API_KEY="your-honeyhive-api-key"
export HH_PROJECT="your-project"

# Provider API keys (set whichever providers you use)
export OPENAI_API_KEY="your-openai-api-key"
export ANTHROPIC_API_KEY="your-anthropic-api-key"
```

***

## Troubleshooting

### Traces not appearing

1. **Check environment variables** - Ensure `HH_API_KEY` and `HH_PROJECT` are set
2. **Pass the tracer provider** - The instrumentor must receive `tracer_provider=tracer.provider`:

```python theme={null}
import os
from honeyhive import HoneyHiveTracer
from openinference.instrumentation.litellm import LiteLLMInstrumentor

tracer = HoneyHiveTracer.init(
    api_key=os.getenv("HH_API_KEY"),
    project=os.getenv("HH_PROJECT"),
)

# ✅ Correct - pass tracer_provider
LiteLLMInstrumentor().instrument(tracer_provider=tracer.provider)

# ❌ Wrong - missing tracer_provider
LiteLLMInstrumentor().instrument()
```

3. **Use module-level calls** - Call `litellm.completion()`, not a directly imported `completion()` function

***

## Related

<CardGroup cols={2}>
  <Card title="Enrich Your Traces" icon="sparkles" href="/v2/tutorials/enriching-traces">
    Add user IDs and custom metadata to traces
  </Card>

  <Card title="Custom Spans" icon="code" href="/v2/tracing/custom-spans">
    Create spans for business logic around API calls
  </Card>

  <Card title="Distributed Tracing" icon="share-nodes" href="/v2/tutorials/distributed-tracing">
    Trace calls across service boundaries
  </Card>
</CardGroup>

***

## Resources

* [LiteLLM Documentation](https://docs.litellm.ai/docs/)
* [OpenInference LiteLLM Instrumentor](https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-litellm)
