Skip to content

Commit

Permalink
fix(client): correctly use custom http client auth (#1028)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Jan 9, 2024
1 parent ade28c4 commit 6279b26
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/openai/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
PostParser,
ProxiesTypes,
RequestFiles,
HttpxSendArgs,
AsyncTransport,
RequestOptions,
UnknownResponse,
Expand Down Expand Up @@ -873,11 +874,15 @@ def _request(
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:
Expand Down Expand Up @@ -1335,11 +1340,15 @@ async def _request(
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:
Expand Down
5 changes: 5 additions & 0 deletions src/openai/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
runtime_checkable,
)

import httpx
import pydantic
from httpx import URL, Proxy, Timeout, Response, BaseTransport, AsyncBaseTransport

Expand Down Expand Up @@ -369,3 +370,7 @@ class InheritsGeneric(Protocol):

class _GenericAlias(Protocol):
__origin__: type[object]


class HttpxSendArgs(TypedDict, total=False):
auth: httpx.Auth

0 comments on commit 6279b26

Please sign in to comment.