{"library":"openinference-instrumentation-litellm","title":"OpenInference LiteLLM Instrumentation","description":"OpenInference LiteLLM Instrumentation provides automatic OpenTelemetry-compatible tracing for applications using the LiteLLM SDK or LiteLLM Proxy. It captures traces for various LiteLLM functions, including `completion()`, `acompletion()`, `embedding()`, and `image_generation()`. This library is part of the Arize AI OpenInference project, which maintains a frequent release cadence across its instrumentation packages, ensuring up-to-date support for various LLM frameworks and providers.","language":"python","status":"active","last_verified":"Sun May 17","install":{"commands":["pip install openinference-instrumentation-litellm litellm opentelemetry-sdk opentelemetry-exporter-otlp"],"cli":null},"imports":["from openinference.instrumentation.litellm import LiteLLMInstrumentor","from opentelemetry.sdk.trace import TracerProvider","from opentelemetry.sdk.trace.export import SimpleSpanProcessor","from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nimport litellm\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import SimpleSpanProcessor\nfrom opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter\nfrom opentelemetry.sdk.resources import Resource\nfrom openinference.instrumentation.litellm import LiteLLMInstrumentor\n\n# Configure OpenTelemetry Tracer Provider\nresource = Resource.create({\n    \"service.name\": \"my-litellm-app\"\n})\n\ntracer_provider = TracerProvider(resource=resource)\n\n# Example: Export traces to a local OpenTelemetry Collector (e.g., Phoenix)\n# Ensure a collector is running, e.g., 'python -m phoenix.server.main serve'\nOTEL_EXPORTER_OTLP_ENDPOINT = os.environ.get(\"OTEL_EXPORTER_OTLP_ENDPOINT\", \"http://127.0.0.1:6006/v1/traces\")\ntracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(OTEL_EXPORTER_OTLP_ENDPOINT)))\n\n# Set the global tracer provider\nfrom opentelemetry import trace\ntrace.set_tracer_provider(tracer_provider)\n\n# Instrument LiteLLM\nLiteLLMInstrumentor().instrument(tracer_provider=tracer_provider)\n\n# Set LiteLLM API key (e.g., for OpenAI model)\nos.environ[\"OPENAI_API_KEY\"] = os.environ.get(\"OPENAI_API_KEY\", \"YOUR_OPENAI_API_KEY_HERE\")\n\ntry:\n    print(\"Making a LiteLLM completion call...\")\n    completion_response = litellm.completion(\n        model=\"gpt-3.5-turbo\",\n        messages=[{\"content\": \"What's the capital of France?\", \"role\": \"user\"}]\n    )\n    print(\"Completion received:\", completion_response.choices[0].message.content)\n\n    print(\"\\nMaking a LiteLLM embedding call...\")\n    embedding_response = litellm.embedding(\n        model=\"text-embedding-ada-002\",\n        input=[\"Hello, world!\"]\n    )\n    print(\"Embedding received (first 10 chars):\", str(embedding_response.data[0].embedding)[:10] + \"...\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please ensure your API key is set correctly and the model is accessible.\")\n\nfinally:\n    # It's important to shut down the tracer provider to ensure all spans are exported.\n    print(\"\\nShutting down tracer provider...\")\n    tracer_provider.shutdown()\n    print(\"Traces exported.\")","lang":"python","description":"This quickstart demonstrates how to set up OpenInference LiteLLM Instrumentation with a basic OpenTelemetry configuration, making an LLM call via LiteLLM. It initializes a `TracerProvider`, configures an `OTLPSpanExporter` (e.g., for a local Phoenix collector), instruments LiteLLM, and then executes a sample `completion` and `embedding` call. Remember to set your `OPENAI_API_KEY` environment variable.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-17","installed_version":"0.1.28","pypi_latest":"0.1.33","is_stale":true,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":19.9,"avg_import_s":2.17,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"openinference-instrumentation-litellm","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.56,"mem_mb":16.3,"disk_size":"249.3M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"openinference-instrumentation-litellm","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":22.5,"import_time_s":0.42,"mem_mb":16.3,"disk_size":"229M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"openinference-instrumentation-litellm","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.82,"mem_mb":17.4,"disk_size":"268.2M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"openinference-instrumentation-litellm","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":19,"import_time_s":0.69,"mem_mb":17.4,"disk_size":"249M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"openinference-instrumentation-litellm","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.94,"mem_mb":17.7,"disk_size":"265.1M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"openinference-instrumentation-litellm","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":16.2,"import_time_s":0.95,"mem_mb":17.7,"disk_size":"245M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"openinference-instrumentation-litellm","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.96,"mem_mb":15.7,"disk_size":"265.1M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"openinference-instrumentation-litellm","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":16.9,"import_time_s":0.83,"mem_mb":15.7,"disk_size":"245M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"openinference-instrumentation-litellm","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":8.17,"mem_mb":107.5,"disk_size":"241.4M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"openinference-instrumentation-litellm","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":24.9,"import_time_s":7.37,"mem_mb":107.5,"disk_size":"222M"}]}}