BerriAI/litellm · error · ValueError

LOGFIRE_TOKEN not found in environment variables

Error message

LOGFIRE_TOKEN not found in environment variables

What it means

Raised when the 'logfire' callback is initialized: before building the OTel HTTP exporter for Pydantic Logfire, LiteLLM requires LOGFIRE_TOKEN in os.environ and hard-fails otherwise. The token is used directly as an Authorization header against LOGFIRE_BASE_URL (default https://logfire-api.pydantic.dev), so without it the exporter could never authenticate.

Solutions

  1. Set LOGFIRE_TOKEN in the LiteLLM process environment (export LOGFIRE_TOKEN=... or env in compose).
  2. Optionally set LOGFIRE_BASE_URL for self-hosted Logfire.
  3. For the proxy, load it via config.yaml environment_vars or the process manager's env, then restart.
  4. Verify with printenv LOGFIRE_TOKEN inside the same process context.

Example fix

# before
import litellm
litellm.success_callback = ['logfire']  # ValueError: LOGFIRE_TOKEN not found

# after
import os
os.environ['LOGFIRE_TOKEN'] = 'your-logfire-token'
import litellm
litellm.success_callback = ['logfire']
Defensive patterns

Strategy: validation

Validate before calling

import os

if not os.environ.get('LOGFIRE_TOKEN'):
    raise RuntimeError('LOGFIRE_TOKEN must be set before enabling the logfire callback')

Try / catch

try:
    litellm.completion(model='gpt-4o', messages=m)
except ValueError as e:
    if 'LOGFIRE_TOKEN' in str(e):
        raise RuntimeError('Set LOGFIRE_TOKEN in the LiteLLM process environment and restart')
    raise

Prevention

When it happens

Trigger: callbacks/success_callback including 'logfire' (SDK or proxy config.yaml) in a process where LOGFIRE_TOKEN is unset; token defined only in a .env file that the proxy does not load; env var present on a dev machine but missing in the deployment container.

Common situations: Enabling logfire tracing after copying a config example; Docker/k8s deployments missing the secret; CI test runs; shell-exported var not reaching a daemonized uvicorn/gunicorn.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/5fc93ba65a202454. Report an issue: GitHub.

Appendix: source

Thrown at litellm/litellm_core_utils/litellm_logging.py:4112

            from litellm.integrations.vantage.vantage_logger import VantageLogger

            for callback in _in_memory_loggers:
                if isinstance(callback, VantageLogger):
                    return callback
            vantage_logger: Final = VantageLogger()
            _in_memory_loggers.append(vantage_logger)
            return vantage_logger
        elif logging_integration == "deepeval":
            for callback in _in_memory_loggers:
                if isinstance(callback, DeepEvalLogger):
                    return callback
            deepeval_logger: Final = DeepEvalLogger()
            _in_memory_loggers.append(deepeval_logger)
            return deepeval_logger

        elif logging_integration == "logfire":
            if "LOGFIRE_TOKEN" not in os.environ:
                raise ValueError("LOGFIRE_TOKEN not found in environment variables")
            from litellm.integrations.opentelemetry import (
                OpenTelemetry,
                OpenTelemetryConfig,
            )

            logfire_base_url: Final = os.getenv("LOGFIRE_BASE_URL", "https://logfire-api.pydantic.dev")
            otel_config = OpenTelemetryConfig(
                exporter="otlp_http",
                endpoint=f"{logfire_base_url.rstrip('/')}/v1/traces",
                headers=f"Authorization={os.getenv('LOGFIRE_TOKEN')}",
            )
            for callback in _in_memory_loggers:
                # Use exact type check to avoid matching ArizePhoenixLogger (subclass)
                if type(callback) is OpenTelemetry:
                    return callback
            _otel_logger = OpenTelemetry(config=otel_config)
            _in_memory_loggers.append(_otel_logger)
            return _otel_logger

View on GitHub (pinned to 77b7c6c40c)