Skip to content

fix(azure): strip model from request body for deployment-based endpoints#2910

Open
giulio-leone wants to merge 3 commits intoopenai:mainfrom
giulio-leone:fix/azure-strip-model-from-deployment-body
Open

fix(azure): strip model from request body for deployment-based endpoints#2910
giulio-leone wants to merge 3 commits intoopenai:mainfrom
giulio-leone:fix/azure-strip-model-from-deployment-body

Conversation

@giulio-leone
Copy link

Summary

When using implicit deployments (model name as deployment), the Azure client correctly rewrites the URL to include /deployments/{model}/, but leaves the model parameter in the request body. Some Azure configurations reject requests where the body model doesn't match the actual model name behind the deployment.

Changes

  • In _build_request, after extracting model from json_data for URL routing, create a new dict without model instead of leaving it in the body
  • Uses dict comprehension rather than pop() to avoid mutating the shared json_data reference (model_copy is shallow), which preserves correct retry behavior

Test

Added test_implicit_deployment_strips_model_from_body with two parametrized cases:

  • /chat/completions (deployment endpoint)
  • /images/generations (deployment endpoint)

Both verify the URL contains /deployments/{model}/ and the request body does NOT contain model.

All 53 existing Azure tests pass.

Fixes #2892

When using implicit deployments (model name as deployment), the Azure
client correctly rewrites the URL to include /deployments/{model}/,
but leaves the model parameter in the request body. Some Azure
configurations reject requests where the body model doesn't match
the actual model name behind the deployment.

Create a new dict without model instead of using pop() to avoid
mutating the shared json_data reference (model_copy is shallow),
which would break request retries.

Fixes openai#2892

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 1, 2026 04:35
@giulio-leone giulio-leone requested a review from a team as a code owner March 1, 2026 04:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes Azure deployment-routing requests by removing the model field from the JSON body after it’s used to rewrite the URL to /deployments/{model}/..., preventing Azure configurations from rejecting requests due to body/URL model mismatches.

Changes:

  • Update Azure client _build_request to rewrite the URL using model and then rebuild json_data without model.
  • Add a regression test asserting the rewritten deployment URL and that model is not present in the request body.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/openai/lib/azure.py Strips model from JSON body when implicitly rewriting deployment-based endpoint URLs.
tests/lib/test_azure.py Adds a regression test ensuring model is removed from the request body for an implicit deployment endpoint.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…, parametrized test

- Replace type: ignore[union-attr] with proper cast() type narrowing
- Assert full URL instead of substring match in deployment test
- Add parametrized test for /chat/completions endpoint
- Move import json to module scope for consistency

Refs: openai#2910
@giulio-leone giulio-leone force-pushed the fix/azure-strip-model-from-deployment-body branch from f6d0357 to 8622ec9 Compare March 1, 2026 23:12
…ints

Replace two separate single-endpoint tests with one parametrized test
covering all 8 deployment endpoints.  json import was already at module
scope and type: ignore was already removed.

Refs: openai#2910
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.

Azure OpenAI - model parameter in request body causes failures when deployment name differs from model name

2 participants