Skip to content

fix(proxy): use max_completion_tokens for gpt-chat-latest health - #30987

Open
AleksandrLiadov wants to merge 2 commits into
BerriAI:litellm_internal_stagingfrom
AleksandrLiadov:fix/azure-chat-latest-health-max-completion-tokens
Open

fix(proxy): use max_completion_tokens for gpt-chat-latest health#30987
AleksandrLiadov wants to merge 2 commits into
BerriAI:litellm_internal_stagingfrom
AleksandrLiadov:fix/azure-chat-latest-health-max-completion-tokens

Conversation

@AleksandrLiadov

Copy link
Copy Markdown
Contributor

What

Fix LiteLLM proxy health checks for Azure gpt-chat-latest deployments by sending max_completion_tokens instead of max_tokens.

Azure gpt-chat-latest rejects health probes containing max_tokens with:

Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.

Deployment names can include suffixes such as azure/gpt-chat-latest-gs, so the health check now detects gpt-chat-latest in either:

  • litellm_params.model
  • model_info.base_model

and sends the bounded health token value as max_completion_tokens for those probes.

Why

The model supports /chat/completions, but the health check currently marks it unhealthy because it uses the wrong token-limit parameter. This is similar to the existing Azure GPT-5/o-series max token handling issue, but gpt-chat-latest is an alias and does not necessarily trigger GPT-5-specific model-name routing.

Related context:

Tests

  • uv run pytest tests/test_litellm/proxy/test_health_check_max_tokens.py::test_azure_gpt_chat_latest_health_check_uses_max_completion_tokens -q
  • uv run pytest tests/test_litellm/proxy/test_health_check_max_tokens.py -q
  • uv run ruff check litellm/proxy/health_check.py tests/test_litellm/proxy/test_health_check_max_tokens.py

Note: local uv emitted a warning parsing exclude-newer = "3 days", but the tests/lint above passed.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codspeed-hq

codspeed-hq Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Congrats! CodSpeed is installed 🎉

🆕 16 new benchmarks were detected.

You will start to see performance impacts in the reports once the benchmarks are run from your default branch.

Detected benchmarks


Open in CodSpeed

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.47368% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/proxy/health_check.py 89.18% 4 Missing ⚠️
litellm/llms/azure/chat/gpt_transformation.py 90.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@greptile-apps

greptile-apps Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes Azure gpt-chat-latest health checks by adding the model to the cost map with a map_max_tokens_to_max_completion_tokens: true flag, then reading that flag generically in both the health-check path (via a new _resolve_health_check_model_info resolver that handles suffixed deployment names like azure/gpt-chat-latest-gs through base_model lookup) and the normal param-mapping path in AzureOpenAIConfig.map_openai_params.

  • Model cost map: azure/gpt-chat-latest added to both JSON files with the new map_max_tokens_to_max_completion_tokens: true field.
  • Health check path: _resolve_health_check_model_info merges cost-map metadata with deployment model_info for suffixed deployments; _update_litellm_params_for_health_check emits max_completion_tokens when the flag is set.
  • Regular call path: _should_map_max_tokens_to_max_completion_tokens translates max_tokens for the canonical azure/gpt-chat-latest name; suffixed deployment names are not covered here.

Confidence Score: 5/5

The change is narrowly scoped to health-check parameter selection and Azure param mapping; the model-map flag is opt-in and can be overridden at the deployment level.

The core fix is correct: health checks for both canonical and suffixed gpt-chat-latest deployments now emit max_completion_tokens, and regular calls for the canonical name benefit too. The reviewer-noted lint CI failure is worth resolving before merge, but the logic is sound and well-tested with mock-only unit tests.

The lint CI check is still failing per the reviewer — worth verifying the full pipeline, as black formatting and ruff on gpt_transformation.py were not included in the author's local checks.

Important Files Changed

Filename Overview
litellm/proxy/health_check.py Adds _resolve_health_check_model_info to merge model-cost metadata with deployment-level model_info; minor issue: GetModelCostMap.load_local_model_cost_map() called inside loop, reading disk once per missed candidate.
litellm/llms/azure/chat/gpt_transformation.py Adds _should_map_max_tokens_to_max_completion_tokens; works for canonical azure/gpt-chat-latest but suffixed deployment names are not resolved here.
model_prices_and_context_window.json Adds azure/gpt-chat-latest metadata with map_max_tokens_to_max_completion_tokens: true.
litellm/model_prices_and_context_window_backup.json Mirrors the azure/gpt-chat-latest entry in the in-package backup JSON.
tests/test_litellm/proxy/test_health_check_max_tokens.py Adds two mock-only tests covering the metadata path and deployment-level override.
tests/test_litellm/llms/azure/chat/test_azure_chat_gpt_transformation.py Adds two unit tests for map_openai_params translation for flagged and unflagged models.
tests/test_litellm/test_utils.py Adds map_max_tokens_to_max_completion_tokens to the model-price JSON schema validator.

Reviews (3): Last reviewed commit: "fix(azure): health check + chat use max_..." | Re-trigger Greptile

