From 0710e0dd8baab0a192c77035ce08bb4e0b30530f Mon Sep 17 00:00:00 2001 From: SparkLabScout Date: Wed, 11 Mar 2026 16:38:16 +0800 Subject: [PATCH 1/2] fix: handle empty string in OPENAI_BASE_URL env var When OPENAI_BASE_URL is set to an empty string, the SDK should fall back to the default API endpoint instead of using the empty string as the base URL. Fixes issue #2927 --- src/openai/_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openai/_client.py b/src/openai/_client.py index aadf3601f2..8aebdd8187 100644 --- a/src/openai/_client.py +++ b/src/openai/_client.py @@ -162,7 +162,7 @@ def __init__( if base_url is None: base_url = os.environ.get("OPENAI_BASE_URL") - if base_url is None: + if base_url is None or base_url == "": base_url = f"https://api.openai.com/v1" super().__init__( @@ -537,7 +537,7 @@ def __init__( if base_url is None: base_url = os.environ.get("OPENAI_BASE_URL") - if base_url is None: + if base_url is None or base_url == "": base_url = f"https://api.openai.com/v1" super().__init__( From f8384f3e38cbc9e456a6b0e0224b4d3ff8ad5f78 Mon Sep 17 00:00:00 2001 From: Jah-yee Date: Fri, 13 Mar 2026 10:36:36 +0800 Subject: [PATCH 2/2] fix: convert by_alias=None to bool for pydantic v2 When DEBUG logging is enabled, model_dump() is called with by_alias=None (the default), which causes pydantic-core's Rust serializer to raise: TypeError: argument 'by_alias': 'NoneType' object cannot be converted to 'PyBool' This fix converts None to True (pydantic's default behavior) before passing to model_dump() for pydantic v2. Fixes: #2921 --- src/openai/_compat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openai/_compat.py b/src/openai/_compat.py index 020ffeb2ca..778bca4d02 100644 --- a/src/openai/_compat.py +++ b/src/openai/_compat.py @@ -149,7 +149,7 @@ def model_dump( exclude_defaults=exclude_defaults, # warnings are not supported in Pydantic v1 warnings=True if PYDANTIC_V1 else warnings, - by_alias=by_alias, + by_alias=bool(by_alias) if by_alias is not None else True, ) return cast( "dict[str, Any]",