Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:BerriAI Litellm Health Check Helpers

From Leeroopedia
Attribute Value
Sources litellm/litellm_core_utils/health_check_helpers.py
Domains Health Checks, Monitoring, Proxy
Last Updated 2026-02-15 16:00 GMT

Overview

Provides helper functions for executing health check calls across all supported LLM modes (chat, embedding, audio, image, video, rerank, realtime, batch, responses, OCR).

Description

The HealthCheckHelpers class contains static methods that support the LiteLLM proxy health check system:

  • ahealth_check_wildcard_models -- For wildcard model configurations (e.g., openai/*), this method picks the cheapest available chat models from the provider and runs a completion with fallbacks to verify connectivity.
  • _update_model_params_with_health_check_tracking_information -- Adds metadata tags and a service-account API key auth to health check requests so they can be identified and tracked in the database spend logs.
  • _get_metadata_for_health_check_call -- Returns the standard metadata dictionary used to tag health check calls.
  • get_mode_handlers -- Returns a dictionary mapping each supported mode string (e.g., "chat", "embedding", "audio_speech") to a lambda that invokes the appropriate litellm.a* async function with the correct parameters. This includes a built-in test PDF URL for OCR health checks.

Usage

Import HealthCheckHelpers when building or extending the proxy health check system. The get_mode_handlers method is the main entry point for obtaining callable handlers for each model mode.

Code Reference

Source Location

litellm/litellm_core_utils/health_check_helpers.py (193 lines)

Signature

class HealthCheckHelpers:
    @staticmethod
    async def ahealth_check_wildcard_models(
        model: str,
        custom_llm_provider: str,
        model_params: dict,
        litellm_logging_obj: "Logging",
    ) -> dict

    @staticmethod
    def _update_model_params_with_health_check_tracking_information(
        model_params: dict,
    ) -> dict

    @staticmethod
    def _get_metadata_for_health_check_call() -> dict

    @staticmethod
    def get_mode_handlers(
        model: str,
        custom_llm_provider: str,
        model_params: dict,
        prompt: Optional[str] = None,
        input: Optional[list] = None,
    ) -> Dict[Literal["chat", "completion", "embedding", "audio_speech",
                       "audio_transcription", "image_generation",
                       "video_generation", "rerank", "realtime", "batch",
                       "responses", "ocr"], Callable]

Import

from litellm.litellm_core_utils.health_check_helpers import HealthCheckHelpers

I/O Contract

ahealth_check_wildcard_models

Direction Name Type Description
Input model str Wildcard model name (e.g., "openai/*")
Input custom_llm_provider str Provider identifier (e.g., "openai")
Input model_params dict Parameters for the completion call
Input litellm_logging_obj Logging Logging object instance
Output return dict Empty dict on success
Output raises Exception If no models available or all fail

get_mode_handlers

Direction Name Type Description
Input model str The model name
Input custom_llm_provider str The LLM provider
Input model_params dict Model parameters
Input prompt Optional[str] Optional prompt text
Input input Optional[list] Optional input list (for embeddings)
Output return Dict[str, Callable] Dictionary mapping mode names to async handler lambdas

Usage Examples

from litellm.litellm_core_utils.health_check_helpers import HealthCheckHelpers

# Get mode handlers for a model
handlers = HealthCheckHelpers.get_mode_handlers(
    model="gpt-4",
    custom_llm_provider="openai",
    model_params={
        "model": "gpt-4",
        "messages": [{"role": "user", "content": "test"}],
        "max_tokens": 10,
    },
)

# Run the chat health check
import asyncio
result = asyncio.run(handlers["chat"]())

# Health check a wildcard model
async def check_wildcard():
    from litellm.litellm_core_utils.litellm_logging import Logging
    logging_obj = Logging(...)
    await HealthCheckHelpers.ahealth_check_wildcard_models(
        model="openai/*",
        custom_llm_provider="openai",
        model_params={"messages": [{"role": "user", "content": "test"}], "max_tokens": 10},
        litellm_logging_obj=logging_obj,
    )

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment