Repository navigation
fix(litellm_model): read the proxy version from a one-token probe whe… - #4869
Conversation
…n the health route is forbidden
LiteLLM virtual keys scoped to `allowed_routes: ['llm_api_routes']` get
HTTP 403 on `/health/readiness/details`, so `_check_proxy_version` raised
and the model server refused to start even against a current proxy.
`GET /v1/models` cannot supply the version: on a real deployment it (and
`/models`, `/health/liveliness`) answers 200 without `x-litellm-version`;
the proxy attaches that header to LLM-call responses only.
When the health route answers 401 or 403 (and only then), POST a one-token
chat completion (`{model: <configured model>, messages: [one short user
message], max_tokens: 1}`) to `<base_url>/v1/chat/completions` with the same
auth headers and timeout, and read `x-litellm-version` from the response
headers whatever the HTTP status is: a model-side 4xx (for example a
thinking model rejecting `max_tokens=1`) still carries the proxy header.
The same parsing, compromised-version and `>= 1.83.0` checks apply; a
missing header or a transport failure still fails closed. A WARNING states
that the probe is a billed one-token call and an INFO line records the
version and that it came from the probe. Operators who object to the probe
can grant the key the health route instead. Behaviour is unchanged when the
health route works.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Rima Shahbazyan <[email protected]>
|
/review |
|
/ok to test e403d40 |
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
SHIP
LGTM — no reliability concerns. Reviewed all three changed files and traced the startup fallback through the shared HTTP helper. The 401/403 branch retains the existing version parsing, compromised-version rejection, and minimum-version guard; successful health checks do not send a probe.
Static review only; tests were not executed in this read-only environment.
Note: formal approval is not available for this request, so this review is posted as a comment only.
Review generated by codex. This was a full review. Request a full review with /review reset=true.
|
/ok to test 635ef50 |
|
Thanks for the fix. One startup correctness issue to address before merging: |
…l-side errors keep the header Review finding on #4869: the fallback probe and its test assumed that a model rejecting the one-token chat completion still answers with x-litellm-version. In LiteLLM 1.105.x the chat-completion exception path omits the version argument to the error handler, so the header is dropped on a model-side 4xx and Gym refuses to start even on a safe proxy. The Responses API exception path passes the version, so its error responses keep the header. Reproduced live on a LiteLLM 1.106.2 proxy with a route-scoped key against a model that rejects the probe: POST /v1/chat/completions 400 answered with x-litellm-call-id, x-litellm-response-cost, x-litellm-key-max-budget, x-litellm-key-spend and x-litellm-timeout only; the same 400 on POST /v1/responses also carried x-litellm-model-id and x-litellm-version. The one-token Responses probe returned 200 with the header on three different model routes. - _version_from_probe_header now POSTs <base_url>/v1/responses with {"model": <configured>, "input": "ping", "max_output_tokens": 1}; same auth headers and timeout; the header is still read regardless of HTTP status and a missing header or transport failure still fails closed. - Module docstring, constant comment, WARNING/INFO log text and README say why neither /v1/models nor /v1/chat/completions is usable. - Tests assert the /v1/responses URL and body, and two regression cases use the observed error-response header sets: the Responses API set (version present) passes, the chat-completions set (no version) fails closed with the "no x-litellm-version header" RuntimeError. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Rima Shahbazyan <[email protected]>
|
LGTM. Thanks for switching the probe to /v1/responses |
|
/ok to test cdcdb5c |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/40155012653 |
What does this PR do?
Lets
litellm_modelstart behind a LiteLLM proxy whose virtual key cannot call the health route, without weakening the minimum-version guard.Why.
LiteLLMModelServer._check_proxy_versionGETs/health/readiness/detailsand requireslitellm_version >= 1.83.0(the guard added after the March 2026 supply-chain incident). LiteLLM virtual keys scoped toallowed_routes: ['llm_api_routes']get HTTP 403 on that route ("Virtual key is not allowed to call this route. Only allowed to call routes: ['llm_api_routes']"), so the server raisedRuntimeErrorand refused to start even though the proxy was current. Origin: the review thread on #4727 (#4727 (comment)), where reading the version from the proxy'sx-litellm-versionresponse header was agreed as the preferred fix instead of skipping the check.Why not
GET /v1/models. An earlier draft of this change read the header fromGET /v1/models. On a real deployment that does not work:/v1/models,/modelsand/health/livelinessall answer 200 withoutx-litellm-version; the proxy attaches thex-litellm-*header family to LLM-call responses only (POST /v1/chat/completions,POST /v1/responses). With that draft the server failed closed at startup (fallback GET .../v1/models returned no x-litellm-version header), which is the correct failure mode but the wrong fallback route.Design. When the health route answers 401 or 403 (and only then), POST a one-token chat completion to
<base_url>/v1/chat/completionswith the sameAuthorization/x-litellm-keyheaders under the same 5 s timeout:{"model": <configured openai_model>, "messages": [{"role": "user", "content": "ping"}], "max_tokens": 1}. Thex-litellm-versionheader is read from the response whatever its HTTP status is: a model-side 4xx (for example a thinking model rejectingmax_tokens=1) still carries the proxy header. The value feeds the existing parse, compromised-version and>= 1.83.0checks. Only a missing header or a transport failure fails closed (RuntimeError, server does not start). Other health failures (5xx, timeouts) still fail immediately without a fallback call. No new config knob.Trade-off. The probe is a billed one-token LLM call at server start (observed cost on the verified route:
x-litellm-response-cost: 4.14e-05). It is logged at WARNING, and an INFO line records the version and that it came from the probe because the health route is forbidden. Operators who object to the probe can instead grant the key the health route, in which case no probe is sent and behaviour is identical to today./v1/responsesalso carries the header; chat completions was chosen as the smallest request every route-scoped key can make.Changes.
responses_api_models/litellm_model/app.py:_version_from_probe_headerplus the 401/403 branch in_check_proxy_version; module docstring and constant comment explain why/v1/modelscannot be used. The health-route success path is unchanged.responses_api_models/litellm_model/README.md: one paragraph describing the check, the probe, why/v1/modelsis not usable, the billing trade-off and the health-route alternative.responses_api_models/litellm_model/tests/test_app.py: six fallback cases inTestVersionCheck(five new, one guard).Validation
Fallback tests:
1.105.1-> passes; asserts exactly two requests, the second aPOSTto<base>/v1/chat/completionswith identical auth headers,max_tokens: 1and the configured model1.105.1-> passes (header read regardless of status)1.82.9->RuntimeErrornaming the minimum safe version1.83.0RuntimeErrornaming the missingx-litellm-versionheaderOSError) ->RuntimeError("Could not verify") after two requestsRuntimeErrorafter a single request (no fallback attempted)Verified negatively: with
app.pyreverted tomain, the first five fail; against the earlier/v1/modelsdraft the first two fail; with the fallback widened to every non-OK health status the last one fails. The pre-existingtest_safe_version_allows_startupstill asserts a single request on the 200 path, andtest_health_auth_error_blocks_startup(401 on both routes, no header) still fails closed.Live verification against a route-scoped virtual key on a LiteLLM proxy (local evidence:
hle-diamond-runs/_option2-smoke/REPORT.md): health route 403;GET /v1/models200 with nox-litellm-version; one-token probe 200 withx-litellm-version: 1.105.1;_check_proxy_version()logs the probe-sourced version and passes; a 5-row HLE-Diamond smoke throughlitellm_modelon a Claude route then ran 5/5 rollouts with no failures, where the same smoke with the/v1/modelsdraft died at startup.Rollouts
N/A for request/response handling: startup-time version check only. The 5/5 smoke above exercised the full path once the server started.
Compatibility and benchmark impact
None for deployments where the health route works (byte-identical behaviour; no probe is sent). Deployments with route-scoped keys that previously could not start now start, at the cost of one billed one-token call per server start, provided the proxy is
>= 1.83.0. No config changes, no migration, no benchmark-result effect.Checklist
pre-commit run --all-files) (so CI lint/format checks pass).git commit -s) (so the DCO check passes).