fix(azure): promote x-ms-served-model header into Response.model for Responses API#3293
Open
xodn348 wants to merge 1 commit into
Open
fix(azure): promote x-ms-served-model header into Response.model for Responses API#3293xodn348 wants to merge 1 commit into
xodn348 wants to merge 1 commit into
Conversation
…Responses API Closes openai#3271
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_process_responseoverrides to bothAzureOpenAIandAsyncAzureOpenAIthat promote thex-ms-served-modelresponse header intoResponse.modelfor Responses API calls.modelfrom the header) so callers can see the actually-deployed model name rather than the logical alias./responsespaths and on responses that lack the header.Issue
Fixes #3271 — when using
AzureOpenAI.responses.create(...)the returnedResponse.modelreflects the requested model alias (e.g."gpt-4o") rather than the precise deployment actually served (e.g."gpt-4o-2024-11-20"). Azure surfaces the real model name in thex-ms-served-modelHTTP response header; this PR reads that header and writes it back intoResponse.model.Changes
src/openai/lib/azure.pyTypeto thetypingimports.ResponseTfrom.._types.AzureOpenAI._process_response(sync): callssuper(), then if the URL starts with/responsesandx-ms-served-modelis non-empty, patchesresult.model(non-streaming) or wrapsstream._iteratorto patchevent.response.modelfor every event that carries aresponse: Responsefield (streaming).AsyncAzureOpenAI._process_response(async): identical logic usingawait super()and an async generator.tests/lib/test_azure.pyopenai.types.responses.response.Response./responsesendpoint not affected, header promoted (async), header absent (async).Local verification
Risk
Low. The override only activates when:
/responses(exact SDK-generated path for the Responses resource), ANDx-ms-served-modelheader is present and non-empty.All other paths and clients are untouched.
Responseuses a mutable PydanticBaseModel(extra="allow"), so field assignment is safe. The streaming wrapper is a thin generator replacement on_iterator; it does not touch transport or parsing.