feat(azure): Add stream_options to payload if api_version supports #15122
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.


Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.
Before submitting, make sure you've checked the following:
devbranch.Changelog Entry
Description
Although it's not documented in MS Azure doc, Azure OpenAI supports
stream_optionssince API version 2024-09-01-preview.This PR adds
stream_optionsto the payload if the API version supports it. To avoid break changes, it will check the API version before addingstream_optionsto payload.Added
Changed
get_azure_allowed_paramsfunction that adjusts based onapi_versionapi_versionparameter toconvert_to_azure_payloadfor dynamic parameter filteringapi_versionconsistently for better compatibilityBreaking Changes
I don't think it will introduce any break changes since it has already check the API version in the code. For the user who use old API version, it will change nothing.
Screenshots or Videos
After the change, Open WebUI will retrieve and display the token usage for ChageGPT models from Azure AI:

(For other models from Azure AI, like DeepSeek and Grok, it seems that they will response token usage even if we don't add
stream_optionsto request)Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.