Commit 90afdfff

Robert Craigie <robert@craigie.dev>
2025-06-28 00:49:01
fix(client): avoid encoding error with empty API keys
1 parent a186778
Changed files (1)
src
openai
src/openai/_client.py
@@ -283,6 +283,9 @@ class OpenAI(SyncAPIClient):
     @override
     def auth_headers(self) -> dict[str, str]:
         api_key = self.api_key
+        if not api_key:
+            # if the api key is an empty string, encoding the header will fail
+            return {}
         return {"Authorization": f"Bearer {api_key}"}
 
     @property
@@ -599,6 +602,9 @@ class AsyncOpenAI(AsyncAPIClient):
     @override
     def auth_headers(self) -> dict[str, str]:
         api_key = self.api_key
+        if not api_key:
+            # if the api key is an empty string, encoding the header will fail
+            return {}
         return {"Authorization": f"Bearer {api_key}"}
 
     @property