Skip to content

fix(nvidia_nim): forward logprobs and top_logprobs to NIM models that serve them - #54008

Merged
mateo-berri merged 8 commits into
BerriAI:mainfrom
linhqm:litellm_nvidia_nim_logprobs
Nov 24, 2026
Merged

mateo-berri merged 8 commits into
BerriAI:mainfrom
linhqm:litellm_nvidia_nim_logprobs

Conversation

@linhqm

@linhqm linhqm commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

Asking an NVIDIA NIM model for logprobs or top_logprobs on chat completions through LiteLLM now works on the models NVIDIA serves them for. Before this, LiteLLM refused the request with a 400, so people had to set allowed_openai_params or drop_params, and the second one threw away what they asked for

Details

TLDR

Problem this solves:

  • nvidia_nim/ chat calls 400 on logprobs and top_logprobs
  • NVIDIA serves both on most of its hosted chat models

How it solves it:

  • NIM now sends both params to NVIDIA
  • A model whose cost-map row says no logprobs keeps the old behavior
  • Four hosted models NVIDIA serves no logprobs on carry that flag
  • Shapes NVIDIA cannot use still get LiteLLM's clear 400

User Flow

Before: a developer who wants token probabilities from an NVIDIA NIM model gets a 400 from LiteLLM

  1. They send POST https://litellm-domain/v1/chat/completions with "model": "<nim model>" and "logprobs": true
  2. The proxy answers 400 litellm.UnsupportedParamsError: nvidia_nim does not support parameters: ['logprobs']
  3. Adding "top_logprobs": 2 gets the same 400 for both params

After: the same request reaches NVIDIA and the reply carries per-token logprobs

  1. They send the same POST https://litellm-domain/v1/chat/completions with "logprobs": true
  2. The proxy answers 200, and each token in choices[0].logprobs.content has its token and logprob, streaming included
  3. Adding "top_logprobs": 2 returns the 2 most likely tokens for each position

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Live runs against NVIDIA's hosted API (integrate.api.nvidia.com). nim-lightning is nvidia/nemotron-3.5-lightning-30b-a3b, which NVIDIA serves logprobs for (openai/gpt-oss-20b, the model first used to reproduce this, was retired by NVIDIA on 2026-11-18). nim-kimi is moonshotai/kimi-k3.1-pro, which NVIDIA refuses logprobs for. Before runs at the merge base fbf539e and After at d5c800d. Cases 12 and 13 read the two model info routes, which should list logprobs only for a model whose chat accepts them. Every case prints the exact command it ran, including the jq filter that keeps the reply readable, and that command's output. The first scored tokens ("Here", "'s") come from the model's reasoning, which NVIDIA scores too, as the direct call shows

Setup, the same for both legs: 2 uvicorn workers sharing one dedicated Redis for router state and coordination, no DB since the change touches no DB path, and no --reload because it ignores --num_workers. LITELLM_LOCAL_MODEL_COST_MAP=True makes the proxy read the cost map from its own tree instead of the copy on main. Each leg ends with a worker check that sends 8 parallel streaming requests and lists which worker pid holds each connection. Env vars are NVIDIA_NIM_API_KEY, LITELLM_MASTER_KEY and LITELLM_LOCAL_MODEL_COST_MAP=True

config.yaml and commands
model_list:
  - model_name: nim-lightning
    litellm_params:
      model: nvidia_nim/nvidia/nemotron-3.5-lightning-30b-a3b
      api_key: os.environ/NVIDIA_NIM_API_KEY
  - model_name: nim-kimi
    litellm_params:
      model: nvidia_nim/moonshotai/kimi-k3.1-pro
      api_key: os.environ/NVIDIA_NIM_API_KEY
router_settings:
  redis_host: 127.0.0.1
  redis_port: $REDIS_PORT
general_settings:
  coordination_redis:
    host: 127.0.0.1
    port: $REDIS_PORT
redis-server --port $REDIS_PORT --save '' --appendonly no &
LITELLM_LOCAL_MODEL_COST_MAP=True python litellm/proxy/proxy_cli.py --config config.yaml --port $PORT --num_workers 2 --detailed_debug
for i in {1..8}; do curl -s -o /dev/null localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"nim-lightning","stream":true,"max_tokens":600,"messages":[{"role":"user","content":"Count to 100"}]}' & done
sleep 2; ss -Htnp state established "( sport = :$PORT )" | grep -o 'pid=[0-9]*' | sort | uniq -c

NVIDIA directly

