Repository navigation
Conversation
OpenRouter supports image editing through its chat completions endpoint
for models like google/gemini-2.5-flash-image, but LiteLLM raised
ValueError("image edit is not supported for openrouter") because
OpenRouter was not registered as an image edit provider.
Add OpenRouterImageEditConfig that routes image edit requests through
the chat completions endpoint with the source image as a base64 data
URL in the message content array.
Fixes BerriAI#22305
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Greptile SummaryAdds image edit support for OpenRouter by implementing
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| litellm/llms/openrouter/image_edit/transformation.py | New OpenRouterImageEditConfig implementing BaseImageEditConfig. Well-structured with request/response transformation, parameter mapping, usage/cost extraction. Follows existing image generation config patterns closely. |
| litellm/utils.py | Adds OpenRouter case to get_provider_image_edit_config factory method. Follows the exact same lazy-import pattern as all other providers. |
| tests/test_litellm/llms/openrouter/image_edit/test_openrouter_image_edit_transformation.py | 33 comprehensive unit tests covering all methods. Mock-only (no network calls), testing parameter mapping, request/response transformation, edge cases, and error handling. |
| docs/my-website/docs/image_edits.md | Documentation updates adding OpenRouter to the supported providers table and SDK/proxy usage examples. |
| docs/my-website/docs/providers/openrouter.md | Provider-specific documentation for OpenRouter image edit including supported models, parameter mapping table, and usage examples. |
Sequence Diagram
sequenceDiagram
participant Client
participant LiteLLM as litellm.image_edit()
participant PCM as ProviderConfigManager
participant Config as OpenRouterImageEditConfig
participant OR as OpenRouter API
Client->>LiteLLM: image_edit(model, image, prompt)
LiteLLM->>PCM: get_provider_image_edit_config("openrouter")
PCM-->>LiteLLM: OpenRouterImageEditConfig
LiteLLM->>Config: validate_environment(headers, api_key)
Config-->>LiteLLM: headers with Bearer token
LiteLLM->>Config: map_openai_params(size, quality, n)
Config-->>LiteLLM: image_config.aspect_ratio, image_config.image_size
LiteLLM->>Config: transform_image_edit_request(model, prompt, image)
Note over Config: Base64-encode image into<br/>chat completion message content
Config-->>LiteLLM: {model, messages, modalities: ["image","text"]}
LiteLLM->>OR: POST /api/v1/chat/completions
OR-->>LiteLLM: {choices, usage, cost}
LiteLLM->>Config: transform_image_edit_response(raw_response)
Note over Config: Extract images from<br/>choices[].message.images[]<br/>Set usage and cost
Config-->>LiteLLM: ImageResponse(data, usage)
LiteLLM-->>Client: ImageResponse
Last reviewed commit: fecb301
Raise ValueError when OPENROUTER_API_KEY is not set instead of sending "Bearer None" and getting a confusing 401 from the API.
|
Shivaang seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Add OpenRouter image edit docs to both the provider page and the main image_edits reference page, including supported models, parameter mappings (size→aspect_ratio, quality→image_size), usage examples, proxy configuration, and a note about 4K quality model support.
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Chesars
merged commit Mar 3, 2026
8a1e915
into
BerriAI:litellm_oss_staging_03_03_2026
3 of 36 checks passed
1 task done
8 of 13 tasks
fzowl
pushed a commit
to fzowl/litellm
that referenced
this pull request
Jun 24, 2026
…edit feat(openrouter): add image edit support for OpenRouter models
This branch was successfully deployed
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.
Relevant issues
Fixes #22305
Pre-Submission checklist
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewType
New Feature
Changes
Problem
OpenRouter models (e.g.,
google/gemini-2.5-flash-image) support image editing through their chat completions endpoint, but LiteLLM has no image edit configuration for the OpenRouter provider. Callinglitellm.image_edit()with an OpenRouter model raisesValueError("image edit is not supported for openrouter")becauseProviderConfigManager.get_provider_image_edit_config()returnsNonefor OpenRouter.Solution
Added
OpenRouterImageEditConfigthat implementsBaseImageEditConfigto route image edit requests through OpenRouter's chat completions endpoint. Unlike providers with dedicated/images/editsendpoints, OpenRouter handles image editing via/api/v1/chat/completionswith the source image sent as a base64 data URL in the message content andmodalities: ["image", "text"]to signal image output.sizetoimage_config.aspect_ratio,qualitytoimage_config.image_sizechoices[].message.images[]in the responseprompt_tokens_detailsuse_multipart_form_data() = False), matching the Gemini image edit patternProviderConfigManager.get_provider_image_edit_config()following the existing factory patternFiles changed
litellm/llms/openrouter/image_edit/__init__.py- New module with factory functionget_openrouter_image_edit_config()litellm/llms/openrouter/image_edit/transformation.py-OpenRouterImageEditConfigclass with request/response transformation, parameter mapping, usage/cost extractionlitellm/utils.py- Added OpenRouter case toProviderConfigManager.get_provider_image_edit_config()tests/test_litellm/llms/openrouter/image_edit/__init__.py- Test module inittests/test_litellm/llms/openrouter/image_edit/test_openrouter_image_edit_transformation.py- 33 unit testsTesting
_read_image_bytesedge casesgoogle/gemini-2.5-flash-image, successfully editing an image and receiving a valid response with correct usage tracking@greptileai @shin-bot-litellm