Comment thread litellm/proxy/health_check.py Outdated
@AleksandrLiadov
AleksandrLiadov force-pushed the fix/azure-chat-latest-health-max-completion-tokens branch 3 times, most recently from e31f702 to dfc42a9 Compare June 22, 2026 18:25
@AleksandrLiadov
AleksandrLiadov changed the base branch from main to litellm_oss_branch June 22, 2026 18:25
if candidate in local_model_cost:
metadata = local_model_cost[candidate]
break
except Exception:
@AleksandrLiadov
AleksandrLiadov force-pushed the fix/azure-chat-latest-health-max-completion-tokens branch 2 times, most recently from c60a9e7 to 3bd5de9 Compare June 22, 2026 18:53
@Sameerlite

Copy link
Copy Markdown
Contributor

Thanks for the contribution! Kicking off a Greptile code review on this one.

@greptileai

@Sameerlite Sameerlite left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks , this correctly fixes health checks for gpt-chat-latest suffix deployments via model-map metadata.

One gap: this only affects the health probe. Normal /chat/completions calls with max_tokens will still 400 on Azure, because gpt-chat-latest doesn't route through GPT-5/o-series config and AzureOpenAIConfig doesn't translate the param.

Could we add a general model-map flag (e.g. map_max_tokens_to_max_completion_tokens) and use it in AzureOpenAIConfig.map_openai_params as well as health checks, or

Also: unrelated test_openapi_compliance.py change - intentional or accidental?

Also: Please change the base branch to litellm_internal_staging

AleksandrLiadov added a commit to AleksandrLiadov/litellm that referenced this pull request Jun 23, 2026
… flag

Address review on BerriAI#30987:
- Replace health-check-only flag with general
  map_max_tokens_to_max_completion_tokens model-map flag
- Apply it in AzureOpenAIConfig.map_openai_params so normal
  /chat/completions no longer 400 on Azure gpt-chat-latest
- Keep health-check probe behavior driven by the same flag
- Revert unrelated test_openapi_compliance.py change
- Add map_openai_params tests
@AleksandrLiadov
AleksandrLiadov changed the base branch from litellm_oss_branch to litellm_internal_staging June 23, 2026 17:52
@AleksandrLiadov

Copy link
Copy Markdown
Contributor Author

Thanks @Sameerlite, addressed all three points:

  1. General param translation (not just health checks): Replaced the health-check-only flag with a general model-map flag map_max_tokens_to_max_completion_tokens. It's now consumed in AzureOpenAIConfig.map_openai_params, so normal /chat/completions calls with max_tokens are translated to max_completion_tokens for flagged models (e.g. azure/gpt-chat-latest) instead of 400ing. The health-check probe uses the same flag. The flag is read from the raw model-cost map (not get_model_info, which strips unknown metadata keys), with a local-map fallback so it works before the remote map ships the entry. Added map_openai_params tests covering both flagged and unflagged models.

  2. test_openapi_compliance.py: Accidental — reverted.

  3. Base branch: Retargeted to litellm_internal_staging.

@AleksandrLiadov
AleksandrLiadov force-pushed the fix/azure-chat-latest-health-max-completion-tokens branch from 629df85 to 040d231 Compare June 23, 2026 18:05
@Sameerlite

Copy link
Copy Markdown
Contributor

Thanks for the contribution! The lint CI check is still failing — could you take a look? Also triggering a fresh Greptile review on the latest commit.

@greptileai

…t-latest

Azure gpt-chat-latest rejects max_tokens and requires max_completion_tokens,
but it does not route through GPT-5/o-series config. Add a general model-map
flag map_max_tokens_to_max_completion_tokens (azure/gpt-chat-latest) consumed
by both AzureOpenAIConfig.map_openai_params (normal /chat/completions) and the
proxy health-check probe, so neither path 400s.

- Add azure/gpt-chat-latest entry + flag to both model cost maps
- AzureOpenAIConfig.map_openai_params translates max_tokens -> max_completion_tokens
- health_check merges model-cost metadata (suffix deployments) and routes the
  bounded probe token to max_completion_tokens when flagged
- tests for chat + health paths; schema allowlist updated

Rebased onto litellm_internal_staging.
@AleksandrLiadov
AleksandrLiadov force-pushed the fix/azure-chat-latest-health-max-completion-tokens branch from 040d231 to 4cc2f97 Compare June 24, 2026 11:10
@Sameerlite

Copy link
Copy Markdown
Contributor

Good fix direction (metadata flag + map_openai_params), but the cost-map lookup doesn’t match repo patterns.

Don’t call GetModelCostMap.load_local_model_cost_map() directly - use litellm.model_cost + _get_bundled_model_cost_map() (see _get_model_cost_entry_for_provider_config in utils.py).

Don’t fall back to get_model_info() for this flag - it won’t return map_max_tokens_to_max_completion_tokens. Either read the raw map entry or add the flag to ProviderSpecificModelInfo and use _supports_factory.

Health check is overbuilt - _resolve_health_check_model_info duplicates lookup logic and changes more than token params. Simpler path: pass model_info/base_model into litellm_params, keep injecting max_tokens, let AzureOpenAIConfig translate.

Tests and the cost-map entry look good. Please simplify the lookup + health-check path and I’ll re-review.

@Sameerlite

Copy link
Copy Markdown
Contributor

Thanks so much for this fix, @AleksandrLiadov — the map_max_tokens_to_max_completion_tokens flag approach looks like a clean, idiomatic solution! Triggering a fresh Greptile review on the latest commit.\n\n@greptileai

@shivamrawat1

Copy link
Copy Markdown
Collaborator

@AleksandrLiadov can your resolve the merge conflicts? i can get it to merge then.

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.

5 participants