openai-node icon indicating copy to clipboard operation
openai-node copied to clipboard

connect ETIMEDOUT - API's are not working

Open founders-growthways opened this issue 1 year ago • 6 comments

Describe the bug

Below attach code is working fine in curl, python but the same set of code is not working in Node JS (tried different versions) as well.

Below error -

Uncaught Error: connect ETIMEDOUT 64:ff9b::3498:60fc:443 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) { errno: -4039, code: 'ETIMEDOUT', syscall: 'connect', address: '64:ff9b::3498:60fc',

To Reproduce

Run the program in node shell and you will get the error

Code snippets

const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);

const completion = await openai.createCompletion({
  model: "text-davinci-003",
  prompt: "Hello world",
});
console.log(completion.data.choices[0].text);

OS

macOS

Node version

Node v18.14.2

Library version

[email protected] / [email protected] / [email protected]

founders-growthways avatar Mar 06 '23 22:03 founders-growthways

I have the same issue and could not resolve it.

KevinnZhao avatar Mar 07 '23 08:03 KevinnZhao

same issue

Developeranees avatar Mar 07 '23 15:03 Developeranees

I also encountered the same problem, did you solve it?

tsix2019 avatar Mar 08 '23 08:03 tsix2019

Openai's API is blocked in China. If you want to continue using it, you can use a foreign node to build services。I do this now, and use it normally。

Jarvan-via avatar Mar 09 '23 02:03 Jarvan-via

Modify Agent.

链接

1442916418 avatar Mar 10 '23 02:03 1442916418

Modify Agent.

链接

My service runs on Tencent Cloud without its own agent. But for local debugging, it may be a good solution

Jarvan-via avatar Mar 10 '23 03:03 Jarvan-via

In your code snippet, you're trying to use the text-davinci-003 model. But looking at the code, it appears the currently only gpt-3.5-turbo and gpt-3.5-turbo-0301 models are supported.

https://github.com/openai/openai-node/blob/0363de20747e272a92e41da4a4c4293104aa9461/dist/api.d.ts#L261-L266

The solution would be to make requests directly yourself, instead of using the openai-node package - here's how.

Lissy93 avatar Mar 17 '23 23:03 Lissy93

修改代理。 链接

我的服务运行在腾讯云上,没有自带代理。但是对于本地调试来说,这可能是一个很好的解决方案

对服务器节点有要求吗?需要国外节点的服务器吗?

Lands-1203 avatar May 23 '23 03:05 Lands-1203

修改代理。 链接

我的服务运行在腾讯云上,没有自带代理。但是对于本地调试来说,这可能是一个很好的解决方案

对服务器节点有要求吗?需要国外节点的服务器吗?

是的,需要国外的服务器的节点,我现在用的是 美国 加州的节点 ,正常使用。

Jarvan-via avatar May 23 '23 03:05 Jarvan-via

You may encounter ETIMEDOUT if there is a problem connecting from your computer to OpenAI's servers, perhaps because it is blocked somewhere along the chain, or due to networking issues.

In some cases, this may be due to regional restrictions; you may want to check the list of supported countries.

If you encounter this issue when using the SDK but not when making the request directly, please open a new issue on this repo.

Related: https://github.com/openai/openai-node/issues/148

rattrayalex avatar Jul 10 '23 00:07 rattrayalex