NVIDIA returns logprobs and top_logprobs, ignores top_logprobs alone, rejects an integer logprobs, and refuses logprobs on kimi-k3.1-pro
#### NVIDIA directly, logprobs and top_logprobs
$ curl -s https://integrate.api.nvidia.com/v1/chat/completions -H "Authorization: Bearer $NVIDIA_NIM_API_KEY" -H "Content-Type: application/json" -d '{"model":"nvidia/nemotron-3.5-lightning-30b-a3b","logprobs":true,"top_logprobs":2,"max_tokens":400,"messages":[{"role":"user","content":"Say hi"}]}' | jq -c "{text: .choices[0].message.content, logprobs: .choices[0].logprobs.content[:2], error: (.error // .detail // .message)} | with_entries(select(.value != null))"
{"text":"Hi there! How can I help you today?","logprobs":[{"token":"Here","logprob":-0.0003853294,"token_id":11745,"bytes":[72,101,114,101],"top_logprobs":[{"token":"Here","logprob":-0.0003853294,"bytes":[72,101,114,101]},{"token":"The","logprob":-7.8753853,"bytes":[84,104,101]}]},{"token":"'s","logprob":-0.00003349725,"token_id":1681,"bytes":[39,115],"top_logprobs":[{"token":"'s","logprob":-0.00003349725,"bytes":[39,115]},{"token":"’s","logprob":-10.875033,"bytes":[226,128,153,115]}]}]}

#### NVIDIA directly, top_logprobs without logprobs
$ curl -s https://integrate.api.nvidia.com/v1/chat/completions -H "Authorization: Bearer $NVIDIA_NIM_API_KEY" -H "Content-Type: application/json" -d '{"model":"nvidia/nemotron-3.5-lightning-30b-a3b","top_logprobs":2,"max_tokens":400,"messages":[{"role":"user","content":"Say hi"}]}' | jq -c "{text: .choices[0].message.content, logprobs: .choices[0].logprobs.content[:2], error: (.error // .detail // .message)} | with_entries(select(.value != null))"
{"text":"Hi!"}

#### NVIDIA directly, integer logprobs
$ curl -s https://integrate.api.nvidia.com/v1/chat/completions -H "Authorization: Bearer $NVIDIA_NIM_API_KEY" -H "Content-Type: application/json" -d '{"model":"nvidia/nemotron-3.5-lightning-30b-a3b","logprobs":2,"max_tokens":400,"messages":[{"role":"user","content":"Say hi"}]}' | jq -c "{text: .choices[0].message.content, logprobs: .choices[0].logprobs.content[:2], error: (.error // .detail // .message)} | with_entries(select(.value != null))"
{"error":"Failed to deserialize the JSON body into the target type: invalid type: integer `2`, expected a boolean at line 1 column 127"}

#### NVIDIA directly, logprobs on kimi-k3.1-pro
$ curl -s https://integrate.api.nvidia.com/v1/chat/completions -H "Authorization: Bearer $NVIDIA_NIM_API_KEY" -H "Content-Type: application/json" -d '{"model":"moonshotai/kimi-k3.1-pro","logprobs":true,"max_tokens":400,"messages":[{"role":"user","content":"Say hi"}]}' | jq -c "{text: .choices[0].message.content, logprobs: .choices[0].logprobs.content[:2], error: (.error // .detail // .message)} | with_entries(select(.value != null))"
{"error":"Validation: `logprobs` is not supported for this model: token logprobs are not available"}

Before (fbf539e)

Every logprobs request answers 400, only drop_params or allowed_openai_params gets a 200 with no logprobs, and no model lists logprobs
#### 1. chat, logprobs
$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-lightning","logprobs":true,"max_tokens":400,"messages":[{"role":"user","content":"Say hi"}]}' | jq -c "{text: .choices[0].message.content, logprobs: .choices[0].logprobs.content[:2], error: .error.message} | with_entries(select(.value != null))"
{"error":"litellm.UnsupportedParamsError: nvidia_nim does not support parameters: ['logprobs'], for model=nvidia/nemotron-3.5-lightning-30b-a3b. To drop these, set `litellm.drop_params=True` or for proxy:\n\n`litellm_settings:\n drop_params: true`\n. \n If you want to use these params dynamically send allowed_openai_params=['logprobs'] in your request.\n\nLiteLLM: model group 'nim-lightning' failed with the error above. No fallback was attempted."}

