I’m encountering a consistent 413 Payload Too Large
error when using the /v1/images/edit
endpoint, even though my image is well under the documented size limits. I’m hoping someone from the community or OpenAI team can provide some insight.
Environment
- API Version: Latest (May 2025)
- Model: gpt-image-1
- Endpoint:
/v1/images/edit
- Image Format: PNG
- Image Size: 1.84MB (1,930,822 bytes)
- Request Method: POST with multipart/form-data
Issue Details
According to the documentation, the size limits are:
- For dall-e-2: Square PNG file less than 4MB
- For gpt-image-1: PNG, WebP, or JPG file less than 25MB
My image is 1.84MB, which is well under both limits. However, I consistently receive a 413 Request Entity Too Large
error from nginx when attempting to make the request.
Here’s the error response:
<html>
<head><title>413 Request Entity Too Large</title></head>
<body>
<center><h1>413 Request Entity Too Large</h1></center>
<hr><center>nginx</center>
</body>
</html>
What I’ve Tried
-
Image Optimization: I’ve already implemented image optimization to reduce the size:
- Resized the image from 1024px to 768px
- Reduced quality from 100 to 85
- Ensured proper PNG format
-
Request Formatting: I’m using standard FormData to construct the request:
const formData = new FormData(); formData.append("model", "gpt-image-1"); formData.append("prompt", "Edit the image to change the woman's hair color to bleach blonde while keeping everything else the same."); formData.append("size", "1024x1024"); formData.append("response_format", "b64_json"); formData.append("n", "1"); formData.append("image", imageBlob, "image.png");
-
Debugging: I’ve confirmed the image blob size is 1.84MB before sending, which should be acceptable according to the documentation.
Questions
-
Is there a discrepancy between the documented size limits and the actual implementation?
-
Does the size limit apply to the entire request payload (including FormData overhead, boundaries, headers, etc.) rather than just the image file itself?
-
Are there different limits for the
/images/edit
endpoint compared to other image endpoints? -
Are there any undocumented requirements or best practices for reducing request size when using the images edit API?
Additional Context
I’m using a server-side implementation with a Cloudflare Worker that fetches the image, transforms it (using Supabase Storage transformations), and then sends it to the OpenAI API. The logs confirm the image size is 1.84MB before sending.
Any insights or suggestions would be greatly appreciated. Thank you!
Code Sample (for reference)
Here’s a simplified version of my image processing and API call:
async function handleGenerateImage(request) {
// Parse request body and validate
const { prompt, images, size = "1024x1024" } = await request.json();
// Process image
const imageBlob = await fetchImageAsBlob(images[0]);
console.log("Image blob size:", imageBlob.size, "bytes", (imageBlob.size / (1024 * 1024)).toFixed(2) + "MB");
// Create FormData
const formData = new FormData();
formData.append("model", "gpt-image-1");
formData.append("prompt", prompt);
formData.append("size", size);
formData.append("response_format", "b64_json");
formData.append("n", "1");
formData.append("image", imageBlob, "image.png");
// Send to OpenAI
const response = await fetch("https://api.openai.com/v1/images/edit", {
method: "POST",
headers: {
"Authorization": `Bearer ${apiKey}`,
},
body: formData,
});
// This is where we get the 413 error
console.log("Response status:", response.status);
const text = await response.text();
console.log("Response text:", text);
// Process response...
}
// Image processing function
async function fetchImageAsBlob(imageUrl) {
// Remove query params and transform image
const baseUrl = imageUrl.split("?")[0];
// Use smaller size for large images
let finalSize = 768; // Reduced from 1024
// Transform URL with quality reduction
const transformedUrl = `${baseUrl}?transform=resize&width=${finalSize}&height=${finalSize}&resize=cover&format=png&quality=85`;
// Fetch and return blob
const resp = await fetch(transformedUrl);
const blob = await resp.blob();
return blob;
}