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: strip trailing slash from --base-url in lite CLI (#32845)
Krrish Dholakiadacf1cfb268e
diff --git a/litellm/proxy/client/cli/main.py b/litellm/proxy/client/cli/main.pyindex 43b64aebd3b..aadaff61238 100644--- a/litellm/proxy/client/cli/main.py+++ b/litellm/proxy/client/cli/main.py@@ -76,6 +76,10 @@ def cli(ctx: click.Context, base_url: str, api_key: Optional[str]) -> None:"""LiteLLM Proxy CLI - Manage your LiteLLM proxy server"""ctx.ensure_object(dict)+ # Normalize once here so every downstream command (login, agents, http, ...) can safely+ # do f"{base_url}/some/path" without producing a double slash.+ base_url = base_url.rstrip("/")+# If no API key provided via flag or environment variable, try to load from saved token.# Pass base_url so we only use the stored key when it was issued for this server.if api_key is None:diff --git a/tests/test_litellm/proxy/client/cli/test_global_options.py b/tests/test_litellm/proxy/client/cli/test_global_options.pyindex 3a19f735c1b..53b7e4dbc29 100644--- a/tests/test_litellm/proxy/client/cli/test_global_options.py+++ b/tests/test_litellm/proxy/client/cli/test_global_options.py@@ -1,7 +1,7 @@# stdlib importsimport osimport sys-from unittest.mock import patch+from unittest.mock import Mock, patchimport pytestfrom click.testing import CliRunner@@ -36,6 +36,35 @@ def test_cli_version_flag(cli_runner):assert "LiteLLM Proxy Server Version: 1.2.3" in result.output+def test_base_url_trailing_slash_normalized(cli_runner):+ """A trailing slash on --base-url must not produce a double slash (e.g. '//sso/cli/start')."""+ with (+ patch("webbrowser.open"),+ patch(+ "requests.post",+ return_value=Mock(+ status_code=200,+ json=Mock(+ return_value={+ "login_id": "cli-test-uuid",+ "poll_secret": "poll-secret",+ "user_code": "ABCD-EFGH",+ }+ ),+ raise_for_status=Mock(),+ ),+ ) as mock_post,+ patch("requests.get", side_effect=ValueError("stop after start request")),+ ):+ cli_runner.invoke(+ cli, ["--base-url", "https://gateway.litellm-sandbox.ai/", "login"]+ )++ mock_post.assert_called_once_with(+ "https://gateway.litellm-sandbox.ai/sso/cli/start", timeout=10+ )++def test_cli_version_command(cli_runner):"""Test that 'version' command prints the correct version, server URL, and server version, and exits successfully"""with (