Skip to content

fix: support aspect_ratio parameter for Vertex AI image generation #12728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

colesmcintosh
Copy link
Collaborator

@colesmcintosh colesmcintosh commented Jul 18, 2025

Title

Support aspect_ratio parameter for Vertex AI image generation

Relevant issues

Fixes #12690

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🐛 Bug Fix

Changes

Summary

Implementation Details

  1. Modified litellm/utils.py:

    • Added "aspect_ratio" to the list of supported parameters for Vertex AI (line 2551)
    • Added transformation logic to convert aspect_ratio to aspectRatio (lines 2575-2579)
    • Prevented duplicate parameter addition in the generic loop (lines 2583-2585)
  2. Updated litellm/types/llms/openai.py:

    • Added "aspect_ratio" to the OpenAIImageGenerationOptionalParams type definition (line 905)

Testing

  • Added unit tests in tests/test_litellm/test_utils.py to verify parameter transformation
  • Added integration tests in tests/image_gen_tests/test_image_generation.py with mocked API calls
  • All existing tests pass
  • Linting and type checking pass
Screenshot 2025-07-18 at 5 38 20 AM

Usage Example

# Direct aspect_ratio usage
response = litellm.image_generation(
    model="vertex_ai/imagegeneration",
    prompt="A beautiful sunset",
    aspect_ratio="16:9"
)

# Works with other parameters
response = litellm.image_generation(
    model="vertex_ai/imagegeneration", 
    prompt="A beautiful sunset",
    aspect_ratio="4:3",
    n=2
)

Supported aspect ratios: "1:1", "9:16", "16:9", "4:3", "3:4"

- Add aspect_ratio to supported Vertex AI parameters
- Transform snake_case aspect_ratio to camelCase aspectRatio as required by Vertex AI API
- Add aspect_ratio to OpenAIImageGenerationOptionalParams type definition
- Maintain backward compatibility with existing size parameter

Fixes BerriAI#12690
Copy link

vercel bot commented Jul 18, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 18, 2025 5:06pm

@colesmcintosh colesmcintosh marked this pull request as ready for review July 18, 2025 11:39
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs testing

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]: Vertex AI image generation ignores aspect_ratio parameter
2 participants