Commit 77ba4182

stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com>
2025-04-14 22:30:49
chore(client): minor internal fixes
1 parent 1828fb6
Changed files (1)
src
src/openai/_base_client.py
@@ -411,7 +411,8 @@ class BaseClient(Generic[_HttpxClientT, _DefaultStreamT]):
 
         idempotency_header = self._idempotency_header
         if idempotency_header and options.method.lower() != "get" and idempotency_header not in headers:
-            headers[idempotency_header] = options.idempotency_key or self._idempotency_key()
+            options.idempotency_key = options.idempotency_key or self._idempotency_key()
+            headers[idempotency_header] = options.idempotency_key
 
         # Don't set these headers if they were already set or removed by the caller. We check
         # `custom_headers`, which can contain `Omit()`, instead of `headers` to account for the removal case.
@@ -945,6 +946,10 @@ class SyncAPIClient(BaseClient[httpx.Client, Stream[Any]]):
         request = self._build_request(options, retries_taken=retries_taken)
         self._prepare_request(request)
 
+        if options.idempotency_key:
+            # ensure the idempotency key is reused between requests
+            input_options.idempotency_key = options.idempotency_key
+
         kwargs: HttpxSendArgs = {}
         if self.custom_auth is not None:
             kwargs["auth"] = self.custom_auth
@@ -1492,6 +1497,10 @@ class AsyncAPIClient(BaseClient[httpx.AsyncClient, AsyncStream[Any]]):
         request = self._build_request(options, retries_taken=retries_taken)
         await self._prepare_request(request)
 
+        if options.idempotency_key:
+            # ensure the idempotency key is reused between requests
+            input_options.idempotency_key = options.idempotency_key
+
         kwargs: HttpxSendArgs = {}
         if self.custom_auth is not None:
             kwargs["auth"] = self.custom_auth