From 2b956f30302ffcfbd5253db1218cb6b06a1efa44 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Tue, 23 Jun 2026 18:53:05 +0000 Subject: [PATCH] fix(cloudflare): treat empty CLOUDFLARE_ACCOUNT_ID as unset An empty or whitespace-only CLOUDFLARE_ACCOUNT_ID slipped past the None guard and built .../accounts//ai/v1, producing the same confusing 404 the PR set out to prevent. Normalize the secret with normalize_nonempty_secret_str so blank values raise the explicit missing-account-id error instead. --- litellm/llms/cloudflare/chat/transformation.py | 9 +++++++-- .../cloudflare/test_cloudflare_transformation.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/litellm/llms/cloudflare/chat/transformation.py b/litellm/llms/cloudflare/chat/transformation.py index ec73ff8818d..68f08741cc5 100644 --- a/litellm/llms/cloudflare/chat/transformation.py +++ b/litellm/llms/cloudflare/chat/transformation.py @@ -5,7 +5,10 @@ import httpx from litellm._logging import verbose_logger from litellm.llms.base_llm.chat.transformation import BaseLLMException from litellm.llms.openai.chat.gpt_transformation import OpenAIGPTConfig -from litellm.secret_managers.main import get_secret_str +from litellm.secret_managers.main import ( + get_secret_str, + normalize_nonempty_secret_str, +) from litellm.types.llms.openai import AllMessageValues @@ -45,7 +48,9 @@ class CloudflareChatConfig(OpenAIGPTConfig): @staticmethod def _resolve_api_base(api_base: Optional[str]) -> str: if not api_base: - account_id = get_secret_str("CLOUDFLARE_ACCOUNT_ID") + account_id = normalize_nonempty_secret_str( + get_secret_str("CLOUDFLARE_ACCOUNT_ID") + ) if account_id is None: raise ValueError( "Missing CLOUDFLARE_ACCOUNT_ID - set CLOUDFLARE_ACCOUNT_ID in the environment or pass api_base explicitly" diff --git a/tests/test_litellm/llms/cloudflare/test_cloudflare_transformation.py b/tests/test_litellm/llms/cloudflare/test_cloudflare_transformation.py index 2e2d01eb12f..1a46015ceb9 100644 --- a/tests/test_litellm/llms/cloudflare/test_cloudflare_transformation.py +++ b/tests/test_litellm/llms/cloudflare/test_cloudflare_transformation.py @@ -100,6 +100,20 @@ def test_get_complete_url_raises_when_account_id_and_base_missing(monkeypatch): ) +def test_get_complete_url_raises_when_account_id_is_empty(monkeypatch): + monkeypatch.setenv("CLOUDFLARE_ACCOUNT_ID", " ") + config = CloudflareChatConfig() + + with pytest.raises(ValueError, match="Missing CLOUDFLARE_ACCOUNT_ID"): + config.get_complete_url( + api_base=None, + api_key="cf-key", + model="@cf/meta/llama-2-7b-chat-int8", + optional_params={}, + litellm_params={}, + ) + + def test_get_complete_url_migrates_legacy_ai_run_base(): config = CloudflareChatConfig()