adrianhajdin/project_ai_mern_image_generation

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

binyamdawit opened this issue Β· 38 comments

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

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

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

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

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?

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

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

was anyone able to fix it?

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.

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

Change const to var

##worked for me

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

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

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

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

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

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!

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.

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

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.

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.

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.

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.

it is billing issue i think

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!

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

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

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??

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?

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

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?

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

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 2. 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 ?

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

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

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

please some answer

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..