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()