agentic icon indicating copy to clipboard operation
agentic copied to clipboard

fetch failed (OpenAI API banned in certain countries like China)

Open TyCoding opened this issue 1 year ago • 51 comments

Describe the feature

api request error

fetch failed

TyCoding avatar Mar 02 '23 12:03 TyCoding

same error and use http api directly is worked

ws02589111 avatar Mar 02 '23 12:03 ws02589111

same error

iAqu avatar Mar 02 '23 12:03 iAqu

same error, error message: "fetch failed"

iSonce avatar Mar 02 '23 13:03 iSonce

maybe need use http proxy , i think...

Kylin93CN avatar Mar 02 '23 13:03 Kylin93CN

same error

Charhua avatar Mar 02 '23 13:03 Charhua

Can you please provide more details on the error you're seeing, including some code snippets for how you're using this package?

This error could mean almost anything, and I won't be able to help without more info.

transitive-bullshit avatar Mar 02 '23 13:03 transitive-bullshit

Can you please provide more details on the error you're seeing, including some code snippets for how you're using this package?

This error could mean almost anything, and I won't be able to help without more info.

{"err":"TypeError: fetch failed\n at Object.fetch (node:internal/deps/undici/undici:11118:11)\n at (/app/node_modules/chatgpt/build/index.js:262:25)"}

ws02589111 avatar Mar 02 '23 13:03 ws02589111

Can you please provide more details on the error you're seeing, including some code snippets for how you're using this package? This error could mean almost anything, and I won't be able to help without more info.

{"err":"TypeError: fetch failed\n at Object.fetch (node:internal/deps/undici/undici:11118:11)\n at (/app/node_modules/chatgpt/build/index.js:262:25)"} 好像是中国地区ip被ban了,大家报错的都是在国内吗?

gefeiyanga avatar Mar 02 '23 13:03 gefeiyanga

Can you paste the full JS/TS code that you're using to call ChatGPTAPI?

Also, which Node.js version are you using?

transitive-bullshit avatar Mar 02 '23 13:03 transitive-bullshit

您能否提供有关您看到的错误的更多详细信息,包括您如何使用此软件包的一些代码片段?此错误可能意味着几乎任何事情,如果没有更多信息,我将无法提供帮助。

{“err”:“TypeError: fetch failed\n at Object.fetch (node:internal/deps/undici/undici:11118:11)\n at (/app/node_modules/chatgpt/build/index.js:262:25)”} 好像是中国地区ip被ban了,大家报错的都是在国内吗?

yes

Charhua avatar Mar 02 '23 13:03 Charhua

Can you please provide more details on the error you're seeing, including some code snippets for how you're using this package? This error could mean almost anything, and I won't be able to help without more info.

{"err":"TypeError: fetch failed\n at Object.fetch (node:internal/deps/undici/undici:11118:11)\n at (/app/node_modules/chatgpt/build/index.js:262:25)"} 好像是中国地区ip被ban了,大家报错的都是在国内吗?

Sorry,maybe this is really true

ws02589111 avatar Mar 02 '23 13:03 ws02589111

same error

TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11118:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///home/lizhou/projects/chatgpt/node_modules/chatgpt/build/index.js:265:25 {
  cause: ConnectTimeoutError: Connect Timeout Error
      at onConnectTimeout (node:internal/deps/undici/undici:6625:28)
      at node:internal/deps/undici/undici:6583:50
      at Immediate._onImmediate (node:internal/deps/undici/undici:6614:13)
      at process.processImmediate (node:internal/timers:471:21) {
    code: 'UND_ERR_CONNECT_TIMEOUT'
  }
}

ZoeLeee avatar Mar 02 '23 13:03 ZoeLeee

Yes, I believe that IP addresses in China are banned from calling the OpenAI API.

If you have this problem, you have a few workarounds:

  1. Use a proxy and pass a custom fetch to the ChatGPTAPI constructor which uses you proxy. Note: you'll still need a valid OpenAI API key from their website.
  2. Using a VPN might solve your problem, depending on how aggressive the firewall is.
  3. Use ChatGPTUnofficialProxyAPI instead of ChatGPTAPI, which may not have the same IP bans.

transitive-bullshit avatar Mar 02 '23 13:03 transitive-bullshit

axios has the "proxy" function, but chatGPTAPI use the 'origin fetch' TAT

Kylin93CN avatar Mar 02 '23 13:03 Kylin93CN

Yes, I believe that IP addresses in China are banned from calling the OpenAI API.

If you have this problem, you have a few workarounds:

  1. Use a proxy and pass a custom fetch to the ChatGPTAPI constructor which uses you proxy. Note: you'll still need a valid OpenAI API key from their website.
  2. Using a VPN might solve your problem, depending on how aggressive the firewall is.
  3. Use ChatGPTUnofficialProxyAPI instead of ChatGPTAPI, which may not have the same IP bans.

Thanks for your help!

iSonce avatar Mar 02 '23 13:03 iSonce

Yes, I believe that IP addresses in China are banned from calling the OpenAI API.

