OpenInference liteLLM Instrumentation
Actively maintained. Last release 9 days ago, commits in 26 of the last 26 weeks. A safe choice.
pip install openinference-instrumentation-litellmOpenInference LiteLLM Instrumentation
LiteLLM allows developers to call all LLM APIs using the openAI format. LiteLLM Proxy is a proxy server to call 100+ LLMs in OpenAI format. Both are supported by this auto-instrumentation.
This package implements OpenInference tracing for the following LiteLLM functions:
- completion()
- acompletion()
- completion_with_retries()
- embedding()
- aembedding()
- image_generation()
- aimage_generation()
- anthropic.messages.create()
- anthropic.messages.acreate()
These traces are fully OpenTelemetry compatible and can be sent to an OpenTelemetry collector for viewing, such as Arize Phoenix or Arize AX.
Installation
pip install openinference-instrumentation-litellm
Quickstart
In a notebook environment (jupyter, colab, etc.) install openinference-instrumentation-litellm if you haven't already as well as arize-phoenix and litellm.
pip install openinference-instrumentation-litellm arize-phoenix litellm
First, import dependencies required to autoinstrument liteLLM and set up phoenix as an collector for OpenInference traces.
import litellm
import phoenix as px
from openinference.instrumentation.litellm import LiteLLMInstrumentor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
Next, we'll start a phoenix server and set it as a collector.
session = px.launch_app()
endpoint = "http://127.0.0.1:6006/v1/traces"
tracer_provider = TracerProvider()
tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))
Set up any API keys needed in you API calls. For example:
import os
os.environ["OPENAI_API_KEY"] = "PASTE_YOUR_API_KEY_HERE"