@@ -956,6 +956,11 @@ def _request(
956956 stream : bool ,
957957 stream_cls : type [_StreamT ] | None ,
958958 ) -> ResponseT | _StreamT :
959+ # create a copy of the options we were given so that if the
960+ # options are mutated later & we then retry, the retries are
961+ # given the original options
962+ input_options = model_copy (options )
963+
959964 cast_to = self ._maybe_override_cast_to (cast_to , options )
960965 self ._prepare_options (options )
961966
@@ -980,7 +985,7 @@ def _request(
980985
981986 if retries > 0 :
982987 return self ._retry_request (
983- options ,
988+ input_options ,
984989 cast_to ,
985990 retries ,
986991 stream = stream ,
@@ -995,7 +1000,7 @@ def _request(
9951000
9961001 if retries > 0 :
9971002 return self ._retry_request (
998- options ,
1003+ input_options ,
9991004 cast_to ,
10001005 retries ,
10011006 stream = stream ,
@@ -1023,7 +1028,7 @@ def _request(
10231028 if retries > 0 and self ._should_retry (err .response ):
10241029 err .response .close ()
10251030 return self ._retry_request (
1026- options ,
1031+ input_options ,
10271032 cast_to ,
10281033 retries ,
10291034 err .response .headers ,
@@ -1532,6 +1537,11 @@ async def _request(
15321537 # execute it earlier while we are in an async context
15331538 self ._platform = await asyncify (get_platform )()
15341539
1540+ # create a copy of the options we were given so that if the
1541+ # options are mutated later & we then retry, the retries are
1542+ # given the original options
1543+ input_options = model_copy (options )
1544+
15351545 cast_to = self ._maybe_override_cast_to (cast_to , options )
15361546 await self ._prepare_options (options )
15371547
@@ -1554,7 +1564,7 @@ async def _request(
15541564
15551565 if retries > 0 :
15561566 return await self ._retry_request (
1557- options ,
1567+ input_options ,
15581568 cast_to ,
15591569 retries ,
15601570 stream = stream ,
@@ -1569,7 +1579,7 @@ async def _request(
15691579
15701580 if retries > 0 :
15711581 return await self ._retry_request (
1572- options ,
1582+ input_options ,
15731583 cast_to ,
15741584 retries ,
15751585 stream = stream ,
@@ -1592,7 +1602,7 @@ async def _request(
15921602 if retries > 0 and self ._should_retry (err .response ):
15931603 await err .response .aclose ()
15941604 return await self ._retry_request (
1595- options ,
1605+ input_options ,
15961606 cast_to ,
15971607 retries ,
15981608 err .response .headers ,
0 commit comments