Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0288213

Browse files
stainless-app[bot]stainless-bot
authored andcommittedFeb 5, 2025
feat(client): send X-Stainless-Read-Timeout header (#2094)
1 parent 7193688 commit 0288213

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed
 

‎src/openai/_base_client.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,17 @@ def _build_headers(self, options: FinalRequestOptions, *, retries_taken: int = 0
420420
if idempotency_header and options.method.lower() != "get" and idempotency_header not in headers:
421421
headers[idempotency_header] = options.idempotency_key or self._idempotency_key()
422422

423-
# Don't set the retry count header if it was already set or removed by the caller. We check
423+
# Don't set these headers if they were already set or removed by the caller. We check
424424
# `custom_headers`, which can contain `Omit()`, instead of `headers` to account for the removal case.
425-
if "x-stainless-retry-count" not in (header.lower() for header in custom_headers):
425+
lower_custom_headers = [header.lower() for header in custom_headers]
426+
if "x-stainless-retry-count" not in lower_custom_headers:
426427
headers["x-stainless-retry-count"] = str(retries_taken)
428+
if "x-stainless-read-timeout" not in lower_custom_headers:
429+
timeout = self.timeout if isinstance(options.timeout, NotGiven) else options.timeout
430+
if isinstance(timeout, Timeout):
431+
timeout = timeout.read
432+
if timeout is not None:
433+
headers["x-stainless-read-timeout"] = str(timeout)
427434

428435
return headers
429436

0 commit comments

Comments
 (0)
Please sign in to comment.