Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix 403 Forbidden: Add User-Agent header to OpenAI client fetch to prevent WAF/Cloudflare blocks #177

Open

Description

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

  1. Set BASE_URL in ~/.deepcode/settings.json to an API endpoint protected by Cloudflare.
  2. Run deepcode and send a message.
  3. Observe the 403 Your request was blocked error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /