From dde18dd9d7300b0d06ff9e35c9c3bc259ec6486f Mon Sep 17 00:00:00 2001 From: OpenClaw Date: Sat, 14 Feb 2026 00:56:19 +0000 Subject: [PATCH] fix(pass-through): Normalize Bedrock agent runtime routes to not require trailing slashes --- litellm/constants.py | 14 +++++++------- .../llm_passthrough_endpoints.py | 8 ++++++-- .../test_pass_through_unit_tests.py | 11 +++++++++++ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/litellm/constants.py b/litellm/constants.py index addd659be73..2f76a8cb8c2 100644 --- a/litellm/constants.py +++ b/litellm/constants.py @@ -1197,13 +1197,13 @@ PYTHON_GC_THRESHOLD = os.getenv("PYTHON_GC_THRESHOLD") # pass through route constansts BEDROCK_AGENT_RUNTIME_PASS_THROUGH_ROUTES = [ - "agents/", - "knowledgebases/", - "flows/", - "retrieveAndGenerate/", - "rerank/", - "generateQuery/", - "optimize-prompt/", + "agents", + "knowledgebases", + "flows", + "retrieveAndGenerate", + "rerank", + "generateQuery", + "optimize-prompt", ] diff --git a/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py b/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py index 81144ad9f31..97618493d47 100644 --- a/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py +++ b/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py @@ -1174,10 +1174,14 @@ def _resolve_vertex_model_from_router( def _is_bedrock_agent_runtime_route(endpoint: str) -> bool: """ - Return True, if the endpoint should be routed to the `bedrock-agent-runtime` endpoint. + Return True if the endpoint should be routed to the `bedrock-agent-runtime` endpoint. + + Uses normalized path segments so trailing slashes are not required. """ + normalized = endpoint.strip("/") + parts = normalized.split("/") for _route in BEDROCK_AGENT_RUNTIME_PASS_THROUGH_ROUTES: - if _route in endpoint: + if _route in parts: return True return False diff --git a/tests/pass_through_unit_tests/test_pass_through_unit_tests.py b/tests/pass_through_unit_tests/test_pass_through_unit_tests.py index 0e681cb1e02..cdb1493d04d 100644 --- a/tests/pass_through_unit_tests/test_pass_through_unit_tests.py +++ b/tests/pass_through_unit_tests/test_pass_through_unit_tests.py @@ -419,6 +419,17 @@ def test_is_bedrock_agent_runtime_route(): ) assert _is_bedrock_agent_runtime_route("/some/random/endpoint") is False + # Test endpoints without trailing slashes still match + assert _is_bedrock_agent_runtime_route("agents") is True + assert _is_bedrock_agent_runtime_route("knowledgebases") is True + assert _is_bedrock_agent_runtime_route("flows") is True + assert _is_bedrock_agent_runtime_route("/agents") is True + assert _is_bedrock_agent_runtime_route("/knowledgebases/") is True + + # Test that partial segment matches do NOT match (no substring false positives) + assert _is_bedrock_agent_runtime_route("/myagents/foo") is False + assert _is_bedrock_agent_runtime_route("/someflows/bar") is False + def test_init_kwargs_filters_pricing_params(mock_request, mock_user_api_key_dict): """