From 25790e13a7deda879a9da84200c73e1a302f97c0 Mon Sep 17 00:00:00 2001 From: PRABHU KIRAN VANDRANKI <72809214+VANDRANKI@users.noreply.github.com> Date: Tue, 2 Jun 2026 10:38:44 -0400 Subject: [PATCH] fix(dashscope): improve get_complete_url guard to prevent double-path append The endswith check fails when api_base has a trailing slash (e.g. .../chat/completions/ passes the guard and appends again). Switch to the safer `endpoint not in api_base` check after rstrip("/"), which mirrors the behavior of the parent OpenAIGPTConfig.get_complete_url. Fixes #28429 --- litellm/llms/dashscope/chat/transformation.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/litellm/llms/dashscope/chat/transformation.py b/litellm/llms/dashscope/chat/transformation.py index ccb4d370c95..c34d6d57ebd 100644 --- a/litellm/llms/dashscope/chat/transformation.py +++ b/litellm/llms/dashscope/chat/transformation.py @@ -71,12 +71,15 @@ class DashScopeChatConfig(OpenAIGPTConfig): stream: Optional[bool] = None, ) -> str: """ - If api_base is not provided, use the default DashScope /chat/completions endpoint. + If api_base is not provided, use the default DashScope base URL. + Appends /chat/completions only when not already present, matching OpenAIGPTConfig behavior. """ if not api_base: api_base = "https://dashscope.aliyuncs.com/compatible-mode/v1" - if not api_base.endswith("/chat/completions"): - api_base = f"{api_base}/chat/completions" + endpoint = "chat/completions" + api_base = api_base.rstrip("/") + if endpoint not in api_base: + api_base = f"{api_base}/{endpoint}" return api_base