Description
When using deepcode-cli with custom/proxy API endpoints (e.g., endpoints routed through Cloudflare or strict enterprise WAFs), requests immediately fail with a 403 Your request was blocked error.
Root Cause
In the initialization of the OpenAI client, the custom fetch implementation using undiciFetch does not provide a default User-Agent.
Many CDNs and WAFs (like Cloudflare) automatically block HTTP requests missing a User-Agent as a basic anti-bot measure.
ypescript // Current implementation fetch: (url, init) => undiciFetch(url, { ...init, dispatcher: keepAliveAgent })
Proposed Solution
Inject a standard or tool-specific User-Agent into the headers before passing them to undiciFetch.
` ypescript
fetch: (url, init) => {
const headers = new Headers(init?.headers);
if (!headers.has("User-Agent")) {
headers.set("User-Agent", "deepcode-cli/0.1.x (Node.js)");
}
// Note: undiciFetch expects a plain object or an array of arrays for headers in some older TS setups,
// so converting Headers back to an object might be necessary depending on the exact undici version used.
const headersObj = Object.fromEntries(headers.entries());
return undiciFetch(url, {
...init,
headers: headersObj,
dispatcher: keepAliveAgent
});
}
`
Steps to Reproduce
- Set
BASE_URL in ~/.deepcode/settings.json to an API endpoint protected by Cloudflare.
- Run
deepcode and send a message.
- Observe the
403 Your request was blocked error.
Description
When using
deepcode-cliwith custom/proxy API endpoints (e.g., endpoints routed through Cloudflare or strict enterprise WAFs), requests immediately fail with a403 Your request was blockederror.Root Cause
In the initialization of the OpenAI client, the custom
fetchimplementation usingundiciFetchdoes not provide a defaultUser-Agent.Many CDNs and WAFs (like Cloudflare) automatically block HTTP requests missing a
User-Agentas a basic anti-bot measure.ypescript // Current implementation fetch: (url, init) => undiciFetch(url, { ...init, dispatcher: keepAliveAgent })Proposed Solution
Inject a standard or tool-specific
User-Agentinto the headers before passing them toundiciFetch.` ypescript
fetch: (url, init) => {
const headers = new Headers(init?.headers);
if (!headers.has("User-Agent")) {
headers.set("User-Agent", "deepcode-cli/0.1.x (Node.js)");
}
// Note: undiciFetch expects a plain object or an array of arrays for headers in some older TS setups,
// so converting Headers back to an object might be necessary depending on the exact undici version used.
const headersObj = Object.fromEntries(headers.entries());
return undiciFetch(url, {
...init,
headers: headersObj,
dispatcher: keepAliveAgent
});
}
`
Steps to Reproduce
BASE_URLin~/.deepcode/settings.jsonto an API endpoint protected by Cloudflare.deepcodeand send a message.403 Your request was blockederror.