If you have this problem, you have a few workarounds:

  1. Use a proxy and pass a custom to the constructor which uses you proxy. Note: you'll still need a valid OpenAI API key from their website.fetch``ChatGPTAPI
  2. Using a VPN might solve your problem, depending on how aggressive the firewall is.
  3. Use instead of , which may not have the same IP bans.ChatGPTUnofficialProxyAPI``ChatGPTAPI

Thanks

Charhua avatar Mar 02 '23 13:03 Charhua

Can you add a proxy option in ChatGPTAPI, please?

huluohu avatar Mar 02 '23 15:03 huluohu

Can you add a proxy option in ChatGPTAPI, please?

This code can help you

npm install https-proxy-agent node-fetch
const api = new ChatGPTAPI({
  fetch: (url, options = {}) => {
        const defaultOptions = {
            agent: require('https-proxy-agent')('http://your-proxy-address:port')
        };

        const mergedOptions = {
            ...defaultOptions,
            ...options
        };

        return require('node-fetch').default(url, mergedOptions);
    }
})

ws02589111 avatar Mar 02 '23 16:03 ws02589111

Can you add a proxy option in ChatGPTAPI, please?

This code can help you

npm install https-proxy-agent node-fetch
const api = new ChatGPTAPI({
  fetch: (url, options = {}) => {
        const defaultOptions = {
            agent: require('https-proxy-agent')('http://your-proxy-address:port')
        };

        const mergedOptions = {
            ...defaultOptions,
            ...options
        };

        return require('node-fetch').default(url, mergedOptions);
    }
})

ok, i'm try ,Thank you!

huluohu avatar Mar 02 '23 16:03 huluohu

同样的错误

TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11118:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///home/lizhou/projects/chatgpt/node_modules/chatgpt/build/index.js:265:25 {
  cause: ConnectTimeoutError: Connect Timeout Error
      at onConnectTimeout (node:internal/deps/undici/undici:6625:28)
      at node:internal/deps/undici/undici:6583:50
      at Immediate._onImmediate (node:internal/deps/undici/undici:6614:13)
      at process.processImmediate (node:internal/timers:471:21) {
    code: 'UND_ERR_CONNECT_TIMEOUT'
  }
}

Yes, I encountered the same mistake. My project has been put into operation in production

Get-wy avatar Mar 03 '23 01:03 Get-wy

Yes, I believe that IP addresses in China are banned from calling the OpenAI API.

If you have this problem, you have a few workarounds:

  1. Use a proxy and pass a custom fetch to the ChatGPTAPI constructor which uses you proxy. Note: you'll still need a valid OpenAI API key from their website.
  2. Using a VPN might solve your problem, depending on how aggressive the firewall is.
  3. Use ChatGPTUnofficialProxyAPI instead of ChatGPTAPI, which may not have the same IP bans.

Using ChatGPTUnofficialProxyAPI also can not in China

Get-wy avatar Mar 03 '23 01:03 Get-wy

image image

I can get result by using curl, but also fetch failed.

gefeiyanga avatar Mar 03 '23 02:03 gefeiyanga

ok, i tried, but i'm fialed;

this is my code please help me check this code thanks;

const api = new ChatGPTAPI({ apiKey, fetch: (url, options = {}) => { const defaultOptions = { agent: require('https-proxy-agent')('http://127.0.0.1:8899') };

const mergedOptions = {
  ...defaultOptions,
  ...options
};

return require('node-fetch').default(url, mergedOptions);

} });

mamahui avatar Mar 03 '23 03:03 mamahui

sorry to ask ; but i really want to know how to get the 'http://your-proxy-address:port' thanks

mamahui avatar Mar 03 '23 03:03 mamahui

This works for me. Thanks all guys!

import { ChatGPTAPI } from "chatgpt";
import proxy from "https-proxy-agent";
import nodeFetch from "node-fetch";

async function example() {
  const api = new ChatGPTAPI({
    apiKey: process.env.OPENAI_API_KEY || "",
    fetch: (url, options = {}) => {
      const defaultOptions = {
        agent: proxy("http://proxy"),
      };

      const mergedOptions = {
        ...defaultOptions,
        ...options,
      };

      return nodeFetch(url, mergedOptions);
    },
  });

  const res = await api.sendMessage("Hello World!");
  console.log(res.text);
}

brooklynb7 avatar Mar 03 '23 03:03 brooklynb7

" http://proxy" this address get from where thanks

mamahui avatar Mar 03 '23 03:03 mamahui

" http://proxy" this address get from where thanks

Such as http://127.0.0.1:1234 It is your Proxy address.

gefeiyanga avatar Mar 03 '23 03:03 gefeiyanga

But I got 'Error: OpenAI error 503' sometimes.

gefeiyanga avatar Mar 03 '23 03:03 gefeiyanga

i set this. but get no replay from openAI

mamahui avatar Mar 03 '23 03:03 mamahui

It's Work

huluohu avatar Mar 03 '23 04:03 huluohu