[java][python][Azure OpenAI] Align token limit handling with max_completion_tokens

Aperta
#1,478 2 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@samarthputhraya ci sta già lavorando.

Dal 29/11/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

affectVersion/0.4.0 bug priority/major
Search before asking
  • 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, reasoning guide. However, the Azure FAQ 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, Python setup and connection.

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 generate both token-limit fields. Keep additional_kwargs as passthrough; no extra validation is required to reject a configuration that explicitly supplies both token-limit names.
  • Update documentation and examples to distinguish the modern typed setting from the explicit older-deployment option. Explain that users should leave max_completion_tokens unset when supplying max_tokens through additional_kwargs. 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, including that the old-field-only case does not also generate max_completion_tokens. For Java, inspect the serialized HTTP body to catch duplicate fields. No special rejection test for explicitly supplying both token-limit names is required.

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!
Lingua principale
Java
Stelle
497
Fork
193
Merge medio
2g 21h
PR unite (30g)
68

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/flink-agents

Tutte le issue di apache/flink-agents

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.