#### 2. chat, logprobs and top_logprobs
$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-lightning","logprobs":true,"top_logprobs":2,"max_tokens":400,"messages":[{"role":"user","content":"Say hi"}]}' | jq -c "{text: .choices[0].message.content, logprobs: .choices[0].logprobs.content[:2], error: .error.message} | with_entries(select(.value != null))"
{"error":"litellm.UnsupportedParamsError: nvidia_nim does not support parameters: ['logprobs', 'top_logprobs'], for model=nvidia/nemotron-3.5-lightning-30b-a3b. To drop these, set `litellm.drop_params=True` or for proxy:\n\n`litellm_settings:\n drop_params: true`\n. \n If you want to use these params dynamically send allowed_openai_params=['logprobs', 'top_logprobs'] in your request.\n\nLiteLLM: model group 'nim-lightning' failed with the error above. No fallback was attempted."}

#### 3. chat streaming, logprobs (first chunk with a token)
$ curl -sN localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-lightning","stream":true,"logprobs":true,"max_tokens":400,"messages":[{"role":"user","content":"Say hi"}]}' | grep -m1 -E '"token"|"error"'
{"error":{"message":"litellm.UnsupportedParamsError: nvidia_nim does not support parameters: ['logprobs'], for model=nvidia/nemotron-3.5-lightning-30b-a3b. To drop these, set `litellm.drop_params=True` or for proxy:\n\n`litellm_settings:\n drop_params: true`\n. \n If you want to use these params dynamically send allowed_openai_params=['logprobs'] in your request.\n\nLiteLLM: model group 'nim-lightning' failed with the error above. No fallback was attempted.","type":"invalid_request_error","param":null,"code":"400"}}

