adrianhajdin / project_ai_mern_image_generation

Build and Deploy a Full Stack MERN AI Image Generation App MidJourney & DALL E Clone
https://jsmastery.pro
1.08k stars 302 forks source link

SyntaxError: Unexpected token 'B', "Billing ha"... is not valid JSON #33

Open binyamdawit opened 1 year ago

binyamdawit commented 1 year ago

I have seen a lot of comments regarding this issue. Here's the solution:

In your CreatePost.jsx file the Screenshot 2023-02-19 053921

Change that line on the above image to this: const response = await fetch('http://localhost:8080/api/v1/dalle', {

The reasoning is of course the domain name

NikoSAN02 commented 1 year ago

Changed it but still getting the same error. In the console log, it seems Delle is failing the request.

nishhdgop commented 1 year ago

Hey Even I had the same issue use the below code in CreatePost.jsx const response = await fetch("http://localhost:8080/api/v1/dalle", { method: "POST", headers: { "Content-Type": "application/json", } use this code in the try catch block of generateImage async function

NikoSAN02 commented 1 year ago

I was able to fix it by using a new account for Open-AI. Works fine for me now.

Saksham1005 commented 1 year ago

I just want to ask that even if we want to use our free credits do we have to register our card on the site?

NikoSAN02 commented 1 year ago

Nope

On Mon, Apr 3, 2023, 11:43 Saksham1005 @.***> wrote:

I just want to ask that even if we want to use our free credits do we have to register our card on the site?

— Reply to this email directly, view it on GitHub https://github.com/adrianhajdin/project_ai_mern_image_generation/issues/33#issuecomment-1493720705, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZ5CLZQTHWDAL3VYMVQBPH3W7JTBNANCNFSM6AAAAAAVA5CT4Q . You are receiving this because you commented.Message ID: @.*** .com>

yashwant1711 commented 1 year ago

i am doing exactly same things but not working for me :(

yashwant1711 commented 1 year ago

can anyone tell me status code while trying this code ??

dastageer-eth commented 1 year ago

was anyone able to fix it?

diwakar-tiwari commented 1 year ago

you need to make a new account at open ai and use the api key from the new account. You are facing this error because the api is paid. With the new account you will get 5$ worth of free credits, each api call costs 0.02$ so be careful making too much requests.

Darkcoder-paditya commented 1 year ago

guys, use this: var openai = new OpenAIApi(configuration); instead of : const openai = new OpenAIApi(configuration);

Change const to var

worked for me

khanfaysal commented 1 year ago

is show any custom message instead of default billing message? anyone hints me. image

Samrat1507 commented 1 year ago

image The community showcase does not show anything the pictures are being stored on cloudinary but it just loads and does not stop

Samrat1507 commented 1 year ago

is show any custom message instead of default billing message? anyone hints me. image

make a new account on openai and use a new key your old acc got expired as mine one did

soumizde commented 1 year ago

There can be a few issues:

  1. Check if you have enough credits in your Open AI account
  2. Put the url in double quotes instead of single ones. So it should be await fetch("", . . .
  3. see if you are putting this

    setForm({ ...form, photo: data:image/jpeg;base64,${data.photo}})

suyash-2002 commented 1 year ago

Changed it but still getting the same error. In the console log, it seems Delle is failing the request.

how did you resolve this error

Sarthak-16XO commented 1 year ago

Hey Even I had the same issue use the below code in CreatePost.jsx const response = await fetch("http://localhost:8080/api/v1/dalle", { method: "POST", headers: { "Content-Type": "application/json", } use this code in the try catch block of generateImage async function

Use the above code and also create new OpenAI api acct so you get free trial of the model and yeah it works!

andrehugofernandes commented 1 year ago

There can be a few issues:

  1. Check if you have enough credits in your Open AI account
  2. Put the url in double quotes instead of single ones. So it should be await fetch("", . . .
  3. see if you are putting this setForm({ ...form, photo: data:image/jpeg;base64,${data.photo}})
  • you might be using single quotes instead of single ticks and it may result in the data not being fetched and read

It´s imperative to use single: setForm({ ...form, photo: data:image/jpeg;base64,${data.photo} }); There´s a ${} in there.

jai-gaur-210 commented 1 year ago

made an new account on open api and the error persists SyntaxError: Unexpected token 'B', "Billing ha"... is not valid JSON anyone please help

soumizde commented 1 year ago

Check if you have updated the environment variables and entered the new valid API key. Restart the server.

If you have and the problem persists, try putting the fetch url in double quotes. That is what worked for me as well as many others. Hope it helps.

jai-gaur-210 commented 1 year ago

yeah did all that but that doesn't work....the thing was they needed a payment method and once I registered my debit card things started working....thanks for the help.

nishaaannnt commented 1 year ago

To anyone still facing this issue there are only two solutions :

  1. Create a new OpenAI account with new phone number , this will grant you $5 trial, then generate a new API key and use it.
  2. Pay for the API itself.

I almost tried all the other methods to solve the issue and to no use. Although in my usage section it shows I haven't used a single dollar or made a single request. So yeah maybe this is an issue by OpenAI pending to be fixed. Try the first option and it should work.

Hope it helps.

Kasifmansuri7 commented 1 year ago

You have not upgraded to a paid plan yet. To add a payment method and start paying for API usage, go to the Billing overview page and click "Set up payment" to continue.

Kasifmansuri7 commented 1 year ago

it is billing issue i think

lazarevkristijan commented 1 year ago

https://platform.openai.com/account/usage Use this link to check out your usage and if you have any free usages left. It's clearly written just need to log in if not logged in.

Hope it helps just to know if it is that you don't have credits or there is an issue with your code if you do have credits and it still doesn't work!

Kasifmansuri7 commented 1 year ago

Just create new account and change the response from base64 to url...thats it

GKozlowskiDesign commented 1 year ago

For me I had to create a paid account, it did not matter if I created new accounts.

SETHEAD commented 1 year ago

yeah did all that but that doesn't work....the thing was they needed a payment method and once I registered my debit card things started working....thanks for the help.

hey did it actually work by just registering a payment method?? you didn't do any other changes to the code??

Kasifmansuri7 commented 1 year ago

Register new account and generate new api

On Tue, 1 Aug, 2023, 8:28 pm SETHEAD, @.***> wrote:

yeah did all that but that doesn't work....the thing was they needed a payment method and once I registered my debit card things started working....thanks for the help.

hey did it actually work by just registering a payment method?? you didn't do any other changes to the code??

— Reply to this email directly, view it on GitHub https://github.com/adrianhajdin/project_ai_mern_image_generation/issues/33#issuecomment-1660499121, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3LZL62DX4KCGLLXQSHORY3XTEKQFANCNFSM6AAAAAAVA5CT4Q . You are receiving this because you commented.Message ID: @.*** .com>

SETHEAD commented 1 year ago

Register new account and generate new api On Tue, 1 Aug, 2023, 8:28 pm SETHEAD, @.> wrote: yeah did all that but that doesn't work....the thing was they needed a payment method and once I registered my debit card things started working....thanks for the help. hey did it actually work by just registering a payment method?? you didn't do any other changes to the code?? — Reply to this email directly, view it on GitHub <#33 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3LZL62DX4KCGLLXQSHORY3XTEKQFANCNFSM6AAAAAAVA5CT4Q . You are receiving this because you commented.Message ID: @. .com>

I created a new account only but still it's not working. Do I need to create an account with a different phone number also?

007unique commented 1 year ago

This error occurs due to OpenAI API Credit . For this problem you need a new account with no expired credit. Check your account credit https://platform.openai.com/account/usage if credit is expire than create a new account with new mobile number it may be give you free credit or use others account which have credit left on.

Also Check ,

  1. Home.jsx
Screenshot_20230806_115438
  1. CreatePost.jsx
Screenshot_20230806_115427 Screenshot_20230806_115420 Screenshot_20230806_115411
Sufi8959 commented 1 year ago

I also had the same issue. I tried to fix but it turns out that my credits got expired last month. Do I need to make a new account to get the free credits again?

Vigneshwaran-VK-21 commented 1 year ago

SyntaxError: Unexpected token 'B', "Billing ha"... is not valid JSON. Solution please..

SETHEAD commented 1 year ago

This error occurs due to OpenAI API Credit . For this problem you need a new account with no expired credit. Check your account credit https://platform.openai.com/account/usage if credit is expire than create a new account with new mobile number it may be give you free credit or use others account which have credit left on.

Also Check ,

  1. Home.jsx
Screenshot_20230806_115438
  1. CreatePost.jsx

Screenshot_20230806_115427 Screenshot_20230806_115420 Screenshot_20230806_115411

so if I do all these methods and do the changes to home and createpost page, will it work ?

isaacmobe commented 11 months ago

Guys can someone add sign up and log in functionality to the whole application, how would i go through that. thanks guys

Sam-ops09 commented 11 months ago

Hey Even I had the same issue use the below code in CreatePost.jsx const response = await fetch("http://localhost:8080/api/v1/dalle", { method: "POST", headers: { "Content-Type": "application/json", } use this code in the try catch block of generateImage async function

nope still the same error

Onnati commented 10 months ago

I have tried all the above solutions but none is working:(, someone please help!

harshilmadaliya commented 10 months ago

please some answer

HrishikeshDeshmukh commented 7 months ago

Hello Guys, Its not the issue of the code, it is because of existing account in openai. Make new Account of OpenAi using extra google account. for new account you have some credit given to use, and these the service can be use easily.

Thanks me Later..