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
fix(router): stop copying forwarded credentials into retry breadcrumbs
mateo-berri1c18d3eda3be
diff --git a/litellm/router.py b/litellm/router.pyindex 045fd32847c..132ff6671a7 100644--- a/litellm/router.py+++ b/litellm/router.py@@ -376,9 +376,19 @@ set_live_deployment_replay(_replay_live_router_model_cost)# Kwargs that log_retry must not copy into a retry breadcrumb. The breadcrumbs reach spend-# logs and logging callbacks, and these carry either the request payload or router-internal-# walk state rather than anything that identifies the failed attempt.-RETRY_BREADCRUMB_EXCLUDED_KWARGS: Final = frozenset(("messages", "original_function", "attempted_targets"))+# logs and logging callbacks, so they must never carry the request payload, router-internal+# walk state, or transport credentials: provider_specific_header / headers / api_key can hold a+# client's forwarded Authorization or a provider key, none of which identify the failed attempt.+RETRY_BREADCRUMB_EXCLUDED_KWARGS: Final = frozenset(+ (+ "messages",+ "original_function",+ "attempted_targets",+ "provider_specific_header",+ "headers",+ "api_key",+ )+)class Router:diff --git a/tests/test_litellm/test_router.py b/tests/test_litellm/test_router.pyindex d00fbf589e3..7e6cc010834 100644--- a/tests/test_litellm/test_router.py+++ b/tests/test_litellm/test_router.py@@ -8565,6 +8565,30 @@ async def test_retry_breadcrumbs_do_not_carry_the_walk_state():assert "attempted_targets" not in breadcrumb+async def test_retry_breadcrumbs_drop_forwarded_client_credentials():+ """log_retry copies kwargs verbatim into previous_models, which reaches spend logs and logging+ callbacks. provider_specific_header can carry a client's forwarded Authorization token, and a+ breadcrumb has no diagnostic use for it, so the raw credential must never land in the breadcrumb."""+ canary = "Bearer sk-ant-oat01-RETRY-BREADCRUMB-CANARY-doNotShip"+ router = _cyclic_fallback_router(num_retries=1)+ capture = _LogCapture(logging.ERROR)++ await _drive_cyclic_fallback(+ router,+ capture,+ provider_specific_header={+ "custom_llm_provider": "openai",+ "extra_headers": {"authorization": canary},+ },+ )++ assert router.previous_models, "no retry breadcrumbs were recorded"+ for breadcrumb in router.previous_models:+ assert "provider_specific_header" not in breadcrumb+ assert canary not in json.dumps(router.previous_models, default=str)++@pytest.mark.asyncioasync def test_fallback_traceback_stays_available_at_debug_level():"""Dropping the stack from the ERROR line is only safe because the fallback path still