Bug
PNG images sent via Discord are rejected by Anthropic with:
messages.N.content.N.image.source.base64: The image was sp...
JPEG images sent to the same conversation, same agent, same model work fine.
Reproduction
- Send a PNG screenshot via Discord desktop → Anthropic 400 error
- Send the same image saved as JPEG → works
- Send from Discord mobile (which auto-compresses to JPEG) → works
- Send via Telegram (which always serves as JPEG) → works
Root cause
prepareImage() in src/core/bot.ts processes images through sharp for resizing but preserves the input format. PNGs pass through as PNGs. Anthropic appears to reject certain PNG encodings or large PNG base64 payloads.
The Telegram adapter sidesteps this because Telegram always serves photos as JPEG (mimeType: 'image/jpeg'). Discord preserves the original upload format.
Suggested fix
Add a format normalization step in prepareImage() -- convert to JPEG (or WebP) via sharp before base64 encoding, regardless of input format:
buffer = await sharp(buffer)
.resize({ width: MAX_IMAGE_DIMENSION, height: MAX_IMAGE_DIMENSION, fit: 'inside', withoutEnlargement: true })
.jpeg({ quality: 90 })
.toBuffer();
mediaType = 'image/jpeg';
This would make the Discord path behave like the Telegram path and prevent format-dependent failures.
Environment
- LettaBot 0.2.0 (built from main)
- Letta Cloud
- Anthropic (Claude Sonnet)
- Discord channel with
attachmentsDir configured
- Raspberry Pi 5 host
Workaround
Users can save images as JPEG before sending, or send from Discord mobile (auto-compresses to JPEG).
Bug
PNG images sent via Discord are rejected by Anthropic with:
JPEG images sent to the same conversation, same agent, same model work fine.
Reproduction
Root cause
prepareImage()insrc/core/bot.tsprocesses images throughsharpfor resizing but preserves the input format. PNGs pass through as PNGs. Anthropic appears to reject certain PNG encodings or large PNG base64 payloads.The Telegram adapter sidesteps this because Telegram always serves photos as JPEG (
mimeType: 'image/jpeg'). Discord preserves the original upload format.Suggested fix
Add a format normalization step in
prepareImage()-- convert to JPEG (or WebP) via sharp before base64 encoding, regardless of input format:This would make the Discord path behave like the Telegram path and prevent format-dependent failures.
Environment
attachmentsDirconfiguredWorkaround
Users can save images as JPEG before sending, or send from Discord mobile (auto-compresses to JPEG).