BerriAI/litellm · error · ValueError

LANGTRACE_API_KEY not found in environment variables

Error message

LANGTRACE_API_KEY not found in environment variables

What it means

When constructing the 'langtrace' integration for the first time, LiteLLM requires LANGTRACE_API_KEY in the environment (used as the auth header for https://langtrace.ai/api/trace). Without it, OTel exporter construction is refused with this ValueError before any traces are sent.

Source

Thrown at litellm/litellm_core_utils/litellm_logging.py:4163

                _PROXY_DynamicRateLimitHandlerV3,
            )

            for callback in _in_memory_loggers:
                if isinstance(callback, _PROXY_DynamicRateLimitHandlerV3):
                    return callback

            if internal_usage_cache is None:
                raise Exception(f"Internal Error: Cache cannot be empty - internal_usage_cache={internal_usage_cache}")

            dynamic_rate_limiter_obj_v3 = _PROXY_DynamicRateLimitHandlerV3(internal_usage_cache=internal_usage_cache)

            if llm_router is not None and isinstance(llm_router, litellm.Router):
                dynamic_rate_limiter_obj_v3.update_variables(llm_router=llm_router)
            _in_memory_loggers.append(dynamic_rate_limiter_obj_v3)
            return dynamic_rate_limiter_obj_v3
        elif logging_integration == "langtrace":
            if "LANGTRACE_API_KEY" not in os.environ:
                raise ValueError("LANGTRACE_API_KEY not found in environment variables")
            _v2 = _maybe_construct_otel_v2("langtrace", _in_memory_loggers)
            if _v2 is not None:
                return _v2

            from litellm.integrations.opentelemetry import (
                OpenTelemetry,
                OpenTelemetryConfig,
            )

            otel_config = OpenTelemetryConfig(
                exporter="otlp_http",
                endpoint="https://langtrace.ai/api/trace",
            )
            os.environ["OTEL_EXPORTER_OTLP_TRACES_HEADERS"] = f"api_key={os.getenv('LANGTRACE_API_KEY')}"
            for callback in _in_memory_loggers:
                if isinstance(callback, OpenTelemetry) and callback.callback_name == "langtrace":
                    return callback
            _otel_logger = OpenTelemetry(config=otel_config, callback_name="langtrace")

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Set LANGTRACE_API_KEY in the LiteLLM proxy process environment and restart
  2. Verify with printenv LANGTRACE_API_KEY inside the exact container/pod running the proxy
  3. Inject via secrets manager (k8s secret, docker secrets) rather than shell exports for durable deploys
  4. Remove 'langtrace' from callbacks if tracing is not wanted in that environment

Example fix

# before
litellm_settings:
  callbacks: ["langtrace"]

# after
export LANGTRACE_API_KEY=<your-key>  # in the proxy's env (docker -e, k8s env, systemd)
litellm_settings:
  callbacks: ["langtrace"]
Defensive patterns

Strategy: validation

Validate before calling

import os
assert os.getenv('LANGTRACE_API_KEY'), 'LANGTRACE_API_KEY required for langtrace callback'

Prevention

When it happens

Trigger: callbacks: ['langtrace'] (config.yaml or LITELLM_CALLBACKS) enabled and the first request is logged in a process whose environment lacks LANGTRACE_API_KEY.

Common situations: Env var missing in containerized deployments; key present in CI but not prod; typo in the variable name; testing locally with callbacks enabled in a shared config.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/7bd747a222699bf4. Report an issue: GitHub.