openai-openapi
openai-openapi copied to clipboard
Error 400 on Image generation
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.
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.
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)
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.
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)
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.
I asked Open AI about this issue and this is what they replied me with:
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.

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
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.
FYI: https://help.openai.com/en/articles/6614457-why-am-i-getting-an-error-message-stating-that-i-ve-reached-my-usage-limit
Still failing for me now, I have used $.03 of a $100 budget. Trying to generate a 256x256, should fit in the budget!
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
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);
}
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)
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
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
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.
Closing this out, the right place of discussion is https://community.openai.com