feat: send request timeout header#3351
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 06be158da8
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if "request-timeout-ms" not in lower_custom_headers: | ||
| if not isinstance(timeout, Timeout) and timeout is not None: | ||
| headers["request-timeout-ms"] = str(int(timeout * 1000)) |
There was a problem hiding this comment.
Preserve default request-timeout-ms overrides
When a client is configured with default_headers={"request-timeout-ms": "..."} and a numeric timeout, this block still overwrites that caller-supplied default because lower_custom_headers only contains per-request extra_headers, while headers already contains merged default headers. The repo's header behavior allows default_headers to override built-in headers (for example X-Stainless-Lang in tests/test_client.py), so this new automatic header cannot be globally overridden via the same public option unless the caller repeats extra_headers on every request.
Useful? React with 👍 / 👎.
Changes being requested
Adds a
request-timeout-msheader when a numeric request timeout is configured, allowing downstream services to receive the request wall-clock deadline in milliseconds. The header is not set forhttpx.Timeoutobjects and can be omitted or overridden by callers viaextra_headers.Additional context & links
Fixes #3277
Tests:
.venv/bin/ruff check src/openai/_base_client.py tests/test_client.py.venv/bin/python -m pytest -o addopts='' tests/test_client.py