Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Build Your Own AI Image Generator

Gary M.
Gary M.
14,187 Points

Open AI errors. Get the following error.

Looks like OPEN AI free wont work. Its telling me I'm hiting a billilng cap even though I've never used it even once.

app.js:25 POST https://api.openai.com/v1/images/generations 400 generateImage @ app.js:25

(anonymous) @ app.js:16

app.js:45 {error: {…}}error: {code: 'billing_hard_limit_reached', message: 'Billing hard limit has been reached', param: null, type: 'invalid_request_error'}

[[Prototype]]: Objectconstructor: ƒ Object()hasOwnProperty: ƒ hasOwnProperty()isPrototypeOf: ƒ isPrototypeOf()propertyIsEnumerable: ƒ propertyIsEnumerable()toLocaleString: ƒ toLocaleString()toString: ƒ toString()valueOf: ƒ valueOf()defineGetter: ƒ defineGetter()defineSetter: ƒ defineSetter()lookupGetter: ƒ lookupGetter()lookupSetter: ƒ lookupSetter()proto: (...)get proto: ƒ proto()set proto: ƒ proto()

app.js:25 Fetch failed loading: POST "https://api.openai.com/v1/images/generations".

3 Answers

Chris Komaroff
PLUS
Chris Komaroff
Courses Plus Student 14,198 Points

It looks like dalle API does NOT want you do include the model argument. It will just default to a correct value. Very confusing. Also noticed, since this is probably not model 'image-alpha-001' anymore, the pages argument is 'n' and not 'num_images'.

fetch(dalle_api_url, {
    method: 'POST',
    headers: {
        "Content-Type": "application/json",
        "Authorization": `Bearer ${api_key}`
    },
    body: JSON.stringify({
        // model: '',  // Not allowed?
        prompt: prompt_value,
        n: 1,
        size: '512x512',
        response_format: 'url',
    })
}).then(res => res.json())
  .then(data => handleImage(data))
  .catch(error => handleError(error))
Gary M.
Gary M.
14,187 Points

Ok ...

Looks like I DID in fact check out open Ai about 4 months ago but never used it. So according to them my THREE month token is expired and I have to set up a pay account to use the API, even in testing mode.

lame.

received the same error, why god why...

Chris Komaroff
Chris Komaroff
Courses Plus Student 14,198 Points

Hi, see my comment below yours. I was able to get this to work Nov 17, 2023.