Skip to content

Commit 8f42cd8

Browse files
chore(client): minor internal fixes
1 parent 8f7e894 commit 8f42cd8

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/writerai/_base_client.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ def _build_headers(self, options: FinalRequestOptions, *, retries_taken: int = 0
410410

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

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

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

1495+
if options.idempotency_key:
1496+
# ensure the idempotency key is reused between requests
1497+
input_options.idempotency_key = options.idempotency_key
1498+
14901499
kwargs: HttpxSendArgs = {}
14911500
if self.custom_auth is not None:
14921501
kwargs["auth"] = self.custom_auth

0 commit comments

Comments
 (0)