Skip to content

Fix image edits generating at on-page size and OpenRouter 400s - #1358

Merged
KeithCu merged 2 commits into
masterfrom
fix/image-edit-openrouter-rejections-11606523006561966997
Oct 6, 2026
Merged

KeithCu merged 2 commits into
masterfrom
fix/image-edit-openrouter-rejections-11606523006561966997

Conversation

@KeithCu

@KeithCu KeithCu commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Fixes an issue where image generation via /api/v1/images on OpenRouter was failing because edits were sized using on-page scaled dimensions instead of native pixel sizes, triggering 400 Bad Request responses (e.g., from Gemini models that enforce strict resolution tiers like "1K").

The solution introduces a native pixel size getter for selected images in image_tools.py and uses it as the source dimensions while preserving the document's scaled size during replacement. It also adds a retry handler in llm_client.py backed by adjust_image_body_for_rejection in base_provider_shim.py that catches OpenRouter "not supported" responses, safely falls back to common accepted parameter values (such as resolution or aspect ratio hints), and retries the request exactly once. All unit tests covering image_completion retries and sizing logic are included.


PR created automatically by Jules for task 11606523006561966997 started by @KeithCu

Images were generating at their scaled on-page dimension rather than their native pixel size, which failed standard provider resolution constraints (e.g. Gemini Flash Lite requiring 1K).
- Added `get_selected_image_pixel_size` to read native image dimensions.
- Updated `ImageGenerate` to generate using the native dimensions but preserve document layout footprint on replace.
- Handled OpenRouter parameter rejection errors by parsing accepted values and retrying exactly once with adjusted parameters.
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Images were generating at their scaled on-page dimension rather than their native pixel size, which failed standard provider resolution constraints (e.g. Gemini Flash Lite requiring 1K).
- Added `get_selected_image_pixel_size` to read native image dimensions.
- Updated `ImageGenerate` to generate using the native dimensions but preserve document layout footprint on replace.
- Handled OpenRouter parameter rejection errors by parsing accepted values and retrying exactly once with adjusted parameters.
@KeithCu
KeithCu merged commit 9101c87 into master Oct 6, 2026
1 check passed
@KeithCu
KeithCu deleted the fix/image-edit-openrouter-rejections-11606523006561966997 branch October 6, 2026 18:13
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.

1 participant