Skip to content

fix(vision): reject oversized images before API call, handle file:// URIs, improve 400 errors#6964

Closed
Tranquil-Flow wants to merge 1 commit into
NousResearch:mainfrom
Tranquil-Flow:fix/vision-analyze-local-image-400
Closed

fix(vision): reject oversized images before API call, handle file:// URIs, improve 400 errors#6964
Tranquil-Flow wants to merge 1 commit into
NousResearch:mainfrom
Tranquil-Flow:fix/vision-analyze-local-image-400

Conversation

@Tranquil-Flow

Copy link
Copy Markdown
Contributor

Summary

Fixes three root causes behind vision_analyze returning 400 Invalid request data on valid local images:

  • Pre-flight base64 size check — base64 encoding inflates data ~33%, so a 3.8 MB file produces a ~5 MB payload that exceeds provider limits. The tool now rejects oversized images with a clear message before the API call, instead of letting the provider return a cryptic 400.
  • file:// URI supportfile:///path/to/image.png previously fell through to "invalid image source" because it matched neither Path.is_file() nor http(s). The scheme is now stripped and the path resolved as a local file.
  • Better error classification for 400sinvalid_request errors were lumped into "model does not support vision". They now get a separate, actionable message suggesting the user resize/compress the image.

Test plan

  • TestFileUriSupport::test_file_uri_resolved_as_local_path — file:// URI resolves and succeeds
  • TestFileUriSupport::test_file_uri_nonexistent_gives_error — missing file:// target fails gracefully
  • TestBase64SizeLimit::test_oversized_image_rejected_before_api_call — 4 MB PNG (>5 MB base64) rejected before LLM call
  • TestBase64SizeLimit::test_small_image_not_rejected — small image passes size check
  • TestErrorClassification::test_invalid_request_error_gives_image_guidance — 400 error produces resize guidance
  • All 54 vision tests pass

Closes #6677

…URIs, improve 400 errors

Three fixes for vision_analyze returning cryptic 400 "Invalid request data":

1. Pre-flight base64 size check — base64 inflates data ~33%, so a 3.8 MB
   file exceeds the 5 MB API limit. Reject early with a clear message
   instead of letting the provider return a generic 400.

2. Handle file:// URIs — strip the scheme and resolve as a local path.
   Previously file:///path/to/image.png fell through to the "invalid
   image source" error since it matched neither is_file() nor http(s).

3. Separate invalid_request errors from "does not support vision" errors
   so the user gets actionable guidance (resize/compress/retry) instead
   of a misleading "model does not support vision" message.

Closes NousResearch#6677
@teknium1

Copy link
Copy Markdown
Contributor

Merged via #7654 with authorship preserved. Thanks for the contribution!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: vision_analyze returns 400 'Invalid request data' on valid local image paths across Anthropic/OpenAI sessions

2 participants