The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
test(router): type the retry-cap tests this PR adds or touches
mateo-berri1b040af41456
diff --git a/tests/router_unit_tests/test_router_helper_utils.py b/tests/router_unit_tests/test_router_helper_utils.pyindex 7949dd7818d..b18bf9351c8 100644--- a/tests/router_unit_tests/test_router_helper_utils.py+++ b/tests/router_unit_tests/test_router_helper_utils.py@@ -11,7 +11,7 @@ import litellmfrom unittest.mock import patch, MagicMock, AsyncMockfrom create_mock_standard_logging_payload import create_standard_logging_payloadfrom litellm.types.utils import StandardLoggingPayload-from litellm.types.router import Deployment, LiteLLM_Params, ModelInfo+from litellm.types.router import Deployment, DeploymentTypedDict, LiteLLM_Params, ModelInfofrom litellm.constants import DEFAULT_AUTO_ROUTER_MAX_INPUT_CHARS@@ -630,7 +630,7 @@ def test_deployment_callback_respects_cooldown_time(model_list):@pytest.mark.parametrize("metadata_key", ["metadata", "litellm_metadata"])-def test_log_retry(model_list, metadata_key):+def test_log_retry(model_list: list[DeploymentTypedDict], metadata_key: str) -> None:"""log_retry appends one flat record per failed attempt, copies neither the request kwargs nor therequest metadata into it, counts every failed attempt of the request independently of theper-hop attempted_retries, and never trusts a negative count planted before the first failure"""diff --git a/tests/test_litellm/proxy/test_litellm_pre_call_utils.py b/tests/test_litellm/proxy/test_litellm_pre_call_utils.pyindex abd59bb4d3b..a2b261dcfb0 100644--- a/tests/test_litellm/proxy/test_litellm_pre_call_utils.py+++ b/tests/test_litellm/proxy/test_litellm_pre_call_utils.py@@ -7353,7 +7353,7 @@ _PLANTED_STAMPS = {@pytest.mark.asyncio-async def test_add_litellm_data_to_request_strips_router_reserved_stamps_from_both_buckets():+async def test_add_litellm_data_to_request_strips_router_reserved_stamps_from_both_buckets() -> None:"""attempted_fallbacks and original_model_group are router-written facts the spend rowreads back; a client planting them in either bucket is dropped at the boundary so therouter never sees a reserved key it did not write."""@@ -7384,7 +7384,7 @@ async def test_add_litellm_data_to_request_strips_router_reserved_stamps_from_bo@pytest.mark.asyncio-async def test_add_litellm_data_to_request_strips_router_reserved_stamps_from_json_string_litellm_metadata():+async def test_add_litellm_data_to_request_strips_router_reserved_stamps_from_json_string_litellm_metadata() -> None:from litellm.proxy.litellm_pre_call_utils import add_litellm_data_to_requestdata = {@@ -7410,7 +7410,7 @@ async def test_add_litellm_data_to_request_strips_router_reserved_stamps_from_js@pytest.mark.asyncio-async def test_add_litellm_data_to_request_strips_router_reserved_stamps_despite_pricing_override_opt_in():+async def test_add_litellm_data_to_request_strips_router_reserved_stamps_despite_pricing_override_opt_in() -> None:"""The pricing strip is gated on allow_client_pricing_override; the reserved-stamp stripis not, because no key or team setting makes a client-written fallback count valid."""from litellm.proxy.litellm_pre_call_utils import add_litellm_data_to_requestdiff --git a/tests/test_litellm/test_router.py b/tests/test_litellm/test_router.pyindex 1de86084980..0485da3eba9 100644--- a/tests/test_litellm/test_router.py+++ b/tests/test_litellm/test_router.py@@ -11066,7 +11066,7 @@ async def test_num_retries_per_request_stops_retries_at_caps_above_four(monkeypa]-def _failing_group_with_healthy_fallback_router(num_retries):+def _failing_group_with_healthy_fallback_router(num_retries: int) -> litellm.Router:return litellm.Router(model_list=[{@@ -11094,8 +11094,8 @@ def _failing_group_with_healthy_fallback_router(num_retries):ids=["cap-spent-before-the-hop", "cap-not-reached-by-the-hop", "planted-negative-count-does-not-lift-the-cap"],)async def test_num_retries_per_request_counts_retries_across_fallback_hops(- monkeypatch, cap, planted_count, hop_refused-):+ monkeypatch: pytest.MonkeyPatch, cap: int, planted_count: int | None, hop_refused: bool+) -> None:"""num_retries_per_request caps the retries of one request, fallback hops included. Each hop starts afresh per-hop attempted_retries at zero, so a cap read from that counter let every hop retry from zeroand a request could spend far more retries than the cap allows. A caller who plants a negative countdiff --git a/tests/test_litellm/test_utils.py b/tests/test_litellm/test_utils.pyindex 3d60fe86d9c..e7878f6bff0 100644--- a/tests/test_litellm/test_utils.py+++ b/tests/test_litellm/test_utils.py@@ -4099,7 +4099,9 @@ def _capped_completion_kwargs(metadata_key: str, metadata: object) -> dict[str,@pytest.mark.parametrize("metadata_key", ["metadata", "litellm_metadata"])@pytest.mark.parametrize("cap, metadata, refused", _RETRY_CAP_CASES)-def test_num_retries_per_request_reads_request_retry_count_sync(monkeypatch, metadata_key, cap, metadata, refused):+def test_num_retries_per_request_reads_request_retry_count_sync(+ monkeypatch: pytest.MonkeyPatch, metadata_key: str, cap: int, metadata: object, refused: bool+) -> None:monkeypatch.setattr(litellm, "num_retries_per_request", cap)kwargs: Final = _capped_completion_kwargs(metadata_key, metadata)if refused:@@ -4112,7 +4114,9 @@ def test_num_retries_per_request_reads_request_retry_count_sync(monkeypatch, met@pytest.mark.asyncio@pytest.mark.parametrize("metadata_key", ["metadata", "litellm_metadata"])@pytest.mark.parametrize("cap, metadata, refused", _RETRY_CAP_CASES)-async def test_num_retries_per_request_reads_request_retry_count_async(monkeypatch, metadata_key, cap, metadata, refused):+async def test_num_retries_per_request_reads_request_retry_count_async(+ monkeypatch: pytest.MonkeyPatch, metadata_key: str, cap: int, metadata: object, refused: bool+) -> None:monkeypatch.setattr(litellm, "num_retries_per_request", cap)kwargs: Final = _capped_completion_kwargs(metadata_key, metadata)if refused: