@@ -409,7 +409,8 @@ def _build_headers(self, options: FinalRequestOptions, *, retries_taken: int = 0
409409
410410 idempotency_header = self ._idempotency_header
411411 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
413414
414415 # Don't set these headers if they were already set or removed by the caller. We check
415416 # `custom_headers`, which can contain `Omit()`, instead of `headers` to account for the removal case.
@@ -943,6 +944,10 @@ def _request(
943944 request = self ._build_request (options , retries_taken = retries_taken )
944945 self ._prepare_request (request )
945946
947+ if options .idempotency_key :
948+ # ensure the idempotency key is reused between requests
949+ input_options .idempotency_key = options .idempotency_key
950+
946951 kwargs : HttpxSendArgs = {}
947952 if self .custom_auth is not None :
948953 kwargs ["auth" ] = self .custom_auth
@@ -1475,6 +1480,10 @@ async def _request(
14751480 request = self ._build_request (options , retries_taken = retries_taken )
14761481 await self ._prepare_request (request )
14771482
1483+ if options .idempotency_key :
1484+ # ensure the idempotency key is reused between requests
1485+ input_options .idempotency_key = options .idempotency_key
1486+
14781487 kwargs : HttpxSendArgs = {}
14791488 if self .custom_auth is not None :
14801489 kwargs ["auth" ] = self .custom_auth
0 commit comments