Image media type detected from file extension instead of actual content, causing API 400 errors
Resolved 💬 2 comments Opened Mar 2, 2026 by seidnerj Closed Mar 2, 2026
Bug Description
When attaching an image via copy/paste that has a mismatched file extension vs actual format (e.g., a file named .jpg that is actually a PNG), the wrong media type is sent to the API, resulting in a 400 error.
Error Message
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.146.content.3.image.source.base64: The image was specified using the image/jpeg media type, but the image appears to be a image/png image"},"request_id":"req_xxxxxxxxxx"}
Steps to Reproduce
- Have an image file that has a wrong extension (e.g., a PNG image saved/named as
.jpg) - Copy/paste (attach) the image into a conversation
- The API returns a 400 error because the declared media type doesn't match the actual image content
Expected Behavior
The actual image format should be detected by inspecting the file content (magic bytes/file signature) rather than relying solely on the file extension. This is a common scenario since:
- Screenshots copied from various tools may have incorrect extensions
- Images downloaded from the web can have mismatched extensions
- Copy/paste operations may not preserve the correct extension
Suggested Fix
Use magic byte detection (e.g., checking the first few bytes of the file for PNG/JPEG/GIF/WebP signatures) to determine the actual media type before sending to the API. Most image formats have well-defined magic bytes:
- PNG:
89 50 4E 47 - JPEG:
FF D8 FF - GIF:
47 49 46 38 - WebP:
52 49 46 46 ... 57 45 42 50
This is a recurring issue that affects users regularly.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