fix(image_edit): forward litellm_params to validate_environment for Vertex AI credentials#26160
Conversation
…ertex AI credentials When aimage_edit or image_edit was called with Vertex AI Gemini/Imagen models via YAML-style config (vertex_project / vertex_credentials in proxy YAML), the credentials were dropped during handler-to-config plumbing, causing fallback to Application Default Credentials and DefaultCredentialsError. Root cause: image_edit_handler and async_image_edit_handler did not pass litellm_params to validate_environment, unlike image_generation_handler. Fixes: 1. Widen BaseImageEditConfig.validate_environment signature to accept litellm_params and api_base (optional kwargs). 2. Forward dict(litellm_params) and litellm_params.api_base from both sync and async image_edit handlers to validate_environment. 3. Update VertexAIImagenImageEditConfig.validate_environment to read vertex_ai_project/vertex_ai_credentials from litellm_params first, matching Gemini config pattern (secondary latent bug fix). 4. Widen all image-edit config override signatures to match base. Made-with: Cursor
Greptile SummaryThis PR fixes All 14 provider-specific overrides receive the new optional parameters (fully backwards-compatible), and focused mock-only regression tests are added for the Vertex Imagen and Gemini configs. Confidence Score: 5/5Safe to merge — the fix is minimal and targeted, all new parameters are optional, and the previously flagged P1 issues are fully resolved. Both root causes (handler not forwarding litellm_params, and validate_environment/get_complete_url ignoring it) are correctly fixed and mirror the existing image_generation pattern. No breaking changes. Mock-only regression tests are added. No remaining P1 issues. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/llms/custom_httpx/llm_http_handler.py | Forwards litellm_params and api_base to validate_environment in both sync and async image_edit handlers — the primary fix for this PR. |
| litellm/llms/vertex_ai/image_edit/vertex_imagen_transformation.py | validate_environment now reads credentials from litellm_params first; get_complete_url now reads project/location from litellm_params — both of the previously flagged P1 issues are resolved. |
| litellm/llms/base_llm/image_edit/transformation.py | Base class signature widened with optional litellm_params and api_base; all 14 concrete subclasses updated to match — no breaking changes. |
| tests/test_litellm/images/test_image_edit_utils.py | Adds regression tests for credential forwarding; all tests use mocks (no real network calls), consistent with the repo's test-folder policy. |
Sequence Diagram
sequenceDiagram
participant C as Caller
participant H as image_edit_handler (sync/async)
participant VE as validate_environment
participant GU as get_complete_url
participant VA as Vertex AI API
C->>H: image_edit(model, image, prompt, litellm_params)
Note over H: BEFORE: litellm_params NOT forwarded
Note over H: AFTER: litellm_params forwarded ✓
H->>VE: validate_environment(..., litellm_params, api_base)
VE->>VE: safe_get_vertex_ai_credentials(litellm_params)
VE->>VE: safe_get_vertex_ai_project(litellm_params)
VE-->>H: headers with Bearer token
H->>GU: get_complete_url(model, api_base, litellm_params)
GU->>GU: safe_get_vertex_ai_project(litellm_params)
GU->>GU: safe_get_vertex_ai_location(litellm_params)
GU-->>H: https://.../{project}/{location}/...
H->>VA: POST with auth headers
VA-->>H: ImageResponse
H-->>C: ImageResponse
Reviews (4): Last reviewed commit: "Merge pull request #26258 from BerriAI/l..." | Re-trigger Greptile
Adds three test cases to prevent regression of the Vertex AI image_edit credentials bug: 1. test_validate_environment_signature_includes_litellm_params: ensures all image-edit configs accept litellm_params (contract for the handler) 2. test_vertex_gemini_image_edit_reads_credentials_from_litellm_params: verifies Gemini config reads from litellm_params first 3. test_vertex_imagen_image_edit_reads_credentials_from_litellm_params: verifies Imagen config reads from litellm_params first These tests catch if the fix is accidentally reverted or if new image-edit configs are added without the litellm_params parameter. Made-with: Cursor
…Imagen get_complete_url VertexAIImagenImageEditConfig.get_complete_url was resolving vertex_project and vertex_location only from env vars and global settings, ignoring litellm_params. Users supplying project/location exclusively via YAML config would get a ValueError or wrong URL even after auth headers were fixed. Mirrors the pattern already used by VertexAIGeminiImageEditConfig and image_generation counterpart (safe_get_vertex_ai_project/location). Also fixes api_key type hint in MockImageEditConfig (str -> Optional[str]) and adds a test covering get_complete_url credential resolution. Made-with: Cursor
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| 29203053 | Triggered | Generic Password | 221dc2f | .circleci/config.yml | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secret safely. Learn here the best practices.
- Revoke and rotate this secret.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
63ba912
into
litellm_internal_staging
Summary
Fixes Vertex AI image-edit failing with
DefaultCredentialsErrorwhen credentials are passed via YAML config (e.g., Open WebUI)./images/generationswith identical config works fine/images/editsignoresvertex_credentials/vertex_projectkwargslitellm_paramstovalidate_environmentfixes [Bug]: Can't authenticate to vertex ai image generation models through v1/images/edits #21691
Changes
BaseImageEditConfig.validate_environmentsignature to accept optionallitellm_paramsandapi_baseimage_edit_handler(matchingimage_generation_handler)VertexAIImagenImageEditConfigto read creds fromlitellm_paramsfirst (secondary bug)Validation
Before

After
