fix: add User-Agent header to OpenAI client fetch (#177) - #273
Open
innocarpe wants to merge 2 commits into
Open
Conversation
Some CDNs and WAFs (e.g. Cloudflare) block requests that arrive without a User-Agent. Inject a default one into the undici fetch wrapper, preserving any caller-provided headers. (cherry picked from commit 67a33160c870c301342eb6b3a70ae01609976c7e)
The undici HeadersInit type used by buildClientHeaders does not accept the global Headers instance in this project's TS config, so switch the test to a tuple-array input. (cherry picked from commit 8ee5241e83e602a87fd64151997dad06b79708f6)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
User-Agentheader to outgoing OpenAI API requests.403 Your request was blockederrors from CDNs/WAFs (e.g. Cloudflare) that reject requests without aUser-Agent.Why
Custom/proxy API endpoints routed through Cloudflare or enterprise WAFs block requests arriving without a
User-Agentas a basic anti-bot measure. The undici fetch wrapper used by the OpenAI client never set one, so those setups failed immediately with 403.Changes
packages/core/src/common/openai-client.ts: addbuildClientHeaders()which injectsdeepcode-cli (Node.js <version>)unless the caller already provided a header, and use it in the fetch wrapper.packages/core/src/tests/openai-client.test.ts: unit tests for header injection/preservation.Validation
npm run typecheck✅npm test— new openai-client tests pass ✅Closes #177