Skip to content

Commit 6071ae5

Browse files
chore(client): minor internal fixes
1 parent c8f8beb commit 6071ae5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/openai/_base_client.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@ def _build_headers(self, options: FinalRequestOptions, *, retries_taken: int = 0
411411

412412
idempotency_header = self._idempotency_header
413413
if idempotency_header and options.method.lower() != "get" and idempotency_header not in headers:
414-
headers[idempotency_header] = options.idempotency_key or self._idempotency_key()
414+
options.idempotency_key = options.idempotency_key or self._idempotency_key()
415+
headers[idempotency_header] = options.idempotency_key
415416

416417
# Don't set these headers if they were already set or removed by the caller. We check
417418
# `custom_headers`, which can contain `Omit()`, instead of `headers` to account for the removal case.
@@ -945,6 +946,10 @@ def _request(
945946
request = self._build_request(options, retries_taken=retries_taken)
946947
self._prepare_request(request)
947948

949+
if options.idempotency_key:
950+
# ensure the idempotency key is reused between requests
951+
input_options.idempotency_key = options.idempotency_key
952+
948953
kwargs: HttpxSendArgs = {}
949954
if self.custom_auth is not None:
950955
kwargs["auth"] = self.custom_auth
@@ -1492,6 +1497,10 @@ async def _request(
14921497
request = self._build_request(options, retries_taken=retries_taken)
14931498
await self._prepare_request(request)
14941499

1500+
if options.idempotency_key:
1501+
# ensure the idempotency key is reused between requests
1502+
input_options.idempotency_key = options.idempotency_key
1503+
14951504
kwargs: HttpxSendArgs = {}
14961505
if self.custom_auth is not None:
14971506
kwargs["auth"] = self.custom_auth

0 commit comments

Comments
 (0)