BerriAI/litellm · error · ImportError

objgraph not found. Please install objgraph to use this feat

Error message

objgraph not found. Please install objgraph to use this feature.

What it means

litellm/proxy/common_utils/debug_utils.py runs a block at import time when LITELLM_PROFILE is 'true': it imports objgraph to snapshot object growth and leaking objects. If objgraph is not installed, the ImportError is re-raised with this message. Because the block sits at module import, the proxy fails during startup, not per-request.

Source

Thrown at litellm/proxy/common_utils/debug_utils.py:100

    return {
        "total_active_tasks": len(active_tasks),
        "by_name": dict(counter),
    }


if os.environ.get("LITELLM_PROFILE", "false").lower() == "true":
    try:
        import objgraph

        print("growth of objects")  # noqa: T201
        objgraph.show_growth()
        print("\n\nMost common types")  # noqa: T201
        objgraph.show_most_common_types()
        roots: Final = objgraph.get_leaking_objects()
        print("\n\nLeaking objects")  # noqa: T201
        objgraph.show_most_common_types(objects=roots)
    except ImportError:
        raise ImportError("objgraph not found. Please install objgraph to use this feature.")

    tracemalloc.start(10)

    @router.get(
        "/memory-usage",
        dependencies=[Depends(user_api_key_auth)],
        include_in_schema=False,
    )
    async def memory_usage():
        # Take a snapshot of the current memory usage
        snapshot: Final = tracemalloc.take_snapshot()
        top_stats: Final = snapshot.statistics("lineno")
        verbose_proxy_logger.debug("TOP STATS: %s", top_stats)

        # Get the top 50 memory usage lines
        top_50: Final = top_stats[:50]
        result: Final = []
        for stat in top_50:

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Unset LITELLM_PROFILE (or set it to false) if you do not need memory profiling.
  2. Or install the dependency: pip install objgraph.
  3. If profiling is wanted in Docker, add objgraph to the image (custom Dockerfile with pip install objgraph).

Example fix

# before
export LITELLM_PROFILE=true
litellm --config config.yaml   # crashes: objgraph not found

# after (option A)
unset LITELLM_PROFILE
litellm --config config.yaml

# after (option B)
pip install objgraph
export LITELLM_PROFILE=true
litellm --config config.yaml
Defensive patterns

Strategy: validation

Validate before calling

import importlib.util, os

def profile_env_ok() -> bool:
    if os.environ.get("LITELLM_PROFILE", "false").lower() != "true":
        return True
    return importlib.util.find_spec("objgraph") is not None

assert profile_env_ok(), "install objgraph or unset LITELLM_PROFILE"

Prevention

When it happens

Trigger: Set LITELLM_PROFILE=true in the proxy environment on a host where objgraph is not installed, then start litellm proxy. The env check is case-insensitive ('true').

Common situations: A profiling flag left in a base Docker image or helm values. Someone follows a memory-debugging guide that says to set LITELLM_PROFILE=true but skips the dependency step. A shared .env file leaks the flag into CI.

Understand the failure class

Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.

Related errors


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