Skip to content

Commit 3d7d93e

Browse files
fix(client): correctly use custom http client auth (#1028)
1 parent ad3fd2c commit 3d7d93e

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/openai/_base_client.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
PostParser,
5959
ProxiesTypes,
6060
RequestFiles,
61+
HttpxSendArgs,
6162
AsyncTransport,
6263
RequestOptions,
6364
UnknownResponse,
@@ -873,11 +874,15 @@ def _request(
873874
request = self._build_request(options)
874875
self._prepare_request(request)
875876

877+
kwargs: HttpxSendArgs = {}
878+
if self.custom_auth is not None:
879+
kwargs["auth"] = self.custom_auth
880+
876881
try:
877882
response = self._client.send(
878883
request,
879-
auth=self.custom_auth,
880884
stream=stream or self._should_stream_response_body(request=request),
885+
**kwargs,
881886
)
882887
except httpx.TimeoutException as err:
883888
if retries > 0:
@@ -1335,11 +1340,15 @@ async def _request(
13351340
request = self._build_request(options)
13361341
await self._prepare_request(request)
13371342

1343+
kwargs: HttpxSendArgs = {}
1344+
if self.custom_auth is not None:
1345+
kwargs["auth"] = self.custom_auth
1346+
13381347
try:
13391348
response = await self._client.send(
13401349
request,
1341-
auth=self.custom_auth,
13421350
stream=stream or self._should_stream_response_body(request=request),
1351+
**kwargs,
13431352
)
13441353
except httpx.TimeoutException as err:
13451354
if retries > 0:

src/openai/_types.py

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
runtime_checkable,
2929
)
3030

31+
import httpx
3132
import pydantic
3233
from httpx import URL, Proxy, Timeout, Response, BaseTransport, AsyncBaseTransport
3334

@@ -369,3 +370,7 @@ class InheritsGeneric(Protocol):
369370

370371
class _GenericAlias(Protocol):
371372
__origin__: type[object]
373+
374+
375+
class HttpxSendArgs(TypedDict, total=False):
376+
auth: httpx.Auth

0 commit comments

Comments
 (0)