[GH-ISSUE #265] How to set IP proxy? Requests to openai easily time out #63

Open
opened 2026-03-03 13:52:40 +03:00 by kerem · 6 comments
Owner

Originally created by @xiaowanjiagit on GitHub (Jan 4, 2025).
Original GitHub issue: https://github.com/jehna/humanify/issues/265

(node:5760) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead.
(Use node --trace-deprecation ... to show where the warning was created)
Processing file 1/3
file:///D:/Program%20Files/nodejs/node_global/node_modules/humanifyjs/node_modules/openai/core.mjs:316
throw new APIConnectionError({ cause: response });
^

APIConnectionError: Connection error.
at OpenAI.makeRequest (file:///D:/Program%20Files/nodejs/node_global/node_modules/humanifyjs/node_modules/openai/core.mjs:316:19)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async file:///D:/Program%20Files/nodejs/node_global/node_modules/humanifyjs/dist/index.mjs:55216:26
at async visitAllIdentifiers (file:///D:/Program%20Files/nodejs/node_global/node_modules/humanifyjs/dist/index.mjs:55082:21)
at async file:///D:/Program%20Files/nodejs/node_global/node_modules/humanifyjs/dist/index.mjs:55210:12
at async unminify (file:///D:/Program%20Files/nodejs/node_global/node_modules/humanifyjs/dist/index.mjs:172:27)
at async Command. (file:///D:/Program%20Files/nodejs/node_global/node_modules/humanifyjs/dist/index.mjs:55292:3) {
status: undefined,
headers: undefined,
request_id: undefined,
error: undefined,
code: undefined,
param: undefined,
type: undefined,
cause: FetchError: request to https://api.openai.com/v1/chat/completions failed, reason:
at ClientRequest. (D:\Program Files\nodejs\node_global\node_modules\humanifyjs\node_modules\node-fetch\lib\index.js:1501:11)
at ClientRequest.emit (node:events:518:28)
at emitErrorEvent (node:_http_client:103:11)
at TLSSocket.socketErrorListener (node:_http_client:506:5)
at TLSSocket.emit (node:events:530:35)
at emitErrorNT (node:internal/streams/destroy:170:8)
at emitErrorCloseNT (node:internal/streams/destroy:129:3)
type: 'system',
errno: 'ETIMEDOUT',
code: 'ETIMEDOUT'
}
}

Originally created by @xiaowanjiagit on GitHub (Jan 4, 2025). Original GitHub issue: https://github.com/jehna/humanify/issues/265 (node:5760) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead. (Use `node --trace-deprecation ...` to show where the warning was created) Processing file 1/3 file:///D:/Program%20Files/nodejs/node_global/node_modules/humanifyjs/node_modules/openai/core.mjs:316 throw new APIConnectionError({ cause: response }); ^ APIConnectionError: Connection error. at OpenAI.makeRequest (file:///D:/Program%20Files/nodejs/node_global/node_modules/humanifyjs/node_modules/openai/core.mjs:316:19) at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async file:///D:/Program%20Files/nodejs/node_global/node_modules/humanifyjs/dist/index.mjs:55216:26 at async visitAllIdentifiers (file:///D:/Program%20Files/nodejs/node_global/node_modules/humanifyjs/dist/index.mjs:55082:21) at async file:///D:/Program%20Files/nodejs/node_global/node_modules/humanifyjs/dist/index.mjs:55210:12 at async unminify (file:///D:/Program%20Files/nodejs/node_global/node_modules/humanifyjs/dist/index.mjs:172:27) at async Command.<anonymous> (file:///D:/Program%20Files/nodejs/node_global/node_modules/humanifyjs/dist/index.mjs:55292:3) { status: undefined, headers: undefined, request_id: undefined, error: undefined, code: undefined, param: undefined, type: undefined, cause: FetchError: request to https://api.openai.com/v1/chat/completions failed, reason: at ClientRequest.<anonymous> (D:\Program Files\nodejs\node_global\node_modules\humanifyjs\node_modules\node-fetch\lib\index.js:1501:11) at ClientRequest.emit (node:events:518:28) at emitErrorEvent (node:_http_client:103:11) at TLSSocket.socketErrorListener (node:_http_client:506:5) at TLSSocket.emit (node:events:530:35) at emitErrorNT (node:internal/streams/destroy:170:8) at emitErrorCloseNT (node:internal/streams/destroy:129:3) type: 'system', errno: 'ETIMEDOUT', code: 'ETIMEDOUT' } }
Author
Owner

@jehna commented on GitHub (Jan 4, 2025):

Do you have an unreliable internet? Would setting a proxy help in this case?

<!-- gh-comment-id:2571365946 --> @jehna commented on GitHub (Jan 4, 2025): Do you have an unreliable internet? Would setting a proxy help in this case?
Author
Owner

@xiaowanjiagit commented on GitHub (Jan 5, 2025):

Do you have an unreliable internet? Would setting a proxy help in this case?

yes, unreliable internet

<!-- gh-comment-id:2571462142 --> @xiaowanjiagit commented on GitHub (Jan 5, 2025): > Do you have an unreliable internet? Would setting a proxy help in this case? yes, unreliable internet
Author
Owner

@jehna commented on GitHub (Jan 5, 2025):

I'm pretty sure that you can use HTTP_PROXY and HTTPS_PROXY environment variables to set the http proxy. Current undici seems to support it and I'd assume the underlying openai library would be using undici.

<!-- gh-comment-id:2571539136 --> @jehna commented on GitHub (Jan 5, 2025): I'm pretty sure that you can use `HTTP_PROXY` and `HTTPS_PROXY` environment variables to set the http proxy. Current undici [seems to support it](https://github.com/nodejs/undici/pull/2994) and I'd assume the underlying openai library would be using undici.
Author
Owner

@jehna commented on GitHub (Jan 5, 2025):

Hmm, seems that openai is still using node-fetch, so it might not work:

github.com/openai/openai-node@f4066e1af9/README.md (L2-L5)

<!-- gh-comment-id:2571543044 --> @jehna commented on GitHub (Jan 5, 2025): Hmm, seems that openai is still using node-fetch, so it might not work: https://github.com/openai/openai-node/blob/f4066e1af907586946a5e6befee9459268425680/README.md?plain=1#L2-L5
Author
Owner

@0xdevalias commented on GitHub (Feb 18, 2025):

seems that openai is still using node-fetch, so it might not work

Related upstream issues / workarounds for node-fetch not supporting HTTP_PROXY / etc:

<!-- gh-comment-id:2664841266 --> @0xdevalias commented on GitHub (Feb 18, 2025): > seems that openai is still using `node-fetch`, so it might not work - https://github.com/openai/openai-node/blob/212710db8c8c139392c6532c0eccfd13558ef2d4/README.md?plain=1#L1-L5 - > We're actively working on a new alpha version that migrates from `node-fetch` to builtin `fetch`. > > Please try it out and let us know if you run into any issues! > > - https://community.openai.com/t/your-feedback-requested-node-js-sdk-5-0-0-alpha/1063774 - > **We’re pleased to share that a new alpha of the 5.0.0 version of the JavaScript / TypeScript SDK is [available on npm](https://www.npmjs.com/package/openai/v/5.0.0-alpha.0) and in the [alpha branch of the GitHub repository](https://github.com/openai/openai-node/tree/alpha)**. This version of the SDK represents a breaking change to the existing 4.x SDK, as **we have migrated completely to using built-in `fetch` for HTTP requests across all environments** (Node.js, Deno, etc). However, we do expect that most of your code will “just work” with minor adjustments in types. - > We’re dropping all support for v16 as active support was dropped over 2 years [ago](https://endoflife.date/nodejs). **Our [minimum](https://github.com/openai/openai-node#requirements) supported version is v18.** > > You’ll have to use a polyfill if you want to continue using v16. Related upstream issues / workarounds for `node-fetch` not supporting `HTTP_PROXY` / etc: - https://github.com/node-fetch/node-fetch/issues/1770 - > I've been using [global-agent](https://github.com/gajus/global-agent) with node-fetch for a while now *(though on v2.7 and only for node < v18)* > > ```js > > import * as globalAgent from 'global-agent'; > > process.env["GLOBAL_AGENT_HTTP_PROXY"] = process.env.HTTP_PROXY || "http://my.proxy.address:8888"; > > globalAgent.bootstrap(); > > ``` > > _Originally posted by @lselden in [#1770](https://github.com/node-fetch/node-fetch/issues/1770#issuecomment-1854439586)_ - https://github.com/node-fetch/node-fetch/issues/195 - > For anybody who stumbles on this issue like I did, the easiest way to support http proxies that I've found so far is to use [`global-agent`](https://github.com/gajus/global-agent). It's super easy to install and worked for me so far. > > _Originally posted by @zicklag in https://github.com/node-fetch/node-fetch/issues/195#issuecomment-1240855743_ - https://github.com/gajus/global-agent - > Global HTTP/HTTPS proxy agent configurable using environment variables.
Author
Owner

@0xdevalias commented on GitHub (May 30, 2025):

Looks like openai v5 is out now, which uses the native fetch, and has better support for proxies:

Here's some updates on the timeline as to when node-fetch will no longer be included in it, which I believe will resolve this error:

seems that openai is still using node-fetch, so it might not work

Looks like openai v5 is officially out, which moves to the built-in fetch:

We can see the migration guide here:

We can see that it now supports a new fetchOptions property for customizing the underlying fetch:

fetchOptions is also the basis for how to configure proxies now:

Originally posted by @0xdevalias in https://github.com/jehna/humanify/issues/52#issuecomment-2921148059

<!-- gh-comment-id:2921150326 --> @0xdevalias commented on GitHub (May 30, 2025): Looks like `openai` v5 is out now, which uses the native `fetch`, and has better support for proxies: > > Here's some updates on the timeline as to when `node-fetch` will no longer be included in it, which I believe will resolve this error: > > > > > > seems that openai is still using `node-fetch`, so it might not work > > > > > > - https://github.com/openai/openai-node/blob/212710db8c8c139392c6532c0eccfd13558ef2d4/README.md?plain=1#L1-L5 > > > - > We're actively working on a new alpha version that migrates from `node-fetch` to builtin `fetch`. > > > > > > > > Please try it out and let us know if you run into any issues! > > > > > > > > - https://community.openai.com/t/your-feedback-requested-node-js-sdk-5-0-0-alpha/1063774 > > > - > **We’re pleased to share that a new alpha of the 5.0.0 version of the JavaScript / TypeScript SDK is [available on npm](https://www.npmjs.com/package/openai/v/5.0.0-alpha.0) and in the [alpha branch of the GitHub repository](https://github.com/openai/openai-node/tree/alpha)**. This version of the SDK represents a breaking change to the existing 4.x SDK, as **we have migrated completely to using built-in `fetch` for HTTP requests across all environments** (Node.js, Deno, etc). However, we do expect that most of your code will “just work” with minor adjustments in types. > > Looks like `openai` v5 is officially out, which moves to the built-in `fetch`: > > - https://github.com/jehna/humanify/pull/459 > - https://github.com/openai/openai-node/releases/tag/v5.0.0 > - https://github.com/openai/openai-node/blob/master/CHANGELOG.md#500-2025-05-29 > - https://github.com/openai/openai-node/releases/tag/v5.0.1 > - https://github.com/openai/openai-node/blob/master/CHANGELOG.md#501-2025-05-29 > > We can see the migration guide here: > > - https://github.com/openai/openai-node/blob/master/MIGRATION.md > - > The main changes are that the SDK now relies on the [builtin Web fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) instead of `node-fetch` and has zero dependencies. > > We can see that it now supports a new `fetchOptions` property for customizing the underlying `fetch`: > > - https://github.com/openai/openai-node/blob/master/MIGRATION.md#removed-httpagent-in-favor-of-fetchoptions > - > Removed `httpAgent` in favor of `fetchOptions` > > > > The `httpAgent` client option has been removed in favor of a [platform-specific `fetchOptions` property](https://github.com/openai/openai-node#fetch-options). This change was made as `httpAgent` relied on `node:http` agents which are not supported by any runtime's builtin `fetch` implementation. > > > > If you were using `httpAgent` for proxy support, check out the [new proxy documentation](https://github.com/openai/openai-node#configuring-proxies). > - https://github.com/openai/openai-node#fetch-options > - > Fetch options > > If you want to set custom fetch options without overriding the fetch function, you can provide a fetchOptions object when instantiating the client or making a request. (Request-specific options override client options.) > > `fetchOptions` is also the basis for how to configure proxies now: > > - https://github.com/openai/openai-node#configuring-proxies > - > Configuring proxies > > > > To modify proxy behavior, you can provide custom `fetchOptions` that add runtime-specific proxy options to requests: > > _Originally posted by @0xdevalias in https://github.com/jehna/humanify/issues/52#issuecomment-2921148059_
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/humanify#63
No description provided.