adrianhajdin/project_ai_mern_image_generation

TypeError: Failed to fetch

sreeramp-official opened this issue · 35 comments

I am unable to generate image. Every time I try to generate an image the following error is showing:

Screenshot from 2024-04-07 07-47-39

Error:
Access to fetch at 'https://dalle-arbb.onrender.com/api/v1/dalle' from origin 'http://localhost:5173' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
CreatePost.jsx:31

POST https://dalle-arbb.onrender.com/api/v1/dalle net::ERR_FAILED

Can anyone please help me?

Hey @sreeram3015 Is your code publically available ? My project working fine (did some changes because the code provided in the yt video is old) let me know I will try to check out what's the issue.

Hey @sreeram3015 Is your code publically available ? My project working fine (did some changes because the code provided in the yt video is old) let me know I will try to check out what's the issue.

Can you share what you have changed in the code which resolved the issue. I too am facing the problem while generating a picture.

Can you share what you have changed in the code which resolved the issue. I too am facing the problem while generating a picture.

Well I updated many parts of the code which I can't recall right now
This is my repo link
without checking side by side I can't tell which part I changed sorry for that.
One change I remember is I changed the OpenAI API call code in server/routes/dalleRoute.js

https://github.com/ItsAnkitPatel/DALL-E/blob/304b68a98e21c0cb4ae84aa8f9792f9695eaef19/server/routes/dalleRoutes.js#L20

Can you share what you have changed in the code which resolved the issue. I too am facing the problem while generating a picture.

Well I updated many parts of the code which I can't recall right now This is my repo link without checking side by side I can't tell which part I changed sorry for that. One change I remember is I changed the OpenAI API call code in server/routes/dalleRoute.js

https://github.com/ItsAnkitPatel/DALL-E/blob/304b68a98e21c0cb4ae84aa8f9792f9695eaef19/server/routes/dalleRoutes.js#L20

i think i made some blunder and might need your help, where can i reach you

i think i made some blunder and might need your help, where can i reach you

I see, can you share your repo ? I will try to look into it too.
And I am available at discord
Discord username: ankit_patel

i think i made some blunder and might need your help, where can i reach you

I see, can you share your repo ? I will try to look into it too. And I am available at discord Discord username: `ankit_patel

Texted you

I am also facing same ptoblem

I am also facing same ptoblem

Can you share your code repo?

bro i m also facing a problem i have downloaded your version of code and i have checked but i m getting "api limit reached error"

bro i m also facing a problem i have downloaded your version of code and i have checked but i m getting "api limit reached error"

Well that only happens when the user sent the too long prompt or the api is expired.

Are you using your own API key ?

yes i m using my own api that all i did and prompt was made using that surprise me button

Screenshot 2024-04-12 at 1 20 05 AM bro do i need to buy subscription to use the feature?
Screenshot 2024-04-12 at 1 20 05 AM bro do i need to buy subscription to use the feature?

Well if you want to use the current account then yes. If you want you can create a different account but the catch is for creating API key they will ask for phone number verification so if you have extra numbers you can use them to create api keys.

yes i m using my own api that all i did and prompt was made using that surprise me button

Then most likely your api key is expired.

I am also facing same ptoblem

Can you share your code repo?

@Rutuja1427 are you still facing the issue if yes then you can ask @Archana2806 for her help too.. Her project issue is resolved..
She can help you..

@Archana2806 can you help me i am facing error while fetch an api

Screenshot (12)
API limit reached this error but there is no usage

Screenshot (13)
@ItsAnkitPatel

Is this my project ?
If yes then it won't work bcs my backend is hosted on a different server whose url is not given bcs of security reasons. So you have to run(host) the server on your machine too..

And that API limit reached is just a custom msg. I will configure it in a better way to give better error information.

Let me know if there are other issues.
And also can you upload your code on github? so that I can run it on my machine for faster debugging.

You can also message me on discord username: ankit_patel

@Rutuja1427 Have u received free credits from OpenAI or have you paid to get any! if yes there might be some issue with the environment variable or code. if no you got to get credits for image generation.

Screenshot (12) API limit reached this error but there is no usage

@Archana2806 was right.. @Rutuja1427 you don't have any credits from openai.. first generate the api key then you will see usd grants in your account..

This is how my account look like.. on the right side you can see the info ? That's how it will look like if you have credits..

image

I tried using different mobile no. which i haven't used before but its showing that its used for another account.

I tried using different mobile no. which i haven't used before but its showing that its used for another account.

Someone(frined/family member) who is into openai API may be used your number ? I don't know what might be other reason if you are using a new number.. it should work but I don't know the solution of this either.. sorry.

No its fine,And One more thing how did you uploaded it on vercel can u tell me the procedure??

do i have create build folder then navigate it to backend ??

No its fine,And One more thing how did you uploaded it on vercel can u tell me the procedure??

Well YT video is enough. I also got to know from there too. Vercel will ask for repo access. Internally it runs the npm build so you don't need to do it.
Hosting fronted is easy in Vercel. When it comes to hosting backend it's quite tricky in Vercel (render is easy to use in this case)
Just directly upload the project on GitHub repo that's enough and give access to the Vercel (node modules upload not important)

(And one suggestion.. you can edit your messages.. so posting mutiple messages is not a good idea)

Oh oKay Thanks Alot Brother!!

Screenshot 2024-04-17 at 11 48 47 PM bro i m getting the above errors after uploading! i want to know what all chnages you did while uploading and how did you navigated it to client -fronted
Screenshot 2024-04-18 at 12 10 39 AM now the backend is working but how to display the frontend

Screenshot 2024-04-17 at 11 48 47 PM bro i m getting the above errors after uploading! i want to know what all chnages you did while uploading and how did you navigated it to client -fronted

Hmm.. first thing when you were uploading did you choose the directory in Vercel for this project ? It will be ./client for this project.. try to check this part... bcs if this part is not set Vercel will run the npm run build on root and as you know there is only client and server folder on the root no veet configuration at all..

image

First change the root directory to client if you still face errors after this just msg me on discord(username: ankit_patel) we will together figure out

Screenshot 2024-04-18 at 12 10 39 AM now the backend is working but how to display the frontend

After doing the correction in root directory just add your render server link inside environment section of Vercel and it will work... if it doesn't let me know via discord (for faster communication)

Screenshot 2024-04-18 182257
can anyone help me to solve this

@deep55gariya can you also share the browser console output to see the more descriptive error..?
Is your code available on github ?

ankit_patel

bro i have sent you friend request in discord.Cient is working and you told me to add some link in environment variable right can u explain me that??

ankit_patel

bro i have sent you friend request in discord.Cient is working and you told me to add some link in environment variable right can u explain me that??

Ok.. for env you have to add on client and server both