#### 4. /v1/responses, top_logprobs
$ curl -s localhost:$PORT/v1/responses -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-lightning","top_logprobs":1,"include":["message.output_text.logprobs"],"max_output_tokens":600,"input":"Say hi"}' | jq -c "{status, output: [.output[]? | select(.type == \"message\") | .content[] | {text, logprobs: .logprobs[:2]}], error: .error.message} | with_entries(select(.value != null))"
{"output":[],"error":"litellm.UnsupportedParamsError: nvidia_nim does not support parameters: ['top_logprobs'], for model=nvidia/nemotron-3.5-lightning-30b-a3b. To drop these, set `litellm.drop_params=True` or for proxy:\n\n`litellm_settings:\n drop_params: true`\n. \n If you want to use these params dynamically send allowed_openai_params=['top_logprobs'] in your request.\n\nLiteLLM: model group 'nim-lightning' failed with the error above. No fallback was attempted."}

#### 5. chat, top_logprobs without logprobs, drop_params
$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-lightning","top_logprobs":2,"drop_params":true,"max_tokens":400,"messages":[{"role":"user","content":"Say hi"}]}' | jq -c "{text: .choices[0].message.content, logprobs: .choices[0].logprobs.content[:2], error: .error.message} | with_entries(select(.value != null))"
{"text":"Hi there!"}

#### 6. chat, top_logprobs without logprobs, no drop_params
$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-lightning","top_logprobs":2,"max_tokens":400,"messages":[{"role":"user","content":"Say hi"}]}' | jq -c "{text: .choices[0].message.content, logprobs: .choices[0].logprobs.content[:2], error: .error.message} | with_entries(select(.value != null))"
{"error":"litellm.UnsupportedParamsError: nvidia_nim does not support parameters: ['top_logprobs'], for model=nvidia/nemotron-3.5-lightning-30b-a3b. To drop these, set `litellm.drop_params=True` or for proxy:\n\n`litellm_settings:\n drop_params: true`\n. \n If you want to use these params dynamically send allowed_openai_params=['top_logprobs'] in your request.\n\nLiteLLM: model group 'nim-lightning' failed with the error above. No fallback was attempted."}

#### 7. chat, top_logprobs without logprobs, allowed_openai_params
$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-lightning","top_logprobs":2,"allowed_openai_params":["top_logprobs"],"max_tokens":400,"messages":[{"role":"user","content":"Say hi"}]}' | jq -c "{text: .choices[0].message.content, logprobs: .choices[0].logprobs.content[:2], error: .error.message} | with_entries(select(.value != null))"
{}

#### 8. text completion, integer logprobs, no drop_params
$ curl -s localhost:$PORT/v1/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-lightning","logprobs":2,"max_tokens":400,"prompt":"Say hi"}' | jq -c "{text: .choices[0].text[:40], logprobs: .choices[0].logprobs, error: .error.message} | with_entries(select(.value != null))"
{"error":"litellm.UnsupportedParamsError: nvidia_nim does not support parameters: ['logprobs'], for model=nvidia/nemotron-3.5-lightning-30b-a3b. To drop these, set `litellm.drop_params=True` or for proxy:\n\n`litellm_settings:\n drop_params: true`\n. \n If you want to use these params dynamically send allowed_openai_params=['logprobs'] in your request.\n\nLiteLLM: model group 'nim-lightning' failed with the error above. No fallback was attempted."}

#### 9. text completion, integer logprobs, drop_params
$ curl -s localhost:$PORT/v1/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-lightning","logprobs":2,"drop_params":true,"max_tokens":400,"prompt":"Say hi"}' | jq -c "{text: .choices[0].text[:40], logprobs: .choices[0].logprobs, error: .error.message} | with_entries(select(.value != null))"
{"text":"Hi!"}

#### 10. chat, logprobs on kimi-k3.1-pro (no logprobs on NIM), drop_params
$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-kimi","logprobs":true,"drop_params":true,"max_tokens":400,"messages":[{"role":"user","content":"Say hi"}]}' | jq -c "{text: .choices[0].message.content, logprobs: .choices[0].logprobs.content[:2], error: .error.message} | with_entries(select(.value != null))"
{"text":"Hi! 👋 I’m Kimi. How can I help you today?"}

#### 11. chat, logprobs on kimi-k3.1-pro, no drop_params
$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-kimi","logprobs":true,"max_tokens":400,"messages":[{"role":"user","content":"Say hi"}]}' | jq -c "{text: .choices[0].message.content, logprobs: .choices[0].logprobs.content[:2], error: .error.message} | with_entries(select(.value != null))"
{"error":"litellm.UnsupportedParamsError: nvidia_nim does not support parameters: ['logprobs'], for model=moonshotai/kimi-k3.1-pro. To drop these, set `litellm.drop_params=True` or for proxy:\n\n`litellm_settings:\n drop_params: true`\n. \n If you want to use these params dynamically send allowed_openai_params=['logprobs'] in your request.\n\nLiteLLM: model group 'nim-kimi' failed with the error above. No fallback was attempted."}

#### 12. /v1/model/info, which models list logprobs as supported
$ curl -s localhost:$PORT/v1/model/info -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" | jq -c "[.data[] | {model: .model_name, logprobs: (.model_info.supported_openai_params | index(\"logprobs\") != null), top_logprobs: (.model_info.supported_openai_params | index(\"top_logprobs\") != null)}]"
[{"model":"nim-lightning","logprobs":false,"top_logprobs":false},{"model":"nim-kimi","logprobs":false,"top_logprobs":false}]

#### 13. /model_group/info, which model groups list logprobs as supported
$ curl -s localhost:$PORT/model_group/info -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" | jq -c "[.data[] | {model_group, logprobs: (.supported_openai_params | index(\"logprobs\") != null), top_logprobs: (.supported_openai_params | index(\"top_logprobs\") != null)}]"
[{"model_group":"nim-lightning","logprobs":false,"top_logprobs":false},{"model_group":"nim-kimi","logprobs":false,"top_logprobs":false}]

#### workers
proxy parent pid 4080196, worker pids: 4080999 4081000
pids holding the 8 in-flight requests:  4 pid=4080999  4 pid=4081000 

After (d5c800d)

Chat and streaming return logprobs, kimi drops them under drop_params and does not list them, and shapes NVIDIA cannot take still get the clear 400
#### 1. chat, logprobs
$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-lightning","logprobs":true,"max_tokens":400,"messages":[{"role":"user","content":"Say hi"}]}' | jq -c "{text: .choices[0].message.content, logprobs: .choices[0].logprobs.content[:2], error: .error.message} | with_entries(select(.value != null))"
{"text":"Hi there! How can I help you today?","logprobs":[{"token":"Here","bytes":[72,101,114,101],"logprob":-0.0009236837,"top_logprobs":[{"token":"Here","bytes":[72,101,114,101],"logprob":-0.0009236837}],"token_id":11745},{"token":"'s","bytes":[39,115],"logprob":-0.000034093275,"top_logprobs":[{"token":"'s","bytes":[39,115],"logprob":-0.000034093275}],"token_id":1681}]}

#### 2. chat, logprobs and top_logprobs
$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-lightning","logprobs":true,"top_logprobs":2,"max_tokens":400,"messages":[{"role":"user","content":"Say hi"}]}' | jq -c "{text: .choices[0].message.content, logprobs: .choices[0].logprobs.content[:2], error: .error.message} | with_entries(select(.value != null))"
{"text":"Hi! 👋 How can I help you today?","logprobs":[{"token":"Here","bytes":[72,101,114,101],"logprob":-0.0015199548,"top_logprobs":[{"token":"Here","bytes":[72,101,114,101],"logprob":-0.0015199548},{"token":"The","bytes":[84,104,101],"logprob":-6.50152}],"token_id":11745},{"token":"'s","bytes":[39,115],"logprob":-0.000031470758,"top_logprobs":[{"token":"'s","bytes":[39,115],"logprob":-0.000031470758},{"token":"’s","bytes":[226,128,153,115],"logprob":-11.000031}],"token_id":1681}]}

#### 3. chat streaming, logprobs (first chunk with a token)
$ curl -sN localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-lightning","stream":true,"logprobs":true,"max_tokens":400,"messages":[{"role":"user","content":"Say hi"}]}' | grep -m1 -E '"token"|"error"'
data: {"id":"chatcmpl-c58c791a-8e33-4e8c-a8ee-2ebdb6d52505","created":1795494021,"model":"nim-lightning","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"reasoning_content":"Here","role":"assistant"},"logprobs":{"content":[{"token":"Here","bytes":[72,101,114,101],"logprob":-0.0008131535,"top_logprobs":[{"token":"Here","bytes":[72,101,114,101],"logprob":-0.0008131535}],"token_id":11745}]}}]}

#### 4. /v1/responses, top_logprobs
$ curl -s localhost:$PORT/v1/responses -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-lightning","top_logprobs":1,"include":["message.output_text.logprobs"],"max_output_tokens":600,"input":"Say hi"}' | jq -c "{status, output: [.output[]? | select(.type == \"message\") | .content[] | {text, logprobs: .logprobs[:2]}], error: .error.message} | with_entries(select(.value != null))"
{"output":[],"error":"litellm.UnsupportedParamsError: nvidia_nim does not support parameters: ['top_logprobs'], for model=nvidia/nemotron-3.5-lightning-30b-a3b. NVIDIA takes logprobs as true or false, and returns top_logprobs only with logprobs=true. To drop these, set `litellm.drop_params=True`, or on the proxy `litellm_settings: drop_params: true`. To pass them as is, send allowed_openai_params=['top_logprobs'].\n\nLiteLLM: model group 'nim-lightning' failed with the error above. No fallback was attempted."}

#### 5. chat, top_logprobs without logprobs, drop_params
$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-lightning","top_logprobs":2,"drop_params":true,"max_tokens":400,"messages":[{"role":"user","content":"Say hi"}]}' | jq -c "{text: .choices[0].message.content, logprobs: .choices[0].logprobs.content[:2], error: .error.message} | with_entries(select(.value != null))"
{"text":"Hi there! How can I help you today?"}

#### 6. chat, top_logprobs without logprobs, no drop_params
$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-lightning","top_logprobs":2,"max_tokens":400,"messages":[{"role":"user","content":"Say hi"}]}' | jq -c "{text: .choices[0].message.content, logprobs: .choices[0].logprobs.content[:2], error: .error.message} | with_entries(select(.value != null))"
{"error":"litellm.UnsupportedParamsError: nvidia_nim does not support parameters: ['top_logprobs'], for model=nvidia/nemotron-3.5-lightning-30b-a3b. NVIDIA takes logprobs as true or false, and returns top_logprobs only with logprobs=true. To drop these, set `litellm.drop_params=True`, or on the proxy `litellm_settings: drop_params: true`. To pass them as is, send allowed_openai_params=['top_logprobs'].\n\nLiteLLM: model group 'nim-lightning' failed with the error above. No fallback was attempted."}

#### 7. chat, top_logprobs without logprobs, allowed_openai_params
$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-lightning","top_logprobs":2,"allowed_openai_params":["top_logprobs"],"max_tokens":400,"messages":[{"role":"user","content":"Say hi"}]}' | jq -c "{text: .choices[0].message.content, logprobs: .choices[0].logprobs.content[:2], error: .error.message} | with_entries(select(.value != null))"
{"text":"Hi! How can I help you today?"}

#### 8. text completion, integer logprobs, no drop_params
$ curl -s localhost:$PORT/v1/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-lightning","logprobs":2,"max_tokens":400,"prompt":"Say hi"}' | jq -c "{text: .choices[0].text[:40], logprobs: .choices[0].logprobs, error: .error.message} | with_entries(select(.value != null))"
{"error":"litellm.UnsupportedParamsError: nvidia_nim does not support parameters: ['logprobs'], for model=nvidia/nemotron-3.5-lightning-30b-a3b. NVIDIA takes logprobs as true or false, and returns top_logprobs only with logprobs=true. To drop these, set `litellm.drop_params=True`, or on the proxy `litellm_settings: drop_params: true`. To pass them as is, send allowed_openai_params=['logprobs'].\n\nLiteLLM: model group 'nim-lightning' failed with the error above. No fallback was attempted."}

#### 9. text completion, integer logprobs, drop_params
$ curl -s localhost:$PORT/v1/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-lightning","logprobs":2,"drop_params":true,"max_tokens":400,"prompt":"Say hi"}' | jq -c "{text: .choices[0].text[:40], logprobs: .choices[0].logprobs, error: .error.message} | with_entries(select(.value != null))"
{"text":"Hi there!"}

#### 10. chat, logprobs on kimi-k3.1-pro (no logprobs on NIM), drop_params
$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-kimi","logprobs":true,"drop_params":true,"max_tokens":400,"messages":[{"role":"user","content":"Say hi"}]}' | jq -c "{text: .choices[0].message.content, logprobs: .choices[0].logprobs.content[:2], error: .error.message} | with_entries(select(.value != null))"
{"text":"Hi! 👋 How can I help you today?"}

#### 11. chat, logprobs on kimi-k3.1-pro, no drop_params
$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-kimi","logprobs":true,"max_tokens":400,"messages":[{"role":"user","content":"Say hi"}]}' | jq -c "{text: .choices[0].message.content, logprobs: .choices[0].logprobs.content[:2], error: .error.message} | with_entries(select(.value != null))"
{"error":"litellm.UnsupportedParamsError: nvidia_nim does not support parameters: ['logprobs'], for model=moonshotai/kimi-k3.1-pro. To drop these, set `litellm.drop_params=True` or for proxy:\n\n`litellm_settings:\n drop_params: true`\n. \n If you want to use these params dynamically send allowed_openai_params=['logprobs'] in your request.\n\nLiteLLM: model group 'nim-kimi' failed with the error above. No fallback was attempted."}

#### 12. /v1/model/info, which models list logprobs as supported
$ curl -s localhost:$PORT/v1/model/info -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" | jq -c "[.data[] | {model: .model_name, logprobs: (.model_info.supported_openai_params | index(\"logprobs\") != null), top_logprobs: (.model_info.supported_openai_params | index(\"top_logprobs\") != null)}]"
[{"model":"nim-lightning","logprobs":true,"top_logprobs":true},{"model":"nim-kimi","logprobs":false,"top_logprobs":false}]

#### 13. /model_group/info, which model groups list logprobs as supported
$ curl -s localhost:$PORT/model_group/info -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" | jq -c "[.data[] | {model_group, logprobs: (.supported_openai_params | index(\"logprobs\") != null), top_logprobs: (.supported_openai_params | index(\"top_logprobs\") != null)}]"
[{"model_group":"nim-lightning","logprobs":true,"top_logprobs":true},{"model_group":"nim-kimi","logprobs":false,"top_logprobs":false}]

#### workers
proxy parent pid 4095878, worker pids: 4096818 4096819
pids holding the 8 in-flight requests:  5 pid=4096818  3 pid=4096819 

After, with #49536 merged in (21ec4635153)

This PR's commits through d5c800d, without its latest merge of main, with #49536 at 1bc94cb merged in. It is a local tree for this check only, since #49536 does not merge cleanly into the current main, and it uses the same setup as the other legs

/v1/responses returns logprobs with both PRs in, streaming included
#### 4. /v1/responses, top_logprobs
$ curl -s localhost:$PORT/v1/responses -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-lightning","top_logprobs":1,"include":["message.output_text.logprobs"],"max_output_tokens":600,"input":"Say hi"}' | jq -c "{status, output: [.output[]? | select(.type == \"message\") | .content[] | {text, logprobs: .logprobs[:2]}], error: .error.message} | with_entries(select(.value != null))"
{"status":"completed","output":[{"text":"Hi there! 😊","logprobs":[{"token":"Here","logprob":-0.0015170982,"bytes":[72,101,114,101],"top_logprobs":[{"token":"Here","logprob":-0.0015170982,"bytes":[72,101,114,101]}]},{"token":"'s","logprob":-0.00004458328,"bytes":[39,115],"top_logprobs":[{"token":"'s","logprob":-0.00004458328,"bytes":[39,115]}]}]}]}

#### 4b. /v1/responses streaming, top_logprobs (first event with logprobs)
$ curl -sN localhost:$PORT/v1/responses -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"nim-lightning","stream":true,"top_logprobs":1,"include":["message.output_text.logprobs"],"max_output_tokens":600,"input":"Say hi"}' | grep -m1 -E '"logprobs":\[\{|"error"'
data: {"logprobs":[{"token":"</think>","logprob":-0.00022611445,"bytes":[60,47,116,104,105,110,107,62],"top_logprobs":[{"token":"</think>","logprob":-0.00022611445,"bytes":[60,47,116,104,105,110,107,62]}]},{"token":"Hi","logprob":-1.072883e-6,"bytes":[72,105],"top_logprobs":[{"token":"Hi","logprob":-1.072883e-6,"bytes":[72,105]}]},{"token":" there","logprob":-0.000013232144,"bytes":[32,116,104,101,114,101],"top_logprobs":[{"token":" there","logprob":-0.000013232144,"bytes":[32,116,104,101,114,101]}]}],"type":"response.output_text.delta","item_id":"msg_8add4799-9e4d-4dde-8b0c-d290efef30db","output_index":1,"content_index":0,"delta":"Hi there","sequence_number":67,"model":"nim-lightning"}

#### workers
proxy parent pid 4111657, worker pids: 4113530 4113531
pids holding the 8 in-flight requests:  5 pid=4113530  2 pid=4113531 

Type

🐛 Bug Fix

Caveats (if any)

Medium

  • /v1/responses top_logprobs still answers 400 until fix(responses): carry logprobs across the chat completions bridge #49536 merges
  • NIM models with no cost-map row now answer 400 under drop_params if they refuse logprobs
    • Any nvidia_nim/ model with no cost-map row gets logprobs sent to NVIDIA. If that model refuses them, the caller now gets NVIDIA's 400. Before, drop_params: true gave a 200 without logprobs
    • This hits self-hosted NIMs and hosted models NVIDIA adds later. None of today's reachable hosted chat models hit it. kimi-k3.1-pro is the only one that refuses, and it is flagged
    • A deployment's model_info: supports_logprobs: false does not turn it off. The only opt-out is additional_drop_params, which drops the params even without drop_params. /model/info still lists logprobs for that deployment
  • nemotron-safety-guard-8b-v3 now returns 200 with no logprobs
    • logprobs: true alone used to get LiteLLM's 400. It now gets a 200 with logprobs: null, and the model lists logprobs as supported
    • NVIDIA returns them for this model only when top_logprobs is also sent. The PR flags the three other models that return no logprobs, but not this one, since the flag would also block logprobs with top_logprobs, which works there

Low

  • The new kimi-k3.1-pro row changes its cost from unmapped to $0
    • response_cost was None with a "model isn't mapped" error and is now 0.0, so x-litellm-response-cost reads 0.0
    • This matches the other NIM rows, none of which carry prices
  • On /v1/responses the refusal asks for logprobs=true, which a Responses caller cannot send. fix(responses): carry logprobs across the chat completions bridge #49536 sends both params, so this goes away with it
  • A complexity router tier that pins top_logprobs without logprobs on a NIM deployment now answers 400 unless drop_params is on
    • Before, the router dropped that pin with a warning, since NIM did not declare the param. An OpenAI deployment refuses the same pin, and pinning both params works
  • Four # mutable-ok follow the dict that get_optional_params fills in place, and the cost-map read is a cast, since validating the whole map on every call is slow. The tests set litellm.drop_params and litellm.model_cost through monkeypatch, the way callers set them
Decisions
  • A model with no cost-map row, or a row without supports_logprobs, gets both params sent to NVIDIA. Most hosted chat models that answered a probe return logprobs, so sending them by default is right. Dropping them for unknown models instead would hide logprobs from most callers. Gemini uses the same rule, and an operator can drop them per deployment with additional_drop_params: ["logprobs", "top_logprobs"]
  • An integer logprobs, which /v1/completions sends as a count, is refused without drop_params and dropped with it, the same as before this PR. NVIDIA only takes true or false. Translating it to logprobs: true plus top_logprobs was rejected because the text completion bridge returns no logprobs from a chat provider, so the caller would get nothing back for it
  • top_logprobs without logprobs: true is refused without drop_params and dropped with it, the same as before this PR. NVIDIA ignores it on some models and answers a bare 400 on others (kimi-k3.1-pro, muse-glimmer-30b), so LiteLLM's error naming the param and the fix is clearer. allowed_openai_params: ["top_logprobs"] still sends it as is
  • /v1/responses with top_logprobs keeps the 400 from before this PR, because the Responses bridge sends top_logprobs without logprobs. fix(responses): carry logprobs across the chat completions bridge #49536 sends both and carries the logprobs back, and the run with both PRs merged in shows /v1/responses returning logprobs

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR
Bugbot summary

[!NOTE]
Medium Risk
Changes NVIDIA NIM request validation and which params reach the API; behavior shifts for logprobs on unknown or flagged models, but scope is limited to the nvidia_nim provider with broad test coverage.

Overview
NVIDIA NIM chat completions forward logprobs and top_logprobs to NVIDIA when the model supports them, instead of always returning LiteLLM’s UnsupportedParamsError. NvidiaNimConfig now gates those params on the cost map’s supports_logprobs flag, validates NVIDIA’s boolean-only logprobs and top_logprobs only with logprobs=true, and plugs into MapsAllowedOpenAIParams so allowed_openai_params and drop_params behave like other OpenAI-like providers. The dedicated nvidia_nim branch in get_optional_params is removed in favor of that shared path.

The cost map adds supports_logprobs: false for several hosted models (including new moonshotai/kimi-k3.1-pro) and unit tests cover forwarding, rejection, dropping, and supported-param discovery.

Reviewed by Cursor Bugbot for commit d5c800d. Bugbot is set up for automated code reviews on this repo. Configure here.

…ponses

NVIDIA NIM serves logprobs and top_logprobs, but nvidia_nim refused both with
UnsupportedParamsError. The Responses bridge also never asked chat for logprobs
when include requested message.output_text.logprobs, leaked top_logprobs on its
own, and dropped the logprobs the model returned. It now maps include to chat
logprobs and puts the tokens on output_text and the streaming events
…gprobs

# Conflicts:
#	tests/unit/llms/nvidia_nim/test_nvidia_nim.py
@veria-ai

veria-ai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

@mateo-berri mateo-berri added the autoapprove This PR may be autoapproved by greptile. The author thinks that it does not need human review. label Nov 24, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge with no new actionable findings.

Summary

This PR forwards logprobs and top_logprobs to NVIDIA NIM models unless their catalog entry explicitly disables them. It preserves rejection, dropping, and explicit overrides for request shapes NVIDIA cannot use.

Both catalog copies carry the new flags. Tests cover outgoing requests, returned probabilities, and model information. The earlier shared-worker QA concern is addressed by the supplied Redis setup and proof that both workers served requests.

  • NIM chat replies now include token scores when models support them.

Reviews (3) · Last reviewed commit: "fix(nvidia_nim): read the logprobs flag ..." · Reviewed by Greptile

@surlymochan surlymochan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verified the logic against the source rather than just the diff, and it holds up:

  • drops_unsupported_params (litellm/litellm_core_utils/core_helpers.py:424-425) returns true for either the per-call flag or the global litellm.drop_params, so the parametrized test's global-flag cases exercise a real path, not just the argument.
  • Branch order in map_openai_params is correct: the top_logprobs drop is checked before the generic param in supported_openai_params branch — since top_logprobs is now in the supported list, the check has to come first or the drop could never trigger.
  • The live-run matrix in the PR body (before: 400 UnsupportedParamsError on all six cases; after: 200 with per-token logprobs on chat, including streaming) matches what the unit tests pin, including the /v1/responses case returning 200 without logprobs until #49536.

One question, not a blocker: asks_logprobs uses non_default_params["logprobs"] is True, so a caller passing a truthy non-bool (e.g. logprobs=1) would be treated as not asking and top_logprobs would be dropped under drop_params. Is the strict check intentional, or should it be a truthiness check?

Non-binding review — leaving the merge decision to the maintainers.

@mateo-berri mateo-berri changed the title fix(nvidia_nim): forward logprobs and top_logprobs to NIM instead of answering 400 fix(nvidia_nim): forward logprobs and top_logprobs to NIM models that serve them Nov 24, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

…gprobs

# Conflicts:
#	litellm/llms/nvidia_nim/chat/transformation.py
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit d5c800d. Configure here.

@mateo-berri mateo-berri 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.

LGTM

@mateo-berri
mateo-berri merged commit 88240a6 into BerriAI:main Nov 24, 2026
59 checks passed
mateo-berri added a commit that referenced this pull request Nov 24, 2026
…answering 400

Port of the nvidia_nim change in #54008 onto lts/1.108.x. NIM's supported params now
list logprobs and top_logprobs, and top_logprobs sent without logprobs is dropped only
under drop_params

Source commits on main: e2a826c, 695e0e8, 537b438 (the first commit's
Responses bridge work was reverted by the second, so only the nvidia_nim files move)
mateo-berri added a commit that referenced this pull request Nov 24, 2026
…s_1_108_x

fix(nvidia_nim): forward logprobs and top_logprobs to NIM models that serve them on lts/1.108.x (#54008)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autoapprove This PR may be autoapproved by greptile. The author thinks that it does not need human review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants