fix(cloudflare): treat empty api_base as unset when resolving URL

This commit is contained in:
mateo-berri 2026-06-23 03:20:35 +00:00
parent 93add6a43b
commit 462a740424
No known key found for this signature in database
2 changed files with 19 additions and 1 deletions

View file

@ -44,7 +44,7 @@ class CloudflareChatConfig(OpenAIGPTConfig):
@staticmethod
def _resolve_api_base(api_base: Optional[str]) -> str:
if api_base is None:
if not api_base:
account_id = get_secret_str("CLOUDFLARE_ACCOUNT_ID")
if account_id is None:
raise ValueError(

View file

@ -68,6 +68,24 @@ def test_get_complete_url_is_idempotent_for_full_base():
)
def test_get_complete_url_falls_back_to_account_id_when_base_is_empty(monkeypatch):
monkeypatch.setenv("CLOUDFLARE_ACCOUNT_ID", "acct")
config = CloudflareChatConfig()
url = config.get_complete_url(
api_base="",
api_key="cf-key",
model="@cf/meta/llama-2-7b-chat-int8",
optional_params={},
litellm_params={},
)
assert (
url
== "https://api.cloudflare.com/client/v4/accounts/acct/ai/v1/chat/completions"
)
def test_get_complete_url_raises_when_account_id_and_base_missing(monkeypatch):
monkeypatch.delenv("CLOUDFLARE_ACCOUNT_ID", raising=False)
config = CloudflareChatConfig()