@@ -409,7 +409,8 @@ def _build_headers(self, options: FinalRequestOptions, *, retries_taken: int = 0
409
409
410
410
idempotency_header = self ._idempotency_header
411
411
if idempotency_header and options .method .lower () != "get" and idempotency_header not in headers :
412
- headers [idempotency_header ] = options .idempotency_key or self ._idempotency_key ()
412
+ options .idempotency_key = options .idempotency_key or self ._idempotency_key ()
413
+ headers [idempotency_header ] = options .idempotency_key
413
414
414
415
# Don't set these headers if they were already set or removed by the caller. We check
415
416
# `custom_headers`, which can contain `Omit()`, instead of `headers` to account for the removal case.
@@ -943,6 +944,10 @@ def _request(
943
944
request = self ._build_request (options , retries_taken = retries_taken )
944
945
self ._prepare_request (request )
945
946
947
+ if options .idempotency_key :
948
+ # ensure the idempotency key is reused between requests
949
+ input_options .idempotency_key = options .idempotency_key
950
+
946
951
kwargs : HttpxSendArgs = {}
947
952
if self .custom_auth is not None :
948
953
kwargs ["auth" ] = self .custom_auth
@@ -1475,6 +1480,10 @@ async def _request(
1475
1480
request = self ._build_request (options , retries_taken = retries_taken )
1476
1481
await self ._prepare_request (request )
1477
1482
1483
+ if options .idempotency_key :
1484
+ # ensure the idempotency key is reused between requests
1485
+ input_options .idempotency_key = options .idempotency_key
1486
+
1478
1487
kwargs : HttpxSendArgs = {}
1479
1488
if self .custom_auth is not None :
1480
1489
kwargs ["auth" ] = self .custom_auth
0 commit comments