Skip to content

fix(image_edit): forward litellm_params to validate_environment for Vertex AI credentials#26160

Merged
Sameerlite merged 4 commits intolitellm_internal_stagingfrom
litellm_vertex_image_edit_credentials_fix
Apr 23, 2026
Merged

fix(image_edit): forward litellm_params to validate_environment for Vertex AI credentials#26160
Sameerlite merged 4 commits intolitellm_internal_stagingfrom
litellm_vertex_image_edit_credentials_fix

Conversation

@Sameerlite
Copy link
Copy Markdown
Collaborator

@Sameerlite Sameerlite commented Apr 21, 2026

Summary

Fixes Vertex AI image-edit failing with DefaultCredentialsError when credentials are passed via YAML config (e.g., Open WebUI).

Changes

  1. Widen BaseImageEditConfig.validate_environment signature to accept optional litellm_params and api_base
  2. Forward both in sync/async image_edit_handler (matching image_generation_handler)
  3. Fix VertexAIImagenImageEditConfig to read creds from litellm_params first (secondary bug)
  4. Update all 14 image-edit config overrides to match new base signature

Validation

  • Repro script confirms credentials now reach Vertex AI (429 rate-limit instead of DefaultCredentialsError)
  • Image-edit tests: 66 passed
  • No breaking changes (all new params are optional)

Before
image

After
image

…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-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 21, 2026

Greptile Summary

This PR fixes DefaultCredentialsError for Vertex AI image-edit by forwarding litellm_params (and api_base) to validate_environment in both the sync and async image_edit_handler, matching the existing pattern in image_generation_handler. It also updates VertexAIImagenImageEditConfig.validate_environment to read credentials from litellm_params first, and fixes get_complete_url to do the same for project/location — addressing the two root causes that kept credentials from reaching the Vertex AI auth layer.

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/5

Safe 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.

Important Files Changed

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
Loading

Reviews (4): Last reviewed commit: "Merge pull request #26258 from BerriAI/l..." | Re-trigger Greptile

Comment thread tests/test_litellm/images/test_image_edit_utils.py Outdated
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
@Sameerlite Sameerlite temporarily deployed to integration-postgres April 21, 2026 09:28 — with GitHub Actions Inactive
@Sameerlite Sameerlite temporarily deployed to integration-postgres April 21, 2026 09:29 — with GitHub Actions Inactive
…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
@Sameerlite Sameerlite temporarily deployed to integration-postgres April 21, 2026 09:34 — with GitHub Actions Inactive
@Sameerlite Sameerlite temporarily deployed to integration-postgres April 21, 2026 09:34 — with GitHub Actions Inactive
@Sameerlite Sameerlite temporarily deployed to integration-postgres April 21, 2026 09:34 — with GitHub Actions Inactive
@Sameerlite Sameerlite temporarily deployed to integration-postgres April 22, 2026 16:09 — with GitHub Actions Inactive
@Sameerlite Sameerlite temporarily deployed to integration-postgres April 22, 2026 16:09 — with GitHub Actions Inactive
@Sameerlite Sameerlite temporarily deployed to integration-postgres April 22, 2026 16:09 — with GitHub Actions Inactive
@Sameerlite Sameerlite temporarily deployed to integration-postgres April 22, 2026 16:09 — with GitHub Actions Inactive
@Sameerlite Sameerlite temporarily deployed to integration-postgres April 22, 2026 16:09 — with GitHub Actions Inactive
@gitguardian
Copy link
Copy Markdown

gitguardian Bot commented Apr 22, 2026

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
29203053 Triggered Generic Password 221dc2f .circleci/config.yml View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. 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


🦉 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
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...rtex_ai/image_edit/vertex_imagen_transformation.py 87.50% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Sameerlite Sameerlite merged commit 63ba912 into litellm_internal_staging Apr 23, 2026
101 of 102 checks passed
@Sameerlite Sameerlite deleted the litellm_vertex_image_edit_credentials_fix branch April 23, 2026 03:06
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]: Can't authenticate to vertex ai image generation models through v1/images/edits

2 participants