I have used the Dalle-2 API for months to generate images without fail. Today I made my first attempt to use Dalle-3. Unfortunately I am geting 400 BAD_REQUEST errors every time. Below is the error object I am getting from the Axios POST request, with my request object embedded.
Hi Paul. Iām using the axios fetch library from my Node.js back-end server. It worked fine with Dalle-2:
// For now, Dalle-3 only allows one image to be created at a time.
if (theNumberOfImagesToMake !== 1)
throw new Error(`${errPrefix}Dalle-3 only generates one image at a time. Use parallel calls to this function (see generateImagesWithDalle3())`);
const Dalle3RequestObj =
{
model: theModel,
prompt: usePrompt,
n: theNumberOfImagesToMake, // Number of images to generate. Must be set to 1 for now.
size: `${theImageSize}x${theImageSize}`,
// NOTE!!: The response format 'b64_json' is oddly named.
// It is absolutely not a JSON object or an object at all.
// It's just the name of a property that you will find in each
// result element in the results array that contains a PNG
// image in base 64 encoded string format.
response_format: 'b64_json',
}
try {
if (bVerbose)
console.info('generate-images', `Making generate image request to Dalle-3 with prompt: ${Dalle3RequestObj.prompt}`);
const responseObj = await axios.post(
URL_OPENAI_DALLE_3_ENDPOINT,
Dalle3RequestObj,
{
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${apiKey}`
},
}
);
Yes I did look at those pages you linked me. Thanks. I didnāt see anything different than what I was doing, except for the fact that I have to do 1 image at a time.
In your code, you have specified the model as "dalle-e-3", but according to the documentation, the correct parameter should be "dall-e-3" (without the extra āeā)
Thanks Paul! That was it. Is there any way to get more detailed information about what causes a 400 error? Perhaps something like āinvalid model nameā in this case?
Well, 400 in general is ābad request,ā but I missed the typo on my first glance. With a 400 error, though, you want to look at what youāre sending - parameters. Glad you got it sorted.