From e40da7dd677e291714bdfc0f61aa255a6e22a09c Mon Sep 17 00:00:00 2001 From: Xsidz Date: Sun, 16 Aug 2026 23:22:54 +0530 Subject: [PATCH] fix(client): restore api_key="" support for local OAI-compatible servers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #3224: v2.34.0 added a credential check using `not self.api_key` which treats explicit api_key="" the same as no key provided. Track whether the caller explicitly passed api_key before the env-var lookup and skip the check when they did — restoring pre-2.34.0 behavior for users pointing at local servers that require no authentication. --- src/openai/_client.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/openai/_client.py b/src/openai/_client.py index 5f980c8cb6..2a2b8a4b6f 100644 --- a/src/openai/_client.py +++ b/src/openai/_client.py @@ -197,6 +197,7 @@ def __init__( self.workload_identity = workload_identity if provider_runtime is None else None + _api_key_provided = api_key is not None if provider_runtime is not None: self.api_key = "" self._api_key_provider = None @@ -224,6 +225,7 @@ def __init__( provider_runtime is None and _enforce_credentials and not self.api_key + and not _api_key_provided and self._api_key_provider is None and workload_identity is None and self.admin_api_key is None @@ -803,6 +805,7 @@ def __init__( self.workload_identity = workload_identity if provider_runtime is None else None + _api_key_provided = api_key is not None if provider_runtime is not None: self.api_key = "" self._api_key_provider = None @@ -830,6 +833,7 @@ def __init__( provider_runtime is None and _enforce_credentials and not self.api_key + and not _api_key_provided and self._api_key_provider is None and workload_identity is None and self.admin_api_key is None