fix: include auth headers in responses websocket handshake#3630
fix: include auth headers in responses websocket handshake#3630maxpetrusenkoagent wants to merge 1 commit into
Conversation
|
Verification update from Hermes Agent:
Note: a full |
|
This PR is stale because it has been open for 10 days with no activity. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 457f41ecb9
ℹ️ 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 _is_openai_omitted_value(value): | ||
| continue | ||
| headers[key] = str(value) | ||
| auth_headers = getattr(self._client, "auth_headers", {}) |
There was a problem hiding this comment.
Avoid inherited bearer auth for Azure clients
When an AsyncAzureOpenAI client is passed here, openai-python 2.36.0 does not override auth_headers; it inherits AsyncOpenAI.auth_headers, which formats the Azure API key as Authorization: Bearer ... instead of the api-key header that Azure's _auth_headers / _prepare_options path uses. This makes the Responses WebSocket handshake send bogus auth for Azure API-key clients, and can also add that bogus bearer alongside a caller's default_headers={"api-key": ...} workaround, so please derive auth through the client's request auth path or special-case Azure instead of reading this property directly.
Useful? React with 👍 / 👎.
Summary
Fixes the Responses WebSocket handshake header merge so it includes the OpenAI client's
auth_headers. In recentopenaiSDK versions,Authorizationlives inAsyncOpenAI.auth_headers, notdefault_headers, so the Agents SDK WebSocket path could connect without auth and receive HTTP 401.This keeps the existing precedence shape narrow:
extra_headersstill apply last and can replace or omit inherited headersTest plan
uv run pytest tests/models/test_openai_responses.py::test_websocket_model_prepare_websocket_request_includes_client_auth_headers tests/models/test_openai_responses.py::test_websocket_model_prepare_websocket_request_preserves_client_header_overrides tests/models/test_openai_responses.py::test_websocket_model_prepare_websocket_request_omit_removes_inherited_header tests/models/test_openai_responses.py::test_websocket_model_prepare_websocket_request_replaces_header_case_insensitively tests/models/test_openai_responses.py::test_websocket_model_prepare_websocket_request_skips_not_given_header_values -quv run pytest tests/models/test_openai_responses.py tests/test_config.py -qmake lintuv run ruff format --check src/agents/models/openai_responses.py tests/models/test_openai_responses.pyuv run mypy src/agents/models/openai_responses.py tests/models/test_openai_responses.py --exclude siteuv run python -m pyright --project pyrightconfig.jsonIssue number
Closes #3133
Checks
make lintandmake format