fix: cap vision image pixel dimensions at 8000px to prevent Anthropic 400 errors - #26001
Closed
zccyman wants to merge 1 commit into
Closed
fix: cap vision image pixel dimensions at 8000px to prevent Anthropic 400 errors#26001zccyman wants to merge 1 commit into
zccyman wants to merge 1 commit into
Conversation
… 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
Collaborator
Contributor
Author
|
Thanks @alt-glitch for the catch. Duplicate of #25838 — both cap vision image pixel dimensions at 8000px. Closing in favor of #25838. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:_vision_analyze_native()— BEFORE base64 encoding, so oversized-but-small-byte-count images are caught early_resize_image_for_vision()— as an additional safeguard for existing callers that go through the resize pathBoth checks:
Image.LANCZOS) to resize while preserving aspect ratioTesting
Closes #25837