@@ -411,7 +411,8 @@ def _build_headers(self, options: FinalRequestOptions, *, retries_taken: int = 0
411
411
412
412
idempotency_header = self ._idempotency_header
413
413
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
415
416
416
417
# Don't set these headers if they were already set or removed by the caller. We check
417
418
# `custom_headers`, which can contain `Omit()`, instead of `headers` to account for the removal case.
@@ -945,6 +946,10 @@ def _request(
945
946
request = self ._build_request (options , retries_taken = retries_taken )
946
947
self ._prepare_request (request )
947
948
949
+ if options .idempotency_key :
950
+ # ensure the idempotency key is reused between requests
951
+ input_options .idempotency_key = options .idempotency_key
952
+
948
953
kwargs : HttpxSendArgs = {}
949
954
if self .custom_auth is not None :
950
955
kwargs ["auth" ] = self .custom_auth
@@ -1492,6 +1497,10 @@ async def _request(
1492
1497
request = self ._build_request (options , retries_taken = retries_taken )
1493
1498
await self ._prepare_request (request )
1494
1499
1500
+ if options .idempotency_key :
1501
+ # ensure the idempotency key is reused between requests
1502
+ input_options .idempotency_key = options .idempotency_key
1503
+
1495
1504
kwargs : HttpxSendArgs = {}
1496
1505
if self .custom_auth is not None :
1497
1506
kwargs ["auth" ] = self .custom_auth
0 commit comments