wenjin272 opened a new issue, #1478: URL: https://github.com/apache/flink-agents/issues/1478
### Search before asking - [x] I searched the existing issues and did not find a duplicate. ### Description Follow-up to #1470: make Azure OpenAI Chat Completions token-limit handling consistent across Java, Python, and YAML, using `max_completion_tokens` as the typed setting. Both setups currently expose `max_tokens`, but the requests differ: - Java translates it to the SDK's `maxCompletionTokens`, sending `max_completion_tokens`. - Python forwards it as `max_tokens`. Consequently, the Python path cannot use this setting with deployments whose models require `max_completion_tokens`. This is a request-field compatibility issue as well as a Java/Python mismatch. Microsoft documents `max_tokens` as deprecated and requires `max_completion_tokens` for reasoning models: [API reference](https://learn.microsoft.com/en-us/rest/api/microsoft-foundry/azureopenai/chat), [reasoning guide](https://learn.microsoft.com/en-us/azure/foundry/openai/how-to/reasoning). However, [the Azure FAQ](https://learn.microsoft.com/en-us/azure/foundry-classic/openai/faq#do-all-azure-openai-models-support-max_completion_tokens-with-the-chat-completions-api) explicitly notes that some older models, such as GPT-4 `turbo-2024-04-09`, do not support the new field. Preserve an explicit way to send the old field for deployments that need it. Source: [Java connection](https://github.com/apache/flink-agents/blob/c5976c41a286135b96232e024777142009e28c18/integrations/chat-models/openai/src/main/java/org/apache/flink/agents/integrations/chatmodels/openai/AzureOpenAIChatModelConnection.java), [Python setup and connection](https://github.com/apache/flink-agents/blob/c5976c41a286135b96232e024777142009e28c18/python/flink_agents/integrations/chat_models/azure/azure_openai_chat_model.py). #### Expected changes - Rename the typed setting to `max_completion_tokens` consistently in Java, Python, and YAML, without an old top-level compatibility alias. Send the new field under the same name in both languages. - Omit the token-limit field when it is unset and retain positive-value validation. - For older deployments, allow users to leave the typed setting unset and explicitly send `additional_kwargs={"max_tokens": ...}`. Do not translate that explicit old field to the new name. - Update the reserved-key validation in both Azure implementations: it currently reserves `max_tokens`, so renaming only the setup field would leave this older-model path blocked. Preserve the existing collision policy for the new typed field. - Do not automatically send both token-limit fields. Define consistent validation for configurations that supply both names so conflicting limits cannot silently reach the API. - Update documentation and examples to distinguish the modern typed setting from the explicit older-deployment option. Check the supported Azure API versions; do not assume every OpenAI-compatible endpoint supports the same fields. #### Verification Cover Java and Python setup-to-request behavior, including YAML/descriptor configuration: omitted limit, explicit new limit, invalid values, and old-field-only passthrough through `additional_kwargs`. Assert the exact outgoing field names and values, and cover the conflicting two-field configuration. For Java, inspect the serialized HTTP body to catch duplicate fields. ### How to reproduce Construct an Azure setup with `max_tokens=256` (or the equivalent Java descriptor argument) and capture a chat request through its connection. Python sends `max_tokens`, while Java sends `max_completion_tokens`. For a reasoning deployment that rejects the old field, the Python request is incompatible with the documented API contract. The current reserved-key validation also rejects `additional_kwargs={"max_tokens": 256}`, preventing it from serving as an explicit older-model option without a corresponding code change. ### Version and environment Identified during the review of #1470, from the source at `c5976c41a286135b96232e024777142009e28c18`. The current main-branch Python Azure file was also checked and is unchanged. This report is based on source inspection and Microsoft's API documentation; no live Azure deployment was tested. This can be implemented separately and does not need to block #1470. Responses token-limit naming is tracked separately in #1477; its API field is `max_output_tokens`. ### Are you willing to submit a PR? - [ ] I'm willing to submit a PR! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
