Skip to content

Fix: base_model name for body and deplyment name in URL - #20747

Merged
Sameerlite merged 2 commits into
mainfrom
litellm_image_gen_bas_model_fix
Feb 9, 2026
Merged

Fix: base_model name for body and deplyment name in URL#20747
Sameerlite merged 2 commits into
mainfrom
litellm_image_gen_bas_model_fix

Conversation

@Sameerlite

Copy link
Copy Markdown
Contributor

Relevant issues

Fixes #20741

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
  • 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

CI (LiteLLM team)

CI status guideline:

  • 50-55 passing tests: main is stable with minor issues.
  • 45-49 passing tests: acceptable but needs attention
  • <= 40 passing tests: unstable; be careful with your merges and assess the risk.
  • Branch creation CI run
    Link:

  • CI run for the last commit
    Link:

  • Merge / cherry-pick CI run
    Links:

Type

🆕 New Feature
🐛 Bug Fix
🧹 Refactoring
📖 Documentation
🚄 Infrastructure
✅ Test

Changes

model_list:
  - model_name: gpt-image-1.5 
    litellm_params:
      base_model: gpt-image-1.5 
      model: azure/gpt-image-15 # deployment name is different 
      api_base: https://openai-gpt-image-1-5-test-v-1.openai.azure.com/
image

@vercel

vercel Bot commented Feb 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Feb 9, 2026 11:45am

Request Review

@greptile-apps

greptile-apps Bot commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

This PR updates Azure image generation so the request body can use litellm_params.base_model while the request URL is constructed with the Azure deployment name (model). It also adds unit tests intended to verify that split.

The changes fit into the existing Azure image generation flow in AzureChatCompletion by (1) overriding the JSON body’s model field when base_model is configured and (2) threading the deployment name into create_azure_base_url() for both sync and async paths.

Confidence Score: 2/5

  • This PR should not be merged until the new null-deref in Azure image generation and the ineffective tests are fixed.
  • The core behavior change is reasonable, but image_generation() can now crash when litellm_params is None, and the added tests include a non-async async-marked test plus exception swallowing that can let regressions slip through.
  • litellm/llms/azure/azure.py; tests/test_litellm/llms/azure/image_generation/test_azure_image_generation_init.py

Important Files Changed

Filename Overview
litellm/llms/azure/azure.py Adjusts Azure image generation to use deployment name for URL and base_model for request body, but introduces a null-deref crash when litellm_params is None (litellm_params.get(...) in image_generation).
tests/test_litellm/llms/azure/image_generation/test_azure_image_generation_init.py Adds sync/async tests for base_model vs deployment URL behavior, but one async test is defined as non-async and both tests swallow exceptions, risking false positives.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant AzureChatCompletion as AzureChatCompletion
    participant AzureBaseURL as create_azure_base_url
    participant SyncReq as make_sync_azure_httpx_request
    participant AsyncReq as make_async_azure_httpx_request

    alt Sync image_generation()
        Caller->>AzureChatCompletion: image_generation(prompt, model=deployment, litellm_params.base_model)
        AzureChatCompletion->>AzureChatCompletion: extra_body flatten + data.model = base_model || deployment
        AzureChatCompletion->>AzureBaseURL: create_azure_base_url(model=deployment)
        AzureBaseURL-->>AzureChatCompletion: img_gen_api_base (/openai/deployments/{deployment}/images/generations)
        AzureChatCompletion->>SyncReq: POST(api_base=img_gen_api_base, json=data)
        SyncReq-->>AzureChatCompletion: httpx.Response
        AzureChatCompletion-->>Caller: ImageResponse
    end

    alt Async aimage_generation()
        Caller->>AzureChatCompletion: aimage_generation(data.model=base_model, model=deployment)
        AzureChatCompletion->>AzureBaseURL: create_azure_base_url(model=deployment)
        AzureBaseURL-->>AzureChatCompletion: img_gen_api_base
        AzureChatCompletion->>AsyncReq: POST(api_base=img_gen_api_base, json=data)
        AsyncReq-->>AzureChatCompletion: httpx.Response
        AzureChatCompletion-->>Caller: ImageResponse
    end
Loading

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +365 to +368
@pytest.mark.asyncio
async def test_azure_aimage_generation_base_model_vs_deployment_name():
"""
Test that Azure async image generation correctly uses base_model in request body

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Async test never runs

The async test is marked with @pytest.mark.asyncio but the function is defined with def (not async def). Pytest will treat it as a normal test and won’t await anything, so this doesn’t actually validate the async path.

This should be async def test_azure_aimage_generation_base_model_vs_deployment_name():.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is async def test_azure_aimage_generation_base_model_vs_deployment_name

Comment on lines +319 to +333
response = azure_chat_completion.image_generation(
prompt=prompt,
timeout=60.0,
optional_params=optional_params,
logging_obj=logging_obj,
headers={},
model=model,
api_key=api_key,
api_base=api_base,
api_version=api_version,
litellm_params=litellm_params,
)
except Exception as e:
# If there's an error, we still want to check the mock calls
pass

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Test can falsely pass

Both new tests wrap the call in try/except Exception: pass and then only assert mock_request.called. This can still pass even if image_generation() fails before constructing the URL/body you want to verify (e.g., raises due to unrelated bug), and can hide regressions.

Remove the blanket exception handler (or assert on the specific expected exception) so the test actually fails when the call path breaks.

@greptile-apps

greptile-apps Bot commented Feb 9, 2026

Copy link
Copy Markdown
Contributor
Additional Comments (1)

litellm/llms/azure/azure.py
Crash when litellm_params None

image_generation() now calls litellm_params.get(...) unconditionally. Since litellm_params is typed/used as optional and can be None at runtime, this will raise AttributeError: 'NoneType' object has no attribute 'get' on image generation calls that don’t pass litellm_params.

This needs a litellm_params = litellm_params or {} (or equivalent guard) before accessing .get().

@ceng-p ceng-p left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks like a decent work around, thanks

@ghost ghost mentioned this pull request Feb 9, 2026
1 task
@Sameerlite
Sameerlite merged commit 6158e46 into main Feb 9, 2026
62 of 67 checks passed
@ishaan-berri
ishaan-berri deleted the litellm_image_gen_bas_model_fix branch March 26, 2026 22:29
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…odel_fix

Fix: base_model name for body and deplyment name in URL
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]: Azure OpenAI gpt-image models bug

2 participants