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