openai-node
openai-node copied to clipboard
connect ETIMEDOUT - API's are not working
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
I have the same issue and could not resolve it.
same issue
I also encountered the same problem, did you solve it?
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。
Modify Agent.
My service runs on Tencent Cloud without its own agent. But for local debugging, it may be a good solution
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.
修改代理。 链接
我的服务运行在腾讯云上,没有自带代理。但是对于本地调试来说,这可能是一个很好的解决方案
对服务器节点有要求吗?需要国外节点的服务器吗?
是的,需要国外的服务器的节点,我现在用的是 美国 加州的节点 ,正常使用。
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