diff --git a/src/openai/_client.py b/src/openai/_client.py index 18d96da9a3..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: @@ -170,7 +167,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 @@ -341,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: @@ -401,7 +397,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