Skip to content

fix: cap vision image pixel dimensions at 8000px to prevent Anthropic 400 errors - #26001

Closed
zccyman wants to merge 1 commit into
NousResearch:mainfrom
atyou2happy:fix/25837-vision-pixel-cap
Closed

fix: cap vision image pixel dimensions at 8000px to prevent Anthropic 400 errors#26001
zccyman wants to merge 1 commit into
NousResearch:mainfrom
atyou2happy:fix/25837-vision-pixel-cap

Conversation

@zccyman

@zccyman zccyman commented May 14, 2026

Copy link
Copy Markdown
Contributor

Problem

Anthropic's Messages API rejects any image larger than 8000 px on either axis with a non-retryable 400 error. Once such an image enters the message history, every subsequent request fails — the session is permanently bricked.

Fix

Add a pixel dimension check (_MAX_PIXEL_DIMENSION = 8000) in two places:

  1. _vision_analyze_native() — BEFORE base64 encoding, so oversized-but-small-byte-count images are caught early
  2. _resize_image_for_vision() — as an additional safeguard for existing callers that go through the resize path

Both checks:

  • Use Pillow (Image.LANCZOS) to resize while preserving aspect ratio
  • Gracefully degrade if Pillow is not installed (log + skip)

Testing

  • 6 unit tests + 1 skip (no Pillow): all pass
  • Tests cover: oversized width, oversized height, both axes, boundary (8000px exact), aspect ratio preservation, graceful Pillow absence

Closes #25837

… 400 errors

Anthropic rejects images >8000px on either axis with a non-retryable 400.
Once in history, every subsequent request fails — session is bricked.

Add pixel dimension check in two places:
1. _vision_analyze_native() — BEFORE base64 encoding
2. _resize_image_for_vision() — safety net in resize path

Pillow remains a soft dependency; check is skipped if unavailable.

Closes NousResearch#25837
@alt-glitch alt-glitch added type/bug Something isn't working tool/vision Vision analysis and image generation P2 Medium — degraded but workaround exists labels May 15, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #25838 — both cap vision image pixel dimensions to prevent Anthropic 400 errors on oversized images. Both fix #25837.

@zccyman

zccyman commented May 15, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @alt-glitch for the catch. Duplicate of #25838 — both cap vision image pixel dimensions at 8000px. Closing in favor of #25838.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Medium — degraded but workaround exists tool/vision Vision analysis and image generation type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: vision_analyze / browser_vision can brick session by inlining oversized image

2 participants