diff --git a/litellm/litellm_core_utils/health_check_utils.py b/litellm/litellm_core_utils/health_check_utils.py index ff252855f0d..874d260eba7 100644 --- a/litellm/litellm_core_utils/health_check_utils.py +++ b/litellm/litellm_core_utils/health_check_utils.py @@ -2,10 +2,29 @@ Utils used for litellm.ahealth_check() """ +#: litellm params that ``_update_litellm_params_for_health_check`` injects for +#: chat-completion health checks but that are invalid (or rejected) on every +#: other handler in :class:`HealthCheckHelpers.get_mode_handlers` — image and +#: video generation, embeddings, audio speech / transcription, rerank, ocr, +#: responses, batch, etc. ``messages`` is always chat-only; ``max_tokens`` is +#: chat/completion-only and is rejected by strict providers (e.g. OpenAI's +#: image-generation endpoints return 400 ``Unknown parameter: 'max_tokens'``). +_NON_CHAT_HEALTH_CHECK_STRIP_KEYS = {"messages", "max_tokens"} + def _filter_model_params(model_params: dict) -> dict: - """Remove 'messages' param from model params.""" - return {k: v for k, v in model_params.items() if k != "messages"} + """Strip chat-only params before invoking a non-chat health check handler. + + ``litellm.acompletion`` is the only mode handler that consumes + ``model_params`` unfiltered; every other handler routes through this + helper, so removing chat-completion-only keys here keeps strict providers + (OpenAI image generation, etc.) from rejecting the request. + """ + return { + k: v + for k, v in model_params.items() + if k not in _NON_CHAT_HEALTH_CHECK_STRIP_KEYS + } def _create_health_check_response(response_headers: dict) -> dict: