Fetch Failed
Closed this issue · 6 comments
When I execute a chat, i get a load of HTML in the response.
I can see there is a fetch fail
,"buildId":"development","isFallback":false,"err":{"name":"TypeError","source":"edge-server","message":"fetch failed","stack":"TypeError: fetch failed\n at context.fetch (file://C:\\git\\nextjs-chatgpt-app\\node_modules\\next\\dist\\server\\web\\sandbox\\context.js:167:38)\n at OpenAIStream
how might i investigate futher to get a more helpful error?
Thanks for reporting. I want to take a look. Can you paste a screenshot of the code before it happens? (I assume that's via that "play" button on the top right of a piece of code, correct?)
On a second look, it seems like the edge function (/pages/api/chat.ts) cannot connect to the OpenAI API servers.
Can you try this again - as maybe the servers were down in that precise moment.
Debugging this
Verify you can connect to the OpenAI API from your browser:
- Open this link api.openai.com/v1/chat/completions
- You should see a message like this:
This is expected, as we didn't pass any API key to this URL. The OpenAI API servers are responding with a message, but the response is expected.
Run again this app (nextjs-chatgpt-app) and see if now it works
Sometimes it happens. Should work either with "next dev" or "next build" + "next start".
Let me know if there's any improvement.
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
event - compiled client and server successfully in 967 ms (855 modules)
wait - compiling / (client and server)...
event - compiled client and server successfully in 850 ms (1052 modules)
OPENAI_API_KEY has not been provided in this deployment environment. Will use the optional keys incoming from the client, which is not recommended.
error - Error [TypeError]: fetch failed
but when i open settings, the key is still there.
although : Ping request could not find host api.openapi.com. Please check the name and try again.
although : Ping request could not find host api.openapi.com. Please check the name and try again.
This is the issue. Somehow that host is not found. Are you on an enterprise network, or enterprise laptop?
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
event - compiled client and server successfully in 2.4s (855 modules)
wait - compiling / (client and server)...
event - compiled client and server successfully in 1554 ms (1054 modules)
wait - compiling /api/chat (client and server)...
event - compiled successfully in 87 ms (43 modules)
wait - compiling /_error (client and server)...
error - pages/api/chat.ts (52:20) @ fetch
error - fetch failed
50 | };
51 |
52 | const res = await fetch('https://api.openai.com/v1/chat/completions', {
| ^
53 | headers: {
54 | 'Content-Type': 'application/json',
55 | Authorization:Bearer ${apiKey}
,
event - compiled client and server successfully in 550 ms (1055 modules)
I also encountered this problem!!!
although : Ping request could not find host api.openapi.com. Please check the name and try again.
This is the issue. Somehow that host is not found. Are you on an enterprise network, or enterprise laptop?
yes. so , if i can't ping the openai end point, i guess i can't use it from this machine