Commit 6279b267

Stainless Bot <107565488+stainless-bot@users.noreply.github.com>
2023-12-28 10:19:05
fix(client): correctly use custom http client auth (#1028)
1 parent ade28c4
Changed files (2)
src/openai/_base_client.py
@@ -58,6 +58,7 @@ from ._types import (
     PostParser,
     ProxiesTypes,
     RequestFiles,
+    HttpxSendArgs,
     AsyncTransport,
     RequestOptions,
     UnknownResponse,
@@ -873,11 +874,15 @@ class SyncAPIClient(BaseClient[httpx.Client, Stream[Any]]):
         request = self._build_request(options)
         self._prepare_request(request)
 
+        kwargs: HttpxSendArgs = {}
+        if self.custom_auth is not None:
+            kwargs["auth"] = self.custom_auth
+
         try:
             response = self._client.send(
                 request,
-                auth=self.custom_auth,
                 stream=stream or self._should_stream_response_body(request=request),
+                **kwargs,
             )
         except httpx.TimeoutException as err:
             if retries > 0:
@@ -1335,11 +1340,15 @@ class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]):
         request = self._build_request(options)
         await self._prepare_request(request)
 
+        kwargs: HttpxSendArgs = {}
+        if self.custom_auth is not None:
+            kwargs["auth"] = self.custom_auth
+
         try:
             response = await self._client.send(
                 request,
-                auth=self.custom_auth,
                 stream=stream or self._should_stream_response_body(request=request),
+                **kwargs,
             )
         except httpx.TimeoutException as err:
             if retries > 0:
src/openai/_types.py
@@ -28,6 +28,7 @@ from typing_extensions import (
     runtime_checkable,
 )
 
+import httpx
 import pydantic
 from httpx import URL, Proxy, Timeout, Response, BaseTransport, AsyncBaseTransport
 
@@ -369,3 +370,7 @@ class InheritsGeneric(Protocol):
 
 class _GenericAlias(Protocol):
     __origin__: type[object]
+
+
+class HttpxSendArgs(TypedDict, total=False):
+    auth: httpx.Auth