* test: modernize models used in CircleCI e2e test suites
Replaces obsolete models (gpt-4o, gpt-4o-mini, gpt-3.5-turbo,
claude-3-5-sonnet-20240620, claude-sonnet-4-20250514) with current
equivalents across the e2e_openai_endpoints and
proxy_e2e_anthropic_messages_tests CircleCI jobs.
- gpt-4o -> gpt-5.5 (responses API e2e tests)
- gpt-4o-mini -> gpt-5-mini (websocket responses, oai_misc_config)
- gpt-4o-mini-2024-07-18 -> gpt-4.1-mini-2025-04-14 (fine-tuning,
still actively fine-tunable)
- gpt-4 / gpt-3.5-turbo target_model_names example -> gpt-5.5 /
gpt-5-mini
- bedrock claude-3-5-sonnet-20240620 batch entry -> haiku-4-5-20251001
(also aligning oai_misc_config model_name with what
test_bedrock_batches_api.py actually requests)
- bedrock claude-sonnet-4-20250514 (deprecated, retires 2026-06-15)
-> claude-sonnet-4-5-20250929
* test: point bedrock-claude-sonnet-4 alias at Sonnet 4.6, not 4.5
Greptile/Cursor flagged that after the previous commit, the
bedrock-claude-sonnet-4 alias collided with bedrock-claude-sonnet-4.5
(both pointed to claude-sonnet-4-5-20250929). Rename to
bedrock-claude-sonnet-4.6 and point it at the Sonnet 4.6 Bedrock ID
(us.anthropic.claude-sonnet-4-6, already in the litellm model
registry) so the alias name matches the underlying model version.
* test: modernize models across remaining CI-mounted configs & tests
Expands the modernization sweep to all CircleCI-mounted proxy configs
and to test directories where the model literal is a fixture/route key
(not the test's subject).
Config changes:
- proxy_server_config.yaml: bump gpt-3.5-turbo / gpt-3.5-turbo-1106 /
gpt-4o / gemini-1.5-flash / dall-e-3 underlying models; rename
gpt-3.5-turbo-end-user-test alias to gpt-5-mini-end-user-test; bump
text-embedding-ada-002 underlying to text-embedding-3-small. User-
facing aliases (gpt-3.5-turbo, gpt-4, text-embedding-ada-002, etc.)
preserved for backward compatibility with tests.
- simple_config.yaml, otel_test_config.yaml, spend_tracking_config.yaml:
bump gpt-3.5-turbo underlying to gpt-5-mini.
- pass_through_config.yaml: claude-3-5-sonnet / claude-3-7-sonnet /
claude-3-haiku entries replaced with claude-sonnet-4-5 / claude-
haiku-4-5 / claude-opus-4-7.
- oai_misc_config.yaml: align alias name with the gpt-5-mini rename.
Test changes (proactive: claude-sonnet-4-20250514 / claude-opus-4-
20250514 retire 2026-06-15):
- tests/llm_translation/test_anthropic_completion.py: bump 3 references
+ paired Vertex AI ID to claude-sonnet-4-5.
- tests/llm_translation/test_optional_params.py: bump 2 references.
- tests/pass_through_unit_tests/test_anthropic_messages_passthrough.py
and test_bedrock_anthropic_messages_test.py: bump router fixtures
using the deprecated model IDs.
- tests/pass_through_unit_tests/base_anthropic_messages_tool_search_test.py:
modernize docstring examples.
- tests/test_end_users.py: update references to renamed alias.
* test: modernize placeholder model literals in router_unit_tests
Mass replace_all on fixture/placeholder model literals across the
router_unit_tests/ suite (model name is a routing key / label, not the
test subject). Sub-agent sweep so far — additional commits will follow
for logging_callback_tests/, enterprise/, top-level tests/test_*.py,
and other CI-mounted dirs.
Mappings applied:
- gpt-3.5-turbo -> gpt-5-mini
- gpt-4 (bare) -> gpt-5.5
- gpt-4o (bare) -> gpt-5
- text-embedding-ada-002 -> text-embedding-3-small
- claude-3-sonnet-20240229 / claude-3-opus-20240229 /
claude-3-haiku-20240307 / claude-3-5-sonnet-20240620 ->
claude-sonnet-4-5-20250929 / claude-opus-4-7 /
claude-haiku-4-5-20251001 as appropriate
Explicitly preserved:
- gpt-4o-mini-* variants (transcribe, tts, etc.) where they're current
- gpt-4-turbo / gpt-4-vision-preview / gpt-4-0613 (subject literals)
- JSONL batch body literals
- Mock LLM response model fields (must match upstream)
- Fake/mock identifiers
* test: modernize placeholder model literals across remaining CI suites
Sub-agent sweep across logging_callback_tests/, guardrails_tests/,
enterprise/, pass_through_unit_tests/, otel_tests/,
llm_responses_api_testing/, batches_tests/, spend_tracking_tests/,
litellm_utils_tests/, unified_google_tests/, and a few top-level
tests/test_*.py files where the model literal is a fixture or
placeholder (router model_list, mock standard logging payload, mock
callback data) rather than the test's subject.
Mappings applied (see scope notes below):
- gpt-3.5-turbo -> gpt-5-mini
- gpt-4 (bare) -> gpt-5.5
- gpt-4o (bare) -> gpt-5.5 (corrected from initial gpt-5 — bare gpt-5
is not a valid OpenAI alias; only gpt-5.5 / gpt-5.4 / gpt-5.2-codex
/ gpt-5-mini exist)
- gpt-4o-mini (bare) -> gpt-5-mini
- text-embedding-ada-002 -> text-embedding-3-small
- claude-3-sonnet-20240229 -> claude-sonnet-4-5-20250929
- claude-3-opus-20240229 -> claude-opus-4-7
- claude-3-haiku-20240307 -> claude-haiku-4-5-20251001
- claude-3-5-sonnet-20240620/20241022 -> claude-sonnet-4-5-20250929
- claude-3-7-sonnet-20250219 -> claude-sonnet-4-6
- gemini-1.5-flash -> gemini-2.5-flash
- gemini-1.5-pro -> gemini-2.5-pro
Explicitly preserved (not modernized):
- llm_translation/ tests where model is the SUBJECT (provider-specific
translation/transformation logic). Only the deprecated 20250514
references were already bumped in a prior commit.
- Cost-calc / tokenizer subject tests in test_utils.py (skip-ranges
documented by the sub-agent).
- Bedrock model IDs in test_health_check.py path-stripping tests.
- JSONL batch request bodies and mock LLM response bodies (must match
upstream literal).
- Langfuse expected-request-body JSON fixtures (cost values are exact-
match-asserted; changing the model would shift response_cost).
- gpt-3.5-turbo-instruct (text-completion endpoint; no modern OpenAI
equivalent).
- Top-level tests calling the proxy through user-facing aliases
(gpt-3.5-turbo, gpt-4, text-embedding-ada-002, dall-e-3) — aliases
in proxy_server_config.yaml stay; only the underlying model was
bumped.
- tests/test_gpt5_azure_temperature_support.py (the test's whole point
is model-name handling).
- Fake / mock / openai/fake identifiers.
Notable side fixes:
- test_spend_accuracy_tests.py: UPSTREAM_MODEL now matches what
spend_tracking_config.yaml's proxy actually routes to (gpt-5-mini),
resolving a latent inconsistency.
- proxy_server_config.yaml: bare `gpt-5` alias renamed to `gpt-5.5`
(bare gpt-5 is not a valid OpenAI alias).
- test_batches_logging_unit_tests.py: explicit_models list entries
kept distinct (gpt-5-mini + gpt-5.5) after bulk rename.
* test: fix CI failures from model modernization sweep
CI surfaced 4 categories of regression from the bulk modernization:
1. Azure deployment names are customer-specific. Reverted:
- tests/litellm_utils_tests/test_health_check.py: azure/text-
embedding-3-small -> azure/text-embedding-ada-002 (the CI Azure
account does not have a text-embedding-3-small deployment).
- tests/logging_callback_tests/test_custom_callback_router.py:
same revert for two router fixtures driving aembedding.
2. gpt-5 family does not accept temperature != 1. Tests that pass a
custom temperature swapped from gpt-5-mini to gpt-4.1-mini (modern
non-reasoning OpenAI mini that still accepts temperature/logprobs):
- tests/logging_callback_tests/test_datadog.py
- tests/logging_callback_tests/test_langsmith_unit_test.py
- tests/logging_callback_tests/test_otel_logging.py
3. proxy_server_config.yaml's gpt-3.5-turbo-large alias was routing to
gpt-5.5 (a reasoning model that rejects logprobs). The proxy test
tests/test_openai_endpoints.py::test_chat_completion_streaming
exercises logprobs/top_logprobs through that alias. Bumped the
underlying model to gpt-4.1 (non-reasoning, still modern).
4. tests/logging_callback_tests/test_gcs_pub_sub.py asserts against a
pinned JSON fixture (gcs_pub_sub_body/spend_logs_payload.json) with
hardcoded model="gpt-4o" and a model-specific spend value. Reverted
the litellm.acompletion calls in the test to model="gpt-4o" so the
fixture's exact-match assertions still hold.
5. tests/pass_through_unit_tests/test_anthropic_messages_passthrough.py:
anthropic.messages.create routing to openai/gpt-5-mini returned an
empty content[0] with max_tokens=100 (reasoning-token consumption).
Swapped to openai/gpt-4.1-mini.
* test: fix Assistants API model + 2 cursor[bot] review nits
1. pass_through_unit_tests/test_custom_logger_passthrough.py: gpt-5.5
isn't accepted by the /v1/assistants endpoint
("unsupported_model"). Switch to gpt-4.1-mini (modern, Assistants-
API-supported, non-reasoning).
2. example_config_yaml/pass_through_config.yaml: the previous sweep
bumped the claude-3-7-sonnet alias to claude-opus-4-7, which is a
tier change (Sonnet -> Opus). Map to claude-sonnet-4-6 to keep the
Sonnet tier intact. (Cursor bugbot review.)
3. example_config_yaml/simple_config.yaml: model_name was left as
gpt-3.5-turbo while the underlying was bumped to gpt-5-mini, which
muddles the "simple" example. Make both sides gpt-5-mini so the
most basic example is a straight 1:1 mapping again. (Cursor bugbot
review.)
* fix: revert gpt-4/gpt-3.5-turbo alias underlying to non-reasoning models
tests/test_openai_endpoints.py::test_completion calls the proxy alias
"gpt-4" with temperature=0, and other tests call gpt-3.5-turbo with
custom temperature / logprobs / the legacy /v1/completions endpoint.
The earlier modernization mapped both aliases to gpt-5.5 / gpt-5-mini,
which are reasoning models that reject temperature != 1 and don't
expose /v1/completions. Map the aliases to gpt-4.1 / gpt-4.1-mini
(modern non-reasoning OpenAI models) instead — keeps user-facing
aliases preserved while picking a current underlying that still
supports the parameters/endpoints the tests exercise.
839 lines
28 KiB
Python
839 lines
28 KiB
Python
#### What this tests ####
|
|
# This tests if ahealth_check() actually works
|
|
|
|
import os
|
|
import sys
|
|
|
|
import pytest
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
sys.path.insert(
|
|
0, os.path.abspath("../..")
|
|
) # Adds the parent directory to the system path
|
|
import asyncio
|
|
|
|
import litellm
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_azure_health_check():
|
|
response = await litellm.ahealth_check(
|
|
model_params={
|
|
"model": "azure/gpt-4.1-mini",
|
|
"messages": [{"role": "user", "content": "Hey, how's it going?"}],
|
|
"api_key": os.getenv("AZURE_AI_API_KEY"),
|
|
"api_base": os.getenv("AZURE_AI_API_BASE"),
|
|
"api_version": os.getenv("AZURE_AI_API_VERSION"),
|
|
}
|
|
)
|
|
print(f"response: {response}")
|
|
|
|
assert "x-ratelimit-remaining-tokens" in response
|
|
return response
|
|
|
|
|
|
# asyncio.run(test_azure_health_check())
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_text_completion_health_check():
|
|
response = await litellm.ahealth_check(
|
|
model_params={"model": "gpt-3.5-turbo-instruct"},
|
|
mode="completion",
|
|
prompt="What's the weather in SF?",
|
|
)
|
|
print(f"response: {response}")
|
|
return response
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_azure_embedding_health_check():
|
|
response = await litellm.ahealth_check(
|
|
model_params={
|
|
"model": "azure/text-embedding-ada-002",
|
|
"api_key": os.getenv("AZURE_AI_API_KEY"),
|
|
"api_base": os.getenv("AZURE_AI_API_BASE"),
|
|
"api_version": os.getenv("AZURE_AI_API_VERSION"),
|
|
},
|
|
input=["test for litellm"],
|
|
mode="embedding",
|
|
)
|
|
print(f"response: {response}")
|
|
|
|
assert "x-ratelimit-remaining-tokens" in response
|
|
return response
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_openai_img_gen_health_check():
|
|
response = await litellm.ahealth_check(
|
|
model_params={
|
|
"model": "gpt-image-1",
|
|
"api_key": os.getenv("OPENAI_API_KEY"),
|
|
},
|
|
mode="image_generation",
|
|
prompt="cute baby sea otter",
|
|
)
|
|
print(f"response: {response}")
|
|
|
|
assert isinstance(response, dict) and "error" not in response
|
|
return response
|
|
|
|
|
|
# asyncio.run(test_openai_img_gen_health_check())
|
|
|
|
|
|
@pytest.mark.skip(
|
|
reason="Azure DALL-E 3 model deployment is deprecated (410 ModelDeprecated)"
|
|
)
|
|
@pytest.mark.asyncio
|
|
async def test_azure_img_gen_health_check():
|
|
"""
|
|
Test Azure image generation health check with retry logic for transient errors.
|
|
Azure sometimes returns internal server errors which are transient and not something we can control.
|
|
"""
|
|
litellm._turn_on_debug()
|
|
max_retries = 3
|
|
retry_delay = 1 # Start with 1 second delay
|
|
|
|
for attempt in range(max_retries):
|
|
response = await litellm.ahealth_check(
|
|
model_params={
|
|
"model": "azure/gpt-image-1",
|
|
"api_base": os.getenv("AZURE_AI_API_BASE"),
|
|
"api_key": os.getenv("AZURE_AI_API_KEY"),
|
|
},
|
|
mode="image_generation",
|
|
prompt="cute baby sea otter",
|
|
)
|
|
|
|
# Check if response is successful (no error)
|
|
if isinstance(response, dict) and "error" not in response:
|
|
return response
|
|
|
|
# Check if error is a transient Azure internal server error
|
|
error_str = str(response.get("error", "")).lower()
|
|
is_transient_error = (
|
|
"internalservererror" in error_str
|
|
or "internal server error" in error_str
|
|
or "internalfailure" in error_str
|
|
or "internal failure" in error_str
|
|
)
|
|
|
|
# If it's the last attempt or not a transient error, fail the test
|
|
if attempt == max_retries - 1 or not is_transient_error:
|
|
assert (
|
|
isinstance(response, dict) and "error" not in response
|
|
), f"Health check failed: {response.get('error', 'Unknown error')}"
|
|
return response
|
|
|
|
# Wait before retrying with exponential backoff
|
|
await asyncio.sleep(retry_delay)
|
|
retry_delay *= 2 # Exponential backoff
|
|
|
|
# Should not reach here, but just in case
|
|
assert False, "Health check failed after all retries"
|
|
|
|
|
|
@pytest.mark.skip(reason="AWS Suspended Account")
|
|
@pytest.mark.asyncio
|
|
async def test_sagemaker_embedding_health_check():
|
|
response = await litellm.ahealth_check(
|
|
model_params={
|
|
"model": "sagemaker/berri-benchmarking-gpt-j-6b-fp16",
|
|
"messages": [{"role": "user", "content": "Hey, how's it going?"}],
|
|
},
|
|
mode="embedding",
|
|
input=["test from litellm"],
|
|
)
|
|
print(f"response: {response}")
|
|
|
|
assert isinstance(response, dict)
|
|
return response
|
|
|
|
|
|
# asyncio.run(test_sagemaker_embedding_health_check())
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_groq_health_check():
|
|
"""
|
|
This should not fail
|
|
|
|
ensure that provider wildcard model passes health check
|
|
"""
|
|
litellm.set_verbose = True
|
|
response = await litellm.ahealth_check(
|
|
model_params={
|
|
"api_key": os.environ.get("GROQ_API_KEY"),
|
|
"model": "groq/*",
|
|
"messages": [{"role": "user", "content": "What's 1 + 1?"}],
|
|
},
|
|
mode=None,
|
|
prompt="What's 1 + 1?",
|
|
input=["test from litellm"],
|
|
)
|
|
print(f"response: {response}")
|
|
assert response == {}
|
|
|
|
return response
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_cohere_rerank_health_check():
|
|
response = await litellm.ahealth_check(
|
|
model_params={
|
|
"model": "cohere/rerank-english-v3.0",
|
|
"api_key": os.getenv("COHERE_API_KEY"),
|
|
},
|
|
mode="rerank",
|
|
prompt="Hey, how's it going",
|
|
)
|
|
|
|
assert "error" not in response
|
|
|
|
print(response)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_audio_speech_health_check():
|
|
response = await litellm.ahealth_check(
|
|
model_params={
|
|
"model": "openai/tts-1",
|
|
"api_key": os.getenv("OPENAI_API_KEY"),
|
|
},
|
|
mode="audio_speech",
|
|
prompt="Hey",
|
|
)
|
|
|
|
assert "error" not in response
|
|
|
|
print(response)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_audio_speech_health_check_with_another_voice():
|
|
response = await litellm.ahealth_check(
|
|
model_params={
|
|
"model": "openai/tts-1",
|
|
"api_key": os.getenv("OPENAI_API_KEY"),
|
|
"health_check_voice": "en-US-JennyNeural",
|
|
},
|
|
mode="audio_speech",
|
|
prompt="Hey",
|
|
)
|
|
|
|
assert "error" not in response
|
|
|
|
print(response)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_audio_transcription_health_check():
|
|
litellm.set_verbose = True
|
|
response = await litellm.ahealth_check(
|
|
model_params={
|
|
"model": "openai/whisper-1",
|
|
"api_key": os.getenv("OPENAI_API_KEY"),
|
|
},
|
|
mode="audio_transcription",
|
|
)
|
|
|
|
print(f"response: {response}")
|
|
|
|
assert "error" not in response
|
|
|
|
print(response)
|
|
|
|
|
|
def test_update_litellm_params_for_health_check():
|
|
"""
|
|
Test if _update_litellm_params_for_health_check correctly:
|
|
1. Updates messages with a random message
|
|
2. Updates model name when health_check_model is provided
|
|
3. Updates voice when health_check_voice is provided for audio_speech mode
|
|
"""
|
|
from litellm.proxy.health_check import _update_litellm_params_for_health_check
|
|
|
|
# Test with health_check_model
|
|
model_info = {"health_check_model": "gpt-5-mini"}
|
|
litellm_params = {
|
|
"model": "gpt-5.5",
|
|
"api_key": "fake_key",
|
|
}
|
|
|
|
updated_params = _update_litellm_params_for_health_check(model_info, litellm_params)
|
|
|
|
assert "messages" in updated_params
|
|
assert isinstance(updated_params["messages"], list)
|
|
assert updated_params["model"] == "gpt-5-mini"
|
|
|
|
# Test without health_check_model
|
|
model_info = {}
|
|
litellm_params = {
|
|
"model": "gpt-5.5",
|
|
"api_key": "fake_key",
|
|
}
|
|
|
|
updated_params = _update_litellm_params_for_health_check(model_info, litellm_params)
|
|
|
|
assert "messages" in updated_params
|
|
assert isinstance(updated_params["messages"], list)
|
|
assert updated_params["model"] == "gpt-5.5"
|
|
|
|
# Test with health_check_voice for audio_speech mode
|
|
model_info = {"mode": "audio_speech", "health_check_voice": "en-US-JennyNeural"}
|
|
litellm_params = {
|
|
"model": "gpt-5.5",
|
|
"api_key": "fake_key",
|
|
}
|
|
updated_params = _update_litellm_params_for_health_check(model_info, litellm_params)
|
|
assert "voice" in updated_params
|
|
assert updated_params["voice"] == "en-US-JennyNeural"
|
|
|
|
# Test without health_check_voice for audio_speech mode
|
|
model_info = {"mode": "audio_speech"}
|
|
litellm_params = {
|
|
"model": "gpt-5.5",
|
|
"api_key": "fake_key",
|
|
}
|
|
updated_params = _update_litellm_params_for_health_check(model_info, litellm_params)
|
|
assert "voice" in updated_params
|
|
assert updated_params["voice"] == "alloy"
|
|
|
|
# Test with health_check_voice for non-audio_speech mode
|
|
model_info = {"mode": "chat", "health_check_voice": "en-US-JennyNeural"}
|
|
litellm_params = {
|
|
"model": "gpt-5.5",
|
|
"api_key": "fake_key",
|
|
}
|
|
updated_params = _update_litellm_params_for_health_check(model_info, litellm_params)
|
|
assert "voice" not in updated_params
|
|
|
|
# Test with Bedrock model with region routing - should strip bedrock/ and region/ prefix
|
|
# Issue #15807: Fixes health checks sending "region/model" as model ID to AWS
|
|
model_info = {}
|
|
litellm_params = {
|
|
"model": "bedrock/us-gov-west-1/anthropic.claude-sonnet-4-5-20250929-v1:0",
|
|
"api_key": "fake_key",
|
|
}
|
|
updated_params = _update_litellm_params_for_health_check(model_info, litellm_params)
|
|
assert updated_params["model"] == "anthropic.claude-sonnet-4-5-20250929-v1:0"
|
|
|
|
# Test with Bedrock cross-region inference profile - should preserve the inference profile prefix
|
|
# AWS requires inference profile IDs like "us.anthropic.claude..." for cross-region routing
|
|
litellm_params = {
|
|
"model": "bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0",
|
|
"api_key": "fake_key",
|
|
}
|
|
updated_params = _update_litellm_params_for_health_check(model_info, litellm_params)
|
|
assert updated_params["model"] == "us.anthropic.claude-haiku-4-5-20251001-v1:0"
|
|
|
|
# Test with Bedrock model without region routing - should just strip bedrock/ prefix
|
|
litellm_params = {
|
|
"model": "bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0",
|
|
"api_key": "fake_key",
|
|
}
|
|
updated_params = _update_litellm_params_for_health_check(model_info, litellm_params)
|
|
assert updated_params["model"] == "us.anthropic.claude-haiku-4-5-20251001-v1:0"
|
|
|
|
# Test that non-Bedrock models are not affected by Bedrock-specific logic
|
|
litellm_params = {
|
|
"model": "openai/gpt-5.5",
|
|
"api_key": "fake_key",
|
|
}
|
|
updated_params = _update_litellm_params_for_health_check(model_info, litellm_params)
|
|
assert updated_params["model"] == "openai/gpt-5.5" # Should remain unchanged
|
|
|
|
# Test ALL cross-region inference profile prefixes (CRIS)
|
|
cris_prefixes = ["us.", "eu.", "apac.", "jp.", "au.", "us-gov.", "global."]
|
|
for prefix in cris_prefixes:
|
|
litellm_params = {
|
|
"model": f"bedrock/{prefix}anthropic.claude-3-haiku-20240307-v1:0",
|
|
"api_key": "fake_key",
|
|
}
|
|
updated_params = _update_litellm_params_for_health_check(
|
|
model_info, litellm_params
|
|
)
|
|
assert (
|
|
updated_params["model"] == f"{prefix}anthropic.claude-3-haiku-20240307-v1:0"
|
|
), f"Failed to preserve CRIS prefix: {prefix}"
|
|
|
|
# Test regional + CRIS combination - region should be stripped, CRIS preserved
|
|
litellm_params = {
|
|
"model": "bedrock/us-east-2/us.anthropic.claude-3-haiku-20240307-v1:0",
|
|
"api_key": "fake_key",
|
|
}
|
|
updated_params = _update_litellm_params_for_health_check(model_info, litellm_params)
|
|
assert updated_params["model"] == "us.anthropic.claude-3-haiku-20240307-v1:0"
|
|
|
|
# Test GovCloud regions
|
|
litellm_params = {
|
|
"model": "bedrock/us-gov-east-1/anthropic.claude-instant-v1",
|
|
"api_key": "fake_key",
|
|
}
|
|
updated_params = _update_litellm_params_for_health_check(model_info, litellm_params)
|
|
assert updated_params["model"] == "anthropic.claude-instant-v1"
|
|
|
|
# Test imported models with handler prefixes - handlers should be preserved
|
|
litellm_params = {
|
|
"model": "bedrock/llama/arn:aws:bedrock:us-east-1:123:imported-model/abc",
|
|
"api_key": "fake_key",
|
|
}
|
|
updated_params = _update_litellm_params_for_health_check(model_info, litellm_params)
|
|
assert (
|
|
updated_params["model"]
|
|
== "llama/arn:aws:bedrock:us-east-1:123:imported-model/abc"
|
|
)
|
|
|
|
litellm_params = {
|
|
"model": "bedrock/deepseek_r1/arn:aws:bedrock:us-west-2:456:imported-model/xyz",
|
|
"api_key": "fake_key",
|
|
}
|
|
updated_params = _update_litellm_params_for_health_check(model_info, litellm_params)
|
|
assert (
|
|
updated_params["model"]
|
|
== "deepseek_r1/arn:aws:bedrock:us-west-2:456:imported-model/xyz"
|
|
)
|
|
|
|
# Test route specifications - routes should be preserved
|
|
litellm_params = {
|
|
"model": "bedrock/converse/us.anthropic.claude-haiku-4-5-20251001-v1:0",
|
|
"api_key": "fake_key",
|
|
}
|
|
updated_params = _update_litellm_params_for_health_check(model_info, litellm_params)
|
|
assert (
|
|
updated_params["model"]
|
|
== "converse/us.anthropic.claude-haiku-4-5-20251001-v1:0"
|
|
)
|
|
|
|
litellm_params = {
|
|
"model": "bedrock/invoke/us-west-2/anthropic.claude-instant-v1",
|
|
"api_key": "fake_key",
|
|
}
|
|
updated_params = _update_litellm_params_for_health_check(model_info, litellm_params)
|
|
assert updated_params["model"] == "invoke/anthropic.claude-instant-v1"
|
|
|
|
# Test ARN formats - should be preserved
|
|
litellm_params = {
|
|
"model": "bedrock/arn:aws:bedrock:eu-central-1:000:application-inference-profile/abc",
|
|
"api_key": "fake_key",
|
|
}
|
|
updated_params = _update_litellm_params_for_health_check(model_info, litellm_params)
|
|
assert (
|
|
updated_params["model"]
|
|
== "arn:aws:bedrock:eu-central-1:000:application-inference-profile/abc"
|
|
)
|
|
|
|
# Test edge case: region + handler + ARN
|
|
litellm_params = {
|
|
"model": "bedrock/us-west-2/llama/arn:aws:bedrock:us-east-1:123:imported-model/abc",
|
|
"api_key": "fake_key",
|
|
}
|
|
updated_params = _update_litellm_params_for_health_check(model_info, litellm_params)
|
|
assert (
|
|
updated_params["model"]
|
|
== "llama/arn:aws:bedrock:us-east-1:123:imported-model/abc"
|
|
)
|
|
|
|
# Test edge case: route + region + CRIS
|
|
litellm_params = {
|
|
"model": "bedrock/converse/us-west-2/eu.anthropic.claude-3-sonnet-20240229-v1:0",
|
|
"api_key": "fake_key",
|
|
}
|
|
updated_params = _update_litellm_params_for_health_check(model_info, litellm_params)
|
|
assert (
|
|
updated_params["model"] == "converse/eu.anthropic.claude-3-sonnet-20240229-v1:0"
|
|
)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_perform_health_check_filters_by_model_id():
|
|
"""
|
|
When model_id is passed, only that deployment is checked (not all deployments
|
|
that share the same model name).
|
|
"""
|
|
from litellm.proxy.health_check import perform_health_check
|
|
|
|
# Two deployments with same model_name but different ids
|
|
model_list = [
|
|
{
|
|
"model_name": "gpt-5.5",
|
|
"model_info": {"id": "deployment-id-1"},
|
|
"litellm_params": {"model": "gpt-5.5", "api_key": "fake-key-1"},
|
|
},
|
|
{
|
|
"model_name": "gpt-5.5",
|
|
"model_info": {"id": "deployment-id-2"},
|
|
"litellm_params": {"model": "gpt-5.5", "api_key": "fake-key-2"},
|
|
},
|
|
]
|
|
|
|
captured_list = []
|
|
|
|
async def mock_perform_health_check(m_list, details=True, **kwargs):
|
|
captured_list.append(m_list)
|
|
return (
|
|
[{"model": "gpt-5.5", "api_key": m_list[0]["litellm_params"]["api_key"]}],
|
|
[],
|
|
{},
|
|
)
|
|
|
|
with patch(
|
|
"litellm.proxy.health_check._perform_health_check",
|
|
side_effect=mock_perform_health_check,
|
|
):
|
|
healthy_endpoints, unhealthy_endpoints, _ = await perform_health_check(
|
|
model_list=model_list, model_id="deployment-id-2", details=True
|
|
)
|
|
|
|
# Only one deployment (deployment-id-2) should have been passed to _perform_health_check
|
|
assert len(captured_list) == 1
|
|
assert len(captured_list[0]) == 1
|
|
assert (captured_list[0][0].get("model_info") or {}).get("id") == "deployment-id-2"
|
|
assert len(healthy_endpoints) == 1
|
|
assert healthy_endpoints[0]["api_key"] == "fake-key-2"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_perform_health_check_skip_disabled_background_models():
|
|
from litellm.proxy.health_check import perform_health_check
|
|
|
|
model_list = [
|
|
{
|
|
"model_name": "a",
|
|
"model_info": {"id": "id-a"},
|
|
"litellm_params": {"model": "m-a", "api_key": "k1"},
|
|
},
|
|
{
|
|
"model_name": "b",
|
|
"model_info": {
|
|
"id": "id-b",
|
|
"disable_background_health_check": True,
|
|
},
|
|
"litellm_params": {"model": "m-b", "api_key": "k2"},
|
|
},
|
|
]
|
|
captured = []
|
|
|
|
async def mock_inner(m_list, details=True, **kwargs):
|
|
captured.append(list(m_list))
|
|
return [], [], {}
|
|
|
|
with patch(
|
|
"litellm.proxy.health_check._perform_health_check",
|
|
side_effect=mock_inner,
|
|
):
|
|
await perform_health_check(
|
|
model_list=model_list,
|
|
health_check_skip_disabled_background_models=True,
|
|
)
|
|
|
|
assert len(captured) == 1
|
|
assert len(captured[0]) == 1
|
|
assert captured[0][0]["model_name"] == "a"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_perform_health_check_with_health_check_model():
|
|
"""
|
|
Test if _perform_health_check correctly uses `health_check_model` when model=`openai/*`:
|
|
1. Verifies that health_check_model overrides the original model when model=`openai/*`
|
|
2. Ensures the health check is performed with the override model
|
|
"""
|
|
from litellm.proxy.health_check import _perform_health_check
|
|
|
|
# Mock model list with health_check_model specified
|
|
model_list = [
|
|
{
|
|
"litellm_params": {"model": "openai/*", "api_key": "fake-key"},
|
|
"model_info": {
|
|
"mode": "chat",
|
|
"health_check_model": "openai/gpt-5-mini", # Override model for health check
|
|
},
|
|
}
|
|
]
|
|
|
|
# Track which model is actually used in the health check
|
|
health_check_calls = []
|
|
|
|
async def mock_health_check(litellm_params, **kwargs):
|
|
health_check_calls.append(litellm_params["model"])
|
|
return {"status": "healthy"}
|
|
|
|
with patch("litellm.ahealth_check", side_effect=mock_health_check):
|
|
healthy_endpoints, unhealthy_endpoints, _ = await _perform_health_check(
|
|
model_list
|
|
)
|
|
print("health check calls: ", health_check_calls)
|
|
|
|
# Verify the health check used the override model
|
|
assert health_check_calls[0] == "openai/gpt-5-mini"
|
|
# Verify the result still shows the original model
|
|
print("healthy endpoints: ", healthy_endpoints)
|
|
assert healthy_endpoints[0]["model"] == "openai/gpt-5-mini"
|
|
assert len(healthy_endpoints) == 1
|
|
assert len(unhealthy_endpoints) == 0
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_health_check_bad_model():
|
|
from litellm.proxy.health_check import _perform_health_check
|
|
import time
|
|
|
|
model_list = [
|
|
{
|
|
"model_name": "openai-gpt-4o",
|
|
"litellm_params": {
|
|
"api_key": "sk-1234",
|
|
"api_base": "https://exampleopenaiendpoint-production.up.railway.app",
|
|
"model": "openai/my-fake-openai-endpoint",
|
|
"mock_timeout": True,
|
|
"timeout": 60,
|
|
},
|
|
"model_info": {
|
|
"id": "ca27ca2eeea2f9e38bb274ead831948a26621a3738d06f1797253f0e6c4278c0",
|
|
"db_model": False,
|
|
"health_check_timeout": 1,
|
|
},
|
|
},
|
|
]
|
|
details = None
|
|
healthy_endpoints, unhealthy_endpoints, _ = await _perform_health_check(
|
|
model_list, details
|
|
)
|
|
print(f"healthy_endpoints: {healthy_endpoints}")
|
|
print(f"unhealthy_endpoints: {unhealthy_endpoints}")
|
|
|
|
# Track which model is actually used in the health check
|
|
health_check_calls = []
|
|
|
|
async def mock_health_check(litellm_params, **kwargs):
|
|
health_check_calls.append(litellm_params["model"])
|
|
await asyncio.sleep(10)
|
|
return {"status": "healthy"}
|
|
|
|
with patch(
|
|
"litellm.ahealth_check", side_effect=mock_health_check
|
|
) as mock_health_check:
|
|
start_time = time.time()
|
|
healthy_endpoints, unhealthy_endpoints, _ = await _perform_health_check(
|
|
model_list
|
|
)
|
|
end_time = time.time()
|
|
print("health check calls: ", health_check_calls)
|
|
assert len(healthy_endpoints) == 0
|
|
assert len(unhealthy_endpoints) == 1
|
|
assert (
|
|
end_time - start_time < 2
|
|
), "Health check took longer than health_check_timeout"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_health_check_respects_concurrency_limit():
|
|
from litellm.proxy.health_check import _perform_health_check
|
|
|
|
model_list = [
|
|
{"litellm_params": {"model": f"openai/gpt-4o-mini-{i}", "api_key": "fake-key"}}
|
|
for i in range(6)
|
|
]
|
|
|
|
active = 0
|
|
max_active = 0
|
|
|
|
async def mock_health_check(litellm_params, **kwargs):
|
|
nonlocal active, max_active
|
|
active += 1
|
|
max_active = max(max_active, active)
|
|
await asyncio.sleep(0.05)
|
|
active -= 1
|
|
return {"status": "healthy"}
|
|
|
|
with patch("litellm.ahealth_check", side_effect=mock_health_check):
|
|
await _perform_health_check(model_list, max_concurrency=2)
|
|
|
|
assert max_active <= 2
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_health_check_creates_only_bounded_initial_tasks():
|
|
from litellm.proxy.health_check import _perform_health_check
|
|
|
|
model_list = [
|
|
{"litellm_params": {"model": f"openai/gpt-4o-mini-{i}", "api_key": "fake-key"}}
|
|
for i in range(10)
|
|
]
|
|
release_event = asyncio.Event()
|
|
create_task_call_count = 0
|
|
real_create_task = asyncio.create_task
|
|
|
|
async def mock_health_check(litellm_params, **kwargs):
|
|
await release_event.wait()
|
|
return {"status": "healthy"}
|
|
|
|
def tracked_create_task(coro):
|
|
nonlocal create_task_call_count
|
|
create_task_call_count += 1
|
|
return real_create_task(coro)
|
|
|
|
with (
|
|
patch("litellm.ahealth_check", side_effect=mock_health_check),
|
|
patch(
|
|
"litellm.proxy.health_check.asyncio.create_task",
|
|
side_effect=tracked_create_task,
|
|
),
|
|
):
|
|
perform_task = real_create_task(
|
|
_perform_health_check(model_list, max_concurrency=2)
|
|
)
|
|
await asyncio.sleep(0.05)
|
|
assert create_task_call_count == 2
|
|
release_event.set()
|
|
await perform_task
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_timeout_does_not_cancel_other_health_checks():
|
|
from litellm.proxy.health_check import _perform_health_check
|
|
|
|
model_list = [
|
|
{
|
|
"litellm_params": {"model": "openai/slow-model", "api_key": "fake-key"},
|
|
"model_info": {"health_check_timeout": 0.05},
|
|
},
|
|
{
|
|
"litellm_params": {"model": "openai/fast-model", "api_key": "fake-key"},
|
|
"model_info": {"health_check_timeout": 1},
|
|
},
|
|
]
|
|
|
|
async def mock_health_check(litellm_params, **kwargs):
|
|
if litellm_params["model"] == "openai/slow-model":
|
|
await asyncio.sleep(0.2)
|
|
return {"status": "healthy"}
|
|
await asyncio.sleep(0.01)
|
|
return {"status": "healthy"}
|
|
|
|
with patch("litellm.ahealth_check", side_effect=mock_health_check):
|
|
healthy_endpoints, unhealthy_endpoints, _ = await _perform_health_check(
|
|
model_list, max_concurrency=1
|
|
)
|
|
|
|
healthy_models = {endpoint["model"] for endpoint in healthy_endpoints}
|
|
unhealthy_models = {endpoint["model"] for endpoint in unhealthy_endpoints}
|
|
|
|
assert "openai/fast-model" in healthy_models
|
|
assert "openai/slow-model" in unhealthy_models
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_ahealth_check_ocr():
|
|
litellm._turn_on_debug()
|
|
response = await litellm.ahealth_check(
|
|
model_params={
|
|
"model": "mistral/mistral-ocr-latest",
|
|
"api_key": os.getenv("MISTRAL_API_KEY"),
|
|
},
|
|
mode="ocr",
|
|
)
|
|
print(response)
|
|
return response
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_image_generation_health_check_prompt(monkeypatch):
|
|
"""Health checks should respect default and environment-configured prompts."""
|
|
|
|
import importlib
|
|
import litellm.constants as litellm_constants
|
|
import litellm.proxy.health_check as health_check
|
|
|
|
def reload_modules():
|
|
reloaded_constants = importlib.reload(litellm_constants)
|
|
reloaded_health_check = importlib.reload(health_check)
|
|
return reloaded_constants, reloaded_health_check
|
|
|
|
async def run_health_check(health_check_module):
|
|
health_check_calls = []
|
|
|
|
async def mock_health_check(litellm_params, mode=None, prompt=None, input=None):
|
|
health_check_calls.append(
|
|
{
|
|
"mode": mode,
|
|
"prompt": prompt,
|
|
"model": litellm_params.get("model"),
|
|
}
|
|
)
|
|
return {"status": "healthy"}
|
|
|
|
model_list = [
|
|
{
|
|
"litellm_params": {"model": "gpt-image-1", "api_key": "fake-key"},
|
|
"model_info": {
|
|
"mode": "image_generation",
|
|
},
|
|
}
|
|
]
|
|
|
|
with patch(
|
|
"litellm.proxy.health_check.litellm.ahealth_check",
|
|
side_effect=mock_health_check,
|
|
):
|
|
await health_check_module._perform_health_check(model_list)
|
|
|
|
return health_check_calls
|
|
|
|
# Default prompt is used when env var is unset
|
|
monkeypatch.delenv("DEFAULT_HEALTH_CHECK_PROMPT", raising=False)
|
|
litellm_constants, health_check = reload_modules()
|
|
health_check_calls = await run_health_check(health_check)
|
|
|
|
assert len(health_check_calls) == 1
|
|
assert (
|
|
health_check_calls[0]["prompt"] == litellm_constants.DEFAULT_HEALTH_CHECK_PROMPT
|
|
)
|
|
|
|
# Environment override should change the prompt without code changes
|
|
override_prompt = "environment override prompt"
|
|
monkeypatch.setenv("DEFAULT_HEALTH_CHECK_PROMPT", override_prompt)
|
|
litellm_constants, health_check = reload_modules()
|
|
health_check_calls = await run_health_check(health_check)
|
|
|
|
assert len(health_check_calls) == 1
|
|
assert health_check_calls[0]["prompt"] == override_prompt
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_health_check_with_custom_llm_provider():
|
|
"""
|
|
Test that ahealth_check correctly uses custom_llm_provider from model_params.
|
|
|
|
This test verifies the fix for the issue where the UI's "Test connect" button
|
|
failed with "LLM Provider NOT provided" error for OpenAI-compatible self-hosted
|
|
providers, even when a provider was selected in the dropdown.
|
|
|
|
The fix ensures that when custom_llm_provider is passed in model_params,
|
|
it's properly forwarded to get_llm_provider() to identify the correct provider.
|
|
"""
|
|
from unittest.mock import MagicMock
|
|
|
|
# Mock the completion call to avoid making real API calls
|
|
mock_response = MagicMock()
|
|
mock_response._hidden_params = {"headers": {"x-ratelimit-remaining-tokens": "1000"}}
|
|
|
|
with patch("litellm.acompletion", return_value=mock_response):
|
|
# Test with a custom model name that wouldn't be recognized without custom_llm_provider
|
|
response = await litellm.ahealth_check(
|
|
model_params={
|
|
"model": "deepseek-r1-distill-qwen-1.5B-q4",
|
|
"custom_llm_provider": "openai",
|
|
"api_base": "https://example.com/v1",
|
|
"api_key": "fake-key",
|
|
},
|
|
mode="chat",
|
|
)
|
|
|
|
# Should succeed without "LLM Provider NOT provided" error
|
|
assert "error" not in response
|
|
assert isinstance(response, dict)
|