From 62f3a1b415a259c7576ec194310e298d84a0900d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=A0=E7=A3=8A?= Date: Sun, 30 Mar 2025 23:27:16 +0800 Subject: [PATCH 1/2] fix: when api_key is None, the request should not contain 'Authorization': f 'Bearer {api_key}'. #961 --- src/openai/_client.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/openai/_client.py b/src/openai/_client.py index 18d96da9a3..407a6d235c 100644 --- a/src/openai/_client.py +++ b/src/openai/_client.py @@ -170,7 +170,9 @@ def qs(self) -> Querystring: @override def auth_headers(self) -> dict[str, str]: api_key = self.api_key - return {"Authorization": f"Bearer {api_key}"} + if api_key : + return {"Authorization": f"Bearer {api_key}"} + return {} @property @override @@ -401,7 +403,9 @@ def qs(self) -> Querystring: @override def auth_headers(self) -> dict[str, str]: api_key = self.api_key - return {"Authorization": f"Bearer {api_key}"} + if api_key : + return {"Authorization": f"Bearer {api_key}"} + return {} @property @override From 634948b0053c7e3980153fb38413e7e171935036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=A0=E7=A3=8A?= Date: Wed, 2 Apr 2025 16:43:15 +0800 Subject: [PATCH 2/2] fix: when api_key is None, the request should not contain 'Authorization': f 'Bearer {api_key}'. #961 --- src/openai/_client.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/openai/_client.py b/src/openai/_client.py index 407a6d235c..20868678f8 100644 --- a/src/openai/_client.py +++ b/src/openai/_client.py @@ -110,10 +110,7 @@ def __init__( """ if api_key is None: api_key = os.environ.get("OPENAI_API_KEY") - if api_key is None: - raise OpenAIError( - "The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable" - ) + self.api_key = api_key if organization is None: @@ -343,10 +340,7 @@ def __init__( """ if api_key is None: api_key = os.environ.get("OPENAI_API_KEY") - if api_key is None: - raise OpenAIError( - "The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable" - ) + self.api_key = api_key if organization is None: