Repository navigation
fix(proxy)!: stop answering with the literal string "None" as error type and param on the proxy-server, auth, spend, and key health routes - #39540
Conversation
…y-server, auth, and health routes The error objects these routes return defaulted `type` and `param` to the four-character string "None", so a client's error handler matched no known OpenAI type and fell into its generic branch. Route them through the shared openai_error_payload helpers instead, so `type` comes from the carried type or the HTTP status and `param` serializes as JSON null.
[Medium impact] The PR appears safe to merge. SummaryThis PR standardizes proxy error payloads so absent parameters serialize as JSON
Reviews (10) · Last reviewed commit: "test(proxy): build the transcription fil..." · Reviewed by Greptile |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…d and management routes The error objects these routes return defaulted `type` and `param` to the four-character string "None", so a client's error handler matched no known OpenAI type and fell into its generic branch. Route them through the shared openai_error_payload helpers instead, so `type` comes from the carried type or the HTTP status and `param` serializes as JSON null.
Takes main's version of each conflicted file, then reapplies the same helper swap on every remaining site that still answered with the literal string "None" as error type or param, and ports the regression tests.
…to a JSON null param
|
@litereview code-review |
1 similar comment
|
@litereview code-review |
|
Main's integration tests still expected the string "None" in param, and seven auth raises (no key, malformed key, master-key-only route, blocked key, SCIM deactivated user, invalid token, admin-only route) still built it, so they now pass None and the tests expect null.
…payload_proxy_server_auth_health # Conflicts: # litellm/proxy/health_endpoints/_health_endpoints.py # litellm/proxy/management_endpoints/internal_user_endpoints.py # litellm/proxy/management_endpoints/key_management_endpoints.py # litellm/proxy/management_endpoints/model_management_endpoints.py # litellm/proxy/management_endpoints/organization_endpoints.py # litellm/proxy/management_endpoints/team_endpoints.py # litellm/proxy/proxy_server.py # tests/integration/management/test_team_delete_large_membership.py # tests/unit/proxy/management_endpoints/test_key_management_endpoints.py
…the tag-routing and no-deployment remap
…d ban the string None as an error type or param
|
bugbot run |
…transcription by its status, as chat does Only a status the proxy remapped into 401 or 403, such as a tag-routing denial, keeps auth_error.
|
bugbot run |
…o it holds after the router refactor
|
bugbot run |
There was a problem hiding this comment.
✅ 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 8ce7767. Configure here.
…aram_lts_1_108_x test(auth): expect null error param for blocked keys (#39540) [lts/1.108.x]
Apply the two integration test updates from 636e707 (BerriAI#39540). The LTS responses already use JSON null.
Many gateway errors outside the LLM endpoints send
typeandparamas the stringNone, which OpenAI-style handlers can't classifyThis moves the proxy server, auth, spend, and key health routes onto the shared error helpers, as #48739 did for health and management
A rejected transcription keeps its 400, so the SDK stops retrying, and a stream a proxy check ends mid-answer reports that check's status, such as 429, not 500
Original
TLDR
Problem this solves:
"type": "None"paramgoes out as the string"None", notnullHow it solves it:
"None"errortypeorparamtypefalls back to the HTTP status's typeparamserializes as JSONnullIntentional product change:
paramis JSONnull, and rejected transcriptions and proxy-ended streams keep their status, not 500User Flow
Before: an OpenAI-style handler can't classify these errors
POST https://litellm-domain/v1/chat/completionswith noAuthorizationheader"param":"None"where their handler expectsnullPOST https://litellm-domain/spend/calculatewith an empty JSON body"type":"None", so theirinvalid_request_errorbranch never firesAfter: the same requests come back typed
POST https://litellm-domain/v1/chat/completionswith noAuthorizationheader"type":"auth_error","param":nullPOST https://litellm-domain/spend/calculatewith an empty JSON body"type":"invalid_request_error","param":nullPre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
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 moreDelays 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
Last updated: 8ce7767. QA ran on ed2c5c0. Changes since QA: a hook's 401 or 403 off chat is typed by status, and a test-only commit. Proof remains valid because only the hook and tag-denial cases reach the hook change, and both re-ran at 7c75bc7. Verification: the completions, moderations, and audio tests
"None","None"invalid_request_error,null"None","None"internal_server_error,nullcode500code429auth_error,"None"auth_error,null"None"paramnullparammetadata"None","None"auth_error,null"None","None"permission_error,nullCells are the body's
typeandparam, or status and SDK request count. The gist holds every case, with the stringNoneon 34 base lines and none at the tipShared setup
Both legs boot the same config with 2 uvicorn workers, each against its own Postgres container, and differ only in the commit.
cbf4e40d38is this PR's merge base with main anded2c5c0bdcis its tip. They ran side by side on a Linux dev box. The clients are the OpenAI Python SDK 3.37.0 and curl. The JWT case pointsJWT_PUBLIC_KEY_URLat a port with nothing listening, the database case pauses that leg's Postgres container mid-run, and the mid-answer cases add a customer-style streaming callback that raises a plain error or a 429 budget error after two chunks. The file cap case sends a 2 MB recording to a transcription deployment set tomax_file_size_mb: 1, and the tag-routing case turns onenable_tag_filteringand sends the tagfreeto a model whose only deployment is taggedpaid. The config, the callback, and the leg scripts are the00_files in the gistBefore (cbf4e40)
Spend calculate with an empty body
typeandparamas the stringNoneTranscription with an unknown model
Steps and output
client.audio.transcriptions.create(model="no-such-audio-model", file=f)with the OpenAI SDKopenai.BadRequestErrorCompletions with an unknown model
Steps and output
curl -sS -i "$PROXY_BASE_URL/v1/completions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"no-such-completion-model","prompt":"hello","max_tokens":5}'typeandparamas the stringNoneAuth rejections
Steps and output
/v1/chat/completionswith noAuthorizationheader, then withAuthorization: sk-no-bearer-prefixPOST /key/block, then call chat through the OpenAI SDK with it, and again with a key whose user SCIM deactivatedPOST /global/spend/resetwith a virtual key,POST /model/newandPOST /budget/newwith aninternal_userkeyparamas the stringNoneon all sevenSpend logs and tags with bad input
Steps and output
curl -sS -i "$PROXY_BASE_URL/spend/logs?start_date=not-a-date&end_date=also-bad" -H "Authorization: Bearer $LITELLM_MASTER_KEY", the same query on/spend/tags, and/spend/logs/ui?page=1&page_size=10with no datesparamas the stringNoneon all threeKey health with a malformed logging entry
Steps and output
curl -sS -X POST "$PROXY_BASE_URL/key/generate" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"metadata":{"logging":["just-a-string"]}}'curl -sS -i -X POST "$PROXY_BASE_URL/key/health" -H "Authorization: Bearer $GENERATED_KEY"with the key it returnedparamis the stringNoneStream that fails mid-answer
Steps and output
midstream-gpt-5.4-miniwith the OpenAI SDK through the proxy whose streaming callback raises after two chunksopenai.APIErrorwhosetypeandparamare the stringNoneStream that hits a 429 limit mid-answer
Steps and output
midstream-limit-gpt-5.4-miniwith the OpenAI SDK through the proxy whose streaming callback raises a 429 budget error after two chunksopenai.APIErrorwhosecodeis500curl -sS -N "$PROXY_BASE_URL/v1/chat/completions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"midstream-limit-gpt-5.4-mini","stream":true,"messages":[{"role":"user","content":"Count from 1 to 30, one number per line"}]}'[DONE]JWKS endpoint unreachable
Steps and output
/v1/chat/completionsparamis the stringNoneDatabase down
Steps and output
docker pause, then callGET /team/listwith the master keyparamis the stringNoneTranscription file over the size cap
Steps and output
client.audio.transcriptions.create(model="transcribe-capped", file=f)on a 2 MB file with the OpenAI SDK's default retries, counting the requests it sendscurl -sS -i "$PROXY_BASE_URL/v1/audio/transcriptions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -F model=transcribe-capped -F file=@two_mb.wavTranscription with a bad metadata field
Steps and output
client.audio.transcriptions.create(model="gpt-4o-mini-transcribe", file=f, extra_body={"metadata": 123})with the OpenAI SDK's default retries, counting the requests it sendscurl -sS -i "$PROXY_BASE_URL/v1/audio/transcriptions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -F model=gpt-4o-mini-transcribe -F metadata=123 -F file=@tone.wavTag-routing denial on completions
Steps and output
client.completions.create(model="gpt-5.4-mini-paid-tier", prompt="hello", max_tokens=5, extra_body={"metadata": {"tags": ["free"]}})with the OpenAI SDKtypeandparamare the stringNonecurl -sS -i "$PROXY_BASE_URL/v1/completions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"gpt-5.4-mini-paid-tier","prompt":"hello","max_tokens":5,"metadata":{"tags":["free"]}}', then the same request on/v1/chat/completions, which this PR leaves alone, then a chat request taggedpaidas a controlinternal_server_erroron chat completions, and a 200 for the controlA hook's 403 off chat
Steps and output
HTTPException(403)for everypolicy-block-*model, the gist's00_lpr_hooks.pyand00_lpr_config.yaml/v1/chat/completions,/v1/completions,/v1/moderations, and/v1/audio/transcriptionsin that order, the completions request beingcurl -sS "$PROXY_BASE_URL/v1/completions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"policy-block-gpt-5.4-mini","prompt":"Say hi","max_tokens":5}' -w "\nstatus=%{http_code}\n", with all four in the gist'slpr_r06_policy_block_403filestypeandparamas the stringNoneoff chat, while chat answerspermission_errorControls with real spend
Steps and output
After (ed2c5c0)
Spend calculate with an empty body
typeand a JSONnullparamTranscription with an unknown model
Steps and output
client.audio.transcriptions.create(model="no-such-audio-model", file=f)with the OpenAI SDKopenai.BadRequestErrorCompletions with an unknown model
Steps and output
curl -sS -i "$PROXY_BASE_URL/v1/completions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"no-such-completion-model","prompt":"hello","max_tokens":5}'typeand a JSONnullparamAuth rejections
Steps and output
/v1/chat/completionswith noAuthorizationheader, then withAuthorization: sk-no-bearer-prefixPOST /key/block, then call chat through the OpenAI SDK with it, and again with a key whose user SCIM deactivatedPOST /global/spend/resetwith a virtual key,POST /model/newandPOST /budget/newwith aninternal_userkeynullparamon all sevenSpend logs and tags with bad input
Steps and output
curl -sS -i "$PROXY_BASE_URL/spend/logs?start_date=not-a-date&end_date=also-bad" -H "Authorization: Bearer $LITELLM_MASTER_KEY", the same query on/spend/tags, and/spend/logs/ui?page=1&page_size=10with no datesnullparamon all threeKey health with a malformed logging entry
Steps and output
curl -sS -X POST "$PROXY_BASE_URL/key/generate" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"metadata":{"logging":["just-a-string"]}}'curl -sS -i -X POST "$PROXY_BASE_URL/key/health" -H "Authorization: Bearer $GENERATED_KEY"with the key it returnednullparamStream that fails mid-answer
Steps and output
midstream-gpt-5.4-miniwith the OpenAI SDK through the proxy whose streaming callback raises after two chunksopenai.APIErrorwith a namedtypeand a nullparamStream that hits a 429 limit mid-answer
Steps and output
midstream-limit-gpt-5.4-miniwith the OpenAI SDK through the proxy whose streaming callback raises a 429 budget error after two chunksopenai.APIErrorwhosecodeis429curl -sS -N "$PROXY_BASE_URL/v1/chat/completions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"midstream-limit-gpt-5.4-mini","stream":true,"messages":[{"role":"user","content":"Count from 1 to 30, one number per line"}]}'[DONE]JWKS endpoint unreachable
Steps and output
/v1/chat/completionsnullparamDatabase down
Steps and output
docker pause, then callGET /team/listwith the master keynullparamTranscription file over the size cap
Steps and output
client.audio.transcriptions.create(model="transcribe-capped", file=f)on a 2 MB file with the OpenAI SDK's default retries, counting the requests it sendscurl -sS -i "$PROXY_BASE_URL/v1/audio/transcriptions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -F model=transcribe-capped -F file=@two_mb.wavTranscription with a bad metadata field
Steps and output
client.audio.transcriptions.create(model="gpt-4o-mini-transcribe", file=f, extra_body={"metadata": 123})with the OpenAI SDK's default retries, counting the requests it sendscurl -sS -i "$PROXY_BASE_URL/v1/audio/transcriptions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -F model=gpt-4o-mini-transcribe -F metadata=123 -F file=@tone.wavTag-routing denial on completions
Steps and output
client.completions.create(model="gpt-5.4-mini-paid-tier", prompt="hello", max_tokens=5, extra_body={"metadata": {"tags": ["free"]}})with the OpenAI SDKauth_error, as main's other routes type a proxy denial, with a JSONnullparamcurl -sS -i "$PROXY_BASE_URL/v1/completions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"gpt-5.4-mini-paid-tier","prompt":"hello","max_tokens":5,"metadata":{"tags":["free"]}}', then the same request on/v1/chat/completions, which this PR leaves alone, then a chat request taggedpaidas a controlA hook's 403 off chat, at 7c75bc7
Steps and output
HTTPException(403)for everypolicy-block-*model, the gist's00_lpr_hooks.pyand00_lpr_config.yaml/v1/chat/completions,/v1/completions,/v1/moderations, and/v1/audio/transcriptionsin that order, the completions request beingcurl -sS "$PROXY_BASE_URL/v1/completions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model":"policy-block-gpt-5.4-mini","prompt":"Say hi","max_tokens":5}' -w "\nstatus=%{http_code}\n", with all four in the gist'slpr_r06_policy_block_403filespermission_errorand a JSONnullparamon all four routesControls with real spend
Steps and output
Observations, all on main already and left alone
/key/healthanswers 500 on a malformed logging entrydetailshape/global/spend/tagsputs a server traceback in its message/user/infotypes a 404 asinternal_server_error/v1/chat/completionstypes a tag denialinternal_server_errorType
🐛 Bug Fix
Caveats (if any)
Low
paramas a required string now getsnull, as OpenAI itself sendsinternal_error,bad_requestandbad_request_errorstay on spend, the file cap andmetadata, since callers may branch on theminvalid_request_error, and the SDK still retries it by status/key/infohave only unit tests, no live caseFinal Attestation
/live-pr-risk report
Verdict: nothing breaks at 7c75bc7, and 8ce7767 changes only a test, so the pass holds at the tip. Base
cbf4e40d38and the PR ran side by side with 2 uvicorn workers each, separate Postgres, real OpenAI upstreams, and a forwarding recorder in front of OpenAI on both legs. The cases, the hook, and every output are the00_lpr_andlpr_files in the gistBreaking
None at 7c75bc7. At ed2c5c0 a pre-call hook's
HTTPException(403)came backauth_erroron completions, moderations, and transcription, while chat answerspermission_error. 7c75bc7 types it by its status, andlpr_r06showspermission_erroron all four routes. Key spend shows up on/key/info3 to 17 seconds after a request on base, the PR, and the merged tree alike, so the onelpr_r11line that differed is timingBackward incompatible
paramis JSONnullandtypeis a named string where both were the string"None", on every route in the table above. mateo-berri asked for this change in the tracking ticketlpr_r10) and the Python SDK once instead of 3 times. Pinned by f764bd9 and approved by mateo-berri as this PR's intended change, in its summaryinvalid_request_errorwheretypewas null (lpr_r01,lpr_r04,lpr_r05). The 408 keeps main's type (f764bd9), and the SDK still retries it by statusRegression risk
The assistants stream, the RAG stream, team callback, login, model metrics, and
/key/infoerrors have unit tests only. The two streams build their error through the same helper the completions route uses, which the live cases cover, and the others only swap the string"None"fornullDependency graph
/v1/completionserrors/v1/moderationserrors/v1/audio/transcriptionserrors/v1/audio/speech/key/infoMerge-ref check
8ce7767 merged with main
4ce724e3dfanswered like the PR on every case it re-ran, thelpr_*.mergefiles. The only difference is per-worker state the PR shows too, the missing-upstream group cooling down after a 404 (lpr_r01,lpr_r03). Main's router refactor (#48847) renamed the router lookups in the transcription route, so 8ce7767 moves the file-cap unit test onto a real router, and the PR's unit tests and theNoneguard pass on that merge. An earlier merge with mainb25ea48c4balso showed a pre-existing gap, already filed with engineeringIntegration suites
These run only on CircleCI, so they ran here from clean trees with 2 integration workers. The accounting, OTEL and Presidio, security, and assistants wire files passed at ed2c5c0. At 7c75bc7 the team and prefix tag-routing files passed 83 of 83, and the assistants chaos file passed when run alone on base and tip. The JWT key-mapping and health-readiness files failed at the tip only on pytest's 180 second timeout while their proxy booted, at a load of 27 to 43 on 8 cores, and they passed on base at a lower load. Importing the proxy server took 34 seconds on both trees run side by side, so the slow boot comes from the machine's load and not from this PR
Not verified
Bugbot summary