openai-openapi icon indicating copy to clipboard operation
openai-openapi copied to clipboard

Error 400 on Image generation

Open agerman77 opened this issue 2 years ago • 13 comments

Hi there, anyone else having troubles to generate images on the openAI.createImage method? I'm getting a 400 Error response from the openAI endpoint.

Any idea? Thanks in advance.

agerman77 avatar Feb 02 '23 09:02 agerman77

Hi there, again... I found the solution. It turns out that error 400 (in this context) is related to possible author rights in image generation. It could also be related to terms or expressions not allowed in openAI.

agerman77 avatar Feb 02 '23 11:02 agerman77

I am getting this as well with even a simple prompt like dinosaur

This is the basic code I am using in Node JS.

const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
	organization: process.env.OPENAI_ORG,
	apiKey: process.env.OPENAI_KEY,
});

const openai = new OpenAIApi(configuration);

const response = await openai.createImage({
	prompt: "dinosaur",
	n: 1,
	size: "512x512",
	response_format: "url"
});

This is the error:

Error: Request failed with status code 400
    at createError (/home/container/node_modules/openai/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/home/container/node_modules/openai/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/home/container/node_modules/openai/node_modules/axios/lib/adapters/http.js:322:11)
    at IncomingMessage.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

yash1441 avatar Apr 04 '23 08:04 yash1441

I am encountering similar issue with my Open-Ai Image generation application.

Error: Request failed with status code 400 at createError (C:\Users\Osama\Open-A.I\backend\node_modules\axios\lib\core\createError.js:16:15) at settle (C:\Users\Osama\Open-A.I\backend\node_modules\axios\lib\core\settle.js:17:12) at IncomingMessage.handleStreamEnd (C:\Users\Osama\Open-A.I\backend\node_modules\axios\lib\adapters\http.js:322:11) at IncomingMessage.emit (node:events:525:35) at endReadableNT (node:internal/streams/readable:1359:12) at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

response: { status: 400, statusText: 'Bad Request'

I have tried generating a new API key but it did not solve my issue. Would be grateful if someone has a solution this issue. 

MuhammadOsama169 avatar Apr 05 '23 19:04 MuhammadOsama169

I am encountering similar issue Error: Request failed with status code 400 at createError (D:\!PROJET TEMPLATE\three-framer\server\node_modules\axios\lib\core\createError.js:16:15) at settle (D:\!PROJET TEMPLATE\three-framer\server\node_modules\axios\lib\core\settle.js:17:12) at IncomingMessage.handleStreamEnd (D:\!PROJET TEMPLATE\three-framer\server\node_modules\axios\lib\adapters\http.js:322:11) at IncomingMessage.emit (node:events:525:35) at endReadableNT (node:internal/streams/readable:1359:12) at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Notoavina3X avatar Apr 06 '23 13:04 Notoavina3X

I copy and pasted the node.js code from the openai documentation to generate an image const response = await openai.createImage({ prompt: "a white siamese cat", n: 1, size: "1024x1024", }); and I still get a bad request error. I generated a new api key and while openai registers that I am using the key, it does not fix the problem. Not sure what could be causing this.

roesnera avatar Apr 29 '23 22:04 roesnera

I asked Open AI about this issue and this is what they replied me with: 23 Its very confusing because even if i generate a new key and fix my security issue. It still does not work. And you guys can check your own fetch request by using postman.

22

So yeah no solution yet because error 400 is not even described on Open AI FAQs https://help.openai.com/en/articles/6891839-api-error-code-guidance

MuhammadOsama169 avatar Apr 30 '23 11:04 MuhammadOsama169

Hi Muhammad. The error doesnt say that the key is invalid. Look at the error codes here. https://platform.openai.com/docs/guides/error-codes. 401 would be an invalid key. Your issue is related to the tokens you require to complete the request as you have exceeded your billing request. This may very possibly be related to a key leaked into the wild but you should start by going to https://platform.openai.com/account/billing/limits and checking what your limit is. Be super careful of your key. If you check it into a git, you doing it wrong.

Netizine avatar Apr 30 '23 13:04 Netizine

FYI: https://help.openai.com/en/articles/6614457-why-am-i-getting-an-error-message-stating-that-i-ve-reached-my-usage-limit

Netizine avatar Apr 30 '23 13:04 Netizine

Still failing for me now, I have used $.03 of a $100 budget. Trying to generate a 256x256, should fit in the budget!

millisecond avatar May 05 '23 01:05 millisecond

this is also failing for me, I have the free budget, which is $18, each call should be costing me cents, still getting this 400 error

nicolaseschneider avatar May 06 '23 00:05 nicolaseschneider

I did finally get through this, it was a mis-named parameter causing the 400. If you handle the error like below it should tell you which field, if it's the same issue.

    if (error.response) {
        console.log("Avatar error status: ", error.response.status);
        console.log("Avatar error data: ", error.response.data);
      } else {
        console.log("Avatar error message: ", error.message);
      }

millisecond avatar May 06 '23 00:05 millisecond

What was the named parameter? I've read that the 'Content-Type' header within the POST request should be deleted but when doing that I still get an error (415 instead of 400)

robriks avatar May 25 '23 07:05 robriks

I did finally get through this, it was a mis-named parameter causing the 400. If you handle the error like below it should tell you which field, if it's the same issue.

    if (error.response) {
        console.log("Avatar error status: ", error.response.status);
        console.log("Avatar error data: ", error.response.data);
      } else {
        console.log("Avatar error message: ", error.message);
      }

It helped me too. Thanks @millisecond

devarsalanali avatar Jun 17 '23 20:06 devarsalanali

I did finally get through this, it was a mis-named parameter causing the 400. If you handle the error like below it should tell you which field, if it's the same issue.

    if (error.response) {
        console.log("Avatar error status: ", error.response.status);
        console.log("Avatar error data: ", error.response.data);
      } else {
        console.log("Avatar error message: ", error.message);
      }

This code help me to find what i was doing wrong, Thanks! @millisecond

Victor-Palha avatar Jul 10 '23 21:07 Victor-Palha

I did finally get through this, it was a mis-named parameter causing the 400. If you handle the error like below it should tell you which field, if it's the same issue.

    if (error.response) {
        console.log("Avatar error status: ", error.response.status);
        console.log("Avatar error data: ", error.response.data);
      } else {
        console.log("Avatar error message: ", error.message);
      }

This code helped me identify the issue. My case was the prompt is too long.

AliHewiagh avatar Jul 24 '23 10:07 AliHewiagh

Closing this out, the right place of discussion is https://community.openai.com

logankilpatrick avatar Sep 06 '23 02:09 logankilpatrick