Skip to content

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

Merged
mateo-berri merged 12 commits into
mainfrom
litellm_openai_error_payload_proxy_server_auth_health
Oct 30, 2026
Merged

mateo-berri merged 12 commits into
mainfrom
litellm_openai_error_payload_proxy_server_auth_health

Conversation

@mateo-berri

@mateo-berri mateo-berri commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Many gateway errors outside the LLM endpoints send type and param as the string None, which OpenAI-style handlers can't classify

This 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:

  • Many proxy routes answer "type": "None"
  • A missing param goes out as the string "None", not null

How it solves it:

Intentional product change: param is JSON null, and rejected transcriptions and proxy-ended streams keep their status, not 500

User Flow

Before: an OpenAI-style handler can't classify these errors

  1. They send POST https://litellm-domain/v1/chat/completions with no Authorization header
  2. HTTP 401 comes back with "param":"None" where their handler expects null
  3. They send POST https://litellm-domain/spend/calculate with an empty JSON body
  4. HTTP 400 comes back with "type":"None", so their invalid_request_error branch never fires

After: the same requests come back typed

  1. They send POST https://litellm-domain/v1/chat/completions with no Authorization header
  2. HTTP 401 comes back with "type":"auth_error","param":null
  3. They send POST https://litellm-domain/spend/calculate with an empty JSON body
  4. HTTP 400 comes back with "type":"invalid_request_error","param":null

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

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

Case Before After
Spend calculate, unknown model "None", "None" invalid_request_error, null
Stream fails mid-answer "None", "None" internal_server_error, null
Stream hits a 429 limit mid-answer frame code 500 frame code 429
Auth rejections, 7 kinds auth_error, "None" auth_error, null
Spend, key health, JWKS, database "None" param null param
Transcription, over cap or bad metadata 500, SDK sends 3 400, SDK sends 1
Completions, tag-routing denial "None", "None" auth_error, null
Hook's 403 off chat "None", "None" permission_error, null
Controls, real spend 200 200
15 other cases unchanged unchanged

Cells are the body's type and param, or status and SDK request count. The gist holds every case, with the string None on 34 base lines and none at the tip

Shared setup

Both legs boot the same config with 2 uvicorn workers, each against its own Postgres container, and differ only in the commit. cbf4e40d38 is this PR's merge base with main and ed2c5c0bdc is 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 points JWT_PUBLIC_KEY_URL at 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 to max_file_size_mb: 1, and the tag-routing case turns on enable_tag_filtering and sends the tag free to a model whose only deployment is tagged paid. The config, the callback, and the leg scripts are the 00_ files in the gist

.venv/bin/python litellm/proxy/proxy_cli.py --config config.yaml --host 127.0.0.1 --port <port> --num_workers 2 --timeout_worker_healthcheck 120 --use_prisma_db_push

Before (cbf4e40)

Spend calculate with an empty body

  1. Run the request
curl -sS -i -X POST "$PROXY_BASE_URL/spend/calculate" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d "{}"
  1. Observe type and param as the string None
HTTP/1.1 400 Bad Request
{"error":{"message":"Bad Request - Either 'model' or 'completion_response' must be provided","type":"None","param":"None","code":"400"}}

Transcription with an unknown model

Steps and output
  1. Call client.audio.transcriptions.create(model="no-such-audio-model", file=f) with the OpenAI SDK
  2. Observe the caught openai.BadRequestError
e.status_code: 400
e.type: 'None'
e.param: 'None'
e.code: '400'

Completions with an unknown model

Steps and output
  1. Run 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}'
  2. Observe type and param as the string None
HTTP/1.1 400 Bad Request
{"error":{"message":"400: {'error': '/completions: Invalid model name passed in model=no-such-completion-model. Call `/v1/models` to view available models for your key.'}","type":"None","param":"None","code":"400"}}

Auth rejections

Steps and output
  1. Send /v1/chat/completions with no Authorization header, then with Authorization: sk-no-bearer-prefix
  2. Block a key with POST /key/block, then call chat through the OpenAI SDK with it, and again with a key whose user SCIM deactivated
  3. Call POST /global/spend/reset with a virtual key, POST /model/new and POST /budget/new with an internal_user key
  4. Observe param as the string None on all seven
{"error":{"message":"Authentication Error, No api key passed in.","type":"auth_error","param":"None","code":"401"}}
{"error":{"message":"Authentication Error, Malformed API Key passed in. Ensure Key has `Bearer ` prefix.","type":"auth_error","param":"None","code":"401"}}
blocked key:          e.type: 'auth_error'  e.param: 'None'
SCIM deactivated:     e.type: 'auth_error'  e.param: 'None'
{"error":{"message":"Authentication Error, Tried to access route=/global/spend/reset, which is only for MASTER KEY","type":"auth_error","param":"None","code":"401"}}
HTTP/1.1 403 Forbidden  /model/new  "type":"auth_error","param":"None"
HTTP/1.1 401 Unauthorized  /budget/new  "type":"auth_error","param":"None"

Spend logs and tags with bad input

Steps and output
  1. Run 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=10 with no dates
  2. Observe param as the string None on all three
HTTP/1.1 500 Internal Server Error
{"error":{"message":"/spend/logs Errortime data 'not-a-date' does not match format '%Y-%m-%d'","type":"internal_error","param":"None","code":"500"}}
HTTP/1.1 400 Bad Request
{"error":{"message":"{'error': \"start_date must be a YYYY-MM-DD date, got 'not-a-date'\"}","type":"internal_error","param":"None","code":"400"}}
HTTP/1.1 400 Bad Request
{"error":{"message":"Start date and end date are required","type":"bad_request","param":"None","code":"400"}}

Key health with a malformed logging entry

Steps and output
  1. Run 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"]}}'
  2. Run curl -sS -i -X POST "$PROXY_BASE_URL/key/health" -H "Authorization: Bearer $GENERATED_KEY" with the key it returned
  3. Observe a 500 whose param is the string None
HTTP/1.1 500 Internal Server Error
{"error":{"message":"Key health check failed: 'str' object has no attribute 'get'","type":"internal_server_error","param":"None","code":"500"}}

Stream that fails mid-answer

Steps and output
  1. Stream midstream-gpt-5.4-mini with the OpenAI SDK through the proxy whose streaming callback raises after two chunks
  2. Observe two real chunks, then an openai.APIError whose type and param are the string None
chunk delta: ''
chunk delta: '1'
exception class: openai.APIError
e.type: 'None'
e.param: 'None'
e.body: {"message": "audit hook could not reach its sink", "type": "None", "param": "None", "code": "500"}

Stream that hits a 429 limit mid-answer

Steps and output
  1. Stream midstream-limit-gpt-5.4-mini with the OpenAI SDK through the proxy whose streaming callback raises a 429 budget error after two chunks
  2. Observe two real chunks, then an openai.APIError whose code is 500
chunk delta: ''
chunk delta: '1'
exception class: openai.APIError
e.type: 'budget_exceeded'
e.param: None
e.code: '500'
e.body: {"message": "Budget has been exceeded mid-stream. Max budget: 0.0001", "type": "budget_exceeded", "param": null, "code": "500"}
  1. Run curl -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"}]}'
  2. Observe the same error frame on the wire after the two chunks, then [DONE]
data: {"error": {"message": "Budget has been exceeded mid-stream. Max budget: 0.0001", "type": "budget_exceeded", "param": null, "code": "500"}}
data: [DONE]

JWKS endpoint unreachable

Steps and output
  1. Mint an RS256 JWT locally and send it as the bearer token to /v1/chat/completions
  2. Observe a 503 whose param is the string None
HTTP/1.1 503 Service Unavailable
{"error":{"message":"Service Unavailable, the identity provider's JWKS endpoint is temporarily unreachable, so the JWT signature could not be verified. Please retry shortly. Error: ConnectError fetching http://127.0.0.1:9/keys after 3 attempts","type":"auth_provider_unavailable","param":"None","code":"503"}}

Database down

Steps and output
  1. Pause the leg's Postgres container with docker pause, then call GET /team/list with the master key
  2. Observe a 503 whose param is the string None
HTTP/1.1 503 Service Unavailable
{"error":{"message":"Service Unavailable, the authentication database is temporarily unreachable. Please retry shortly.","type":"no_db_connection","param":"None","code":"503"}}

Transcription file over the size cap

Steps and output
  1. Call 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 sends
  2. Observe a 500, so the SDK retries the same upload twice
exception class: openai.InternalServerError
e.status_code: 500
e.type: 'bad_request'
e.param: 'file'
requests sent: 3
  1. Run curl -sS -i "$PROXY_BASE_URL/v1/audio/transcriptions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -F model=transcribe-capped -F file=@two_mb.wav
  2. Observe the same status on the wire
HTTP/1.1 500 Internal Server Error
{"error":{"message":"File size is too large. Please check your file size. Passed file size: 2.136272430419922 MB. Max file size: 1.0 MB","type":"bad_request","param":"file","code":"500"}}

Transcription with a bad metadata field

Steps and output
  1. Call 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 sends
  2. Observe a 500, so the SDK retries the same upload twice
exception class: openai.InternalServerError
e.status_code: 500
e.type: 'bad_request_error'
e.param: 'metadata'
requests sent: 3
  1. Run curl -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.wav
  2. Observe the same status on the wire
HTTP/1.1 500 Internal Server Error
{"error":{"message":"Invalid type for 'metadata': expected an object, but got a string instead.","type":"bad_request_error","param":"metadata","code":"500"}}

Tag-routing denial on completions

Steps and output
  1. Call client.completions.create(model="gpt-5.4-mini-paid-tier", prompt="hello", max_tokens=5, extra_body={"metadata": {"tags": ["free"]}}) with the OpenAI SDK
  2. Observe a 401 whose type and param are the string None
exception class: openai.AuthenticationError
e.status_code: 401
e.type: 'None'
e.param: 'None'
  1. Run curl -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 tagged paid as a control
  2. Observe the same body on the wire, internal_server_error on chat completions, and a 200 for the control
HTTP/1.1 401 Unauthorized
{"error":{"message":"Not allowed to access model due to tags configuration. Passed model=gpt-5.4-mini-paid-tier and tags=['free']","type":"None","param":"None","code":"401"}}
HTTP/1.1 401 Unauthorized
{"error":{"message":"Not allowed to access model due to tags configuration. Passed model=gpt-5.4-mini-paid-tier and tags=['free']","type":"internal_server_error","param":null,"code":"401"}}
HTTP 200

A hook's 403 off chat

Steps and output
  1. Boot with a pre-call hook that raises HTTPException(403) for every policy-block-* model, the gist's 00_lpr_hooks.py and 00_lpr_config.yaml
  2. Send the blocked model to /v1/chat/completions, /v1/completions, /v1/moderations, and /v1/audio/transcriptions in that order, the completions request being curl -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's lpr_r06_policy_block_403 files
  3. Observe type and param as the string None off chat, while chat answers permission_error
{"error":{"message":"Blocked by the content policy","type":"permission_error","param":null,"code":"403","provider_specific_fields":{"error":"Blocked by the content policy"}}}
status=403
{"error":{"message":"403: {'error': 'Blocked by the content policy'}","type":"None","param":"None","code":"403"}}
status=403
{"error":{"message":"403: {'error': 'Blocked by the content policy'}","type":"None","param":"None","code":"403"}}
status=403
{"error":{"message":"{'error': 'Blocked by the content policy'}","type":"None","param":"None","code":"403"}}
status=403

Controls with real spend

Steps and output
  1. Run chat, streamed chat, moderation, speech, and transcription through the OpenAI SDK against real OpenAI models
  2. Observe every call succeed
chat non-stream: gpt-5.4-mini 'pong' 15 tokens
chat stream: '1, 2, 3, 4, 5' 29 tokens
moderation: omni-moderation-latest flagged = False
speech: 55296 bytes of audio
transcription: 'The quick brown fox jumps over the lazy dog.'

After (ed2c5c0)

Spend calculate with an empty body

  1. Run the request
curl -sS -i -X POST "$PROXY_BASE_URL/spend/calculate" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d "{}"
  1. Observe a named type and a JSON null param
HTTP/1.1 400 Bad Request
{"error":{"message":"Bad Request - Either 'model' or 'completion_response' must be provided","type":"invalid_request_error","param":null,"code":"400"}}

Transcription with an unknown model

Steps and output
  1. Call client.audio.transcriptions.create(model="no-such-audio-model", file=f) with the OpenAI SDK
  2. Observe the caught openai.BadRequestError
e.status_code: 400
e.type: 'invalid_request_error'
e.param: None
e.code: '400'

Completions with an unknown model

Steps and output
  1. Run 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}'
  2. Observe a named type and a JSON null param
HTTP/1.1 400 Bad Request
{"error":{"message":"400: {'error': '/completions: Invalid model name passed in model=no-such-completion-model. Call `/v1/models` to view available models for your key.'}","type":"invalid_request_error","param":null,"code":"400"}}

Auth rejections

Steps and output
  1. Send /v1/chat/completions with no Authorization header, then with Authorization: sk-no-bearer-prefix
  2. Block a key with POST /key/block, then call chat through the OpenAI SDK with it, and again with a key whose user SCIM deactivated
  3. Call POST /global/spend/reset with a virtual key, POST /model/new and POST /budget/new with an internal_user key
  4. Observe a JSON null param on all seven
{"error":{"message":"Authentication Error, No api key passed in.","type":"auth_error","param":null,"code":"401"}}
{"error":{"message":"Authentication Error, Malformed API Key passed in. Ensure Key has `Bearer ` prefix.","type":"auth_error","param":null,"code":"401"}}
blocked key:          e.type: 'auth_error'  e.param: None
SCIM deactivated:     e.type: 'auth_error'  e.param: None
{"error":{"message":"Authentication Error, Tried to access route=/global/spend/reset, which is only for MASTER KEY","type":"auth_error","param":null,"code":"401"}}
HTTP/1.1 403 Forbidden  /model/new  "type":"auth_error","param":null
HTTP/1.1 401 Unauthorized  /budget/new  "type":"auth_error","param":null

Spend logs and tags with bad input

Steps and output
  1. Run 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=10 with no dates
  2. Observe a JSON null param on all three
HTTP/1.1 500 Internal Server Error
{"error":{"message":"/spend/logs Errortime data 'not-a-date' does not match format '%Y-%m-%d'","type":"internal_error","param":null,"code":"500"}}
HTTP/1.1 400 Bad Request
{"error":{"message":"{'error': \"start_date must be a YYYY-MM-DD date, got 'not-a-date'\"}","type":"internal_error","param":null,"code":"400"}}
HTTP/1.1 400 Bad Request
{"error":{"message":"Start date and end date are required","type":"bad_request","param":null,"code":"400"}}

Key health with a malformed logging entry

Steps and output
  1. Run 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"]}}'
  2. Run curl -sS -i -X POST "$PROXY_BASE_URL/key/health" -H "Authorization: Bearer $GENERATED_KEY" with the key it returned
  3. Observe a 500 with a JSON null param
HTTP/1.1 500 Internal Server Error
{"error":{"message":"Key health check failed: 'str' object has no attribute 'get'","type":"internal_server_error","param":null,"code":"500"}}

Stream that fails mid-answer

Steps and output
  1. Stream midstream-gpt-5.4-mini with the OpenAI SDK through the proxy whose streaming callback raises after two chunks
  2. Observe two real chunks, then an openai.APIError with a named type and a null param
chunk delta: ''
chunk delta: '1'
exception class: openai.APIError
e.type: 'internal_server_error'
e.param: None
e.body: {"message": "audit hook could not reach its sink", "type": "internal_server_error", "param": null, "code": "500"}

Stream that hits a 429 limit mid-answer

Steps and output
  1. Stream midstream-limit-gpt-5.4-mini with the OpenAI SDK through the proxy whose streaming callback raises a 429 budget error after two chunks
  2. Observe two real chunks, then an openai.APIError whose code is 429
chunk delta: ''
chunk delta: '1'
exception class: openai.APIError
e.type: 'budget_exceeded'
e.param: None
e.code: '429'
e.body: {"message": "Budget has been exceeded mid-stream. Max budget: 0.0001", "type": "budget_exceeded", "param": null, "code": "429"}
  1. Run curl -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"}]}'
  2. Observe the same error frame on the wire after the two chunks, then [DONE]
data: {"error": {"message": "Budget has been exceeded mid-stream. Max budget: 0.0001", "type": "budget_exceeded", "param": null, "code": "429"}}
data: [DONE]

JWKS endpoint unreachable

Steps and output
  1. Mint an RS256 JWT locally and send it as the bearer token to /v1/chat/completions
  2. Observe a 503 with a JSON null param
HTTP/1.1 503 Service Unavailable
{"error":{"message":"Service Unavailable, the identity provider's JWKS endpoint is temporarily unreachable, so the JWT signature could not be verified. Please retry shortly. Error: ConnectError fetching http://127.0.0.1:9/keys after 3 attempts","type":"auth_provider_unavailable","param":null,"code":"503"}}

Database down

Steps and output
  1. Pause the leg's Postgres container with docker pause, then call GET /team/list with the master key
  2. Observe a 503 with a JSON null param
HTTP/1.1 503 Service Unavailable
{"error":{"message":"Service Unavailable, the authentication database is temporarily unreachable. Please retry shortly.","type":"no_db_connection","param":null,"code":"503"}}

Transcription file over the size cap

Steps and output
  1. Call 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 sends
  2. Observe the proxy's own 400, so the SDK sends the upload once
exception class: openai.BadRequestError
e.status_code: 400
e.type: 'bad_request'
e.param: 'file'
requests sent: 1
  1. Run curl -sS -i "$PROXY_BASE_URL/v1/audio/transcriptions" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -F model=transcribe-capped -F file=@two_mb.wav
  2. Observe the same status on the wire
HTTP/1.1 400 Bad Request
{"error":{"message":"File size is too large. Please check your file size. Passed file size: 2.136272430419922 MB. Max file size: 1.0 MB","type":"bad_request","param":"file","code":"400"}}

Transcription with a bad metadata field

Steps and output
  1. Call 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 sends
  2. Observe a 400, so the SDK sends the upload once
exception class: openai.BadRequestError
e.status_code: 400
e.type: 'bad_request_error'
e.param: 'metadata'
requests sent: 1
  1. Run curl -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.wav
  2. Observe the same status on the wire
HTTP/1.1 400 Bad Request
{"error":{"message":"Invalid type for 'metadata': expected an object, but got a string instead.","type":"bad_request_error","param":"metadata","code":"400"}}

Tag-routing denial on completions

Steps and output
  1. Call client.completions.create(model="gpt-5.4-mini-paid-tier", prompt="hello", max_tokens=5, extra_body={"metadata": {"tags": ["free"]}}) with the OpenAI SDK
  2. Observe a 401 typed auth_error, as main's other routes type a proxy denial, with a JSON null param
exception class: openai.AuthenticationError
e.status_code: 401
e.type: 'auth_error'
e.param: None
  1. Run curl -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 tagged paid as a control
  2. Observe the same body on the wire, chat completions unchanged from base, and a 200 for the control
HTTP/1.1 401 Unauthorized
{"error":{"message":"Not allowed to access model due to tags configuration. Passed model=gpt-5.4-mini-paid-tier and tags=['free']","type":"auth_error","param":null,"code":"401"}}
HTTP/1.1 401 Unauthorized
{"error":{"message":"Not allowed to access model due to tags configuration. Passed model=gpt-5.4-mini-paid-tier and tags=['free']","type":"internal_server_error","param":null,"code":"401"}}
HTTP 200

A hook's 403 off chat, at 7c75bc7

Steps and output
  1. Boot with a pre-call hook that raises HTTPException(403) for every policy-block-* model, the gist's 00_lpr_hooks.py and 00_lpr_config.yaml
  2. Send the blocked model to /v1/chat/completions, /v1/completions, /v1/moderations, and /v1/audio/transcriptions in that order, the completions request being curl -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's lpr_r06_policy_block_403 files
  3. Observe permission_error and a JSON null param on all four routes
{"error":{"message":"Blocked by the content policy","type":"permission_error","param":null,"code":"403","provider_specific_fields":{"error":"Blocked by the content policy"}}}
status=403
{"error":{"message":"403: {'error': 'Blocked by the content policy'}","type":"permission_error","param":null,"code":"403"}}
status=403
{"error":{"message":"403: {'error': 'Blocked by the content policy'}","type":"permission_error","param":null,"code":"403"}}
status=403
{"error":{"message":"{'error': 'Blocked by the content policy'}","type":"permission_error","param":null,"code":"403"}}
status=403

Controls with real spend

Steps and output
  1. Run chat, streamed chat, moderation, speech, and transcription through the OpenAI SDK against real OpenAI models
  2. Observe every call succeed
chat non-stream: gpt-5.4-mini 'pong' 15 tokens
chat stream: '1, 2, 3, 4, 5' 29 tokens
moderation: omni-moderation-latest flagged = False
speech: 62592 bytes of audio
transcription: 'The quick brown fox jumps over the lazy dog.'
Observations, all on main already and left alone
  • /key/health answers 500 on a malformed logging entry
  • Speech, org info, and team callback errors use FastAPI's detail shape
  • /global/spend/tags puts a server traceback in its message
  • /user/info types a 404 as internal_server_error
  • /v1/chat/completions types a tag denial internal_server_error

Type

🐛 Bug Fix

Caveats (if any)

Low

  • A client that types param as a required string now gets null, as OpenAI itself sends
  • internal_error, bad_request and bad_request_error stay on spend, the file cap and metadata, since callers may branch on them
  • A timeout's 408 is typed invalid_request_error, and the SDK still retries it by status
  • Team callback, login, model metrics, assistants stream and /key/info have only unit tests, no live case

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
/live-pr-risk report

Verdict: nothing breaks at 7c75bc7, and 8ce7767 changes only a test, so the pass holds at the tip. Base cbf4e40d38 and 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 the 00_lpr_ and lpr_ files in the gist

Breaking

None at 7c75bc7. At ed2c5c0 a pre-call hook's HTTPException(403) came back auth_error on completions, moderations, and transcription, while chat answers permission_error. 7c75bc7 types it by its status, and lpr_r06 shows permission_error on all four routes. Key spend shows up on /key/info 3 to 17 seconds after a request on base, the PR, and the merged tree alike, so the one lpr_r11 line that differed is timing

Backward incompatible

  • param is JSON null and type is 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 ticket
  • A transcription the proxy rejects answers its own 400 instead of 500 (32074cf), so the dashboard's openai-node client sends the upload 2 times instead of 4 (lpr_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 summary
  • A stream a proxy check ends mid-answer carries that check's status in its error frame, such as 429 instead of 500 (32074cf). Approved by mateo-berri as this PR's intended change, in its summary
  • An upstream 404, 400, or timeout on completions is typed invalid_request_error where type was null (lpr_r01, lpr_r04, lpr_r05). The 408 keeps main's type (f764bd9), and the SDK still retries it by status

Regression risk

The assistants stream, the RAG stream, team callback, login, model metrics, and /key/info errors 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" for null

Dependency graph

Dependent Status
/v1/completions errors verified live
/v1/moderations errors verified live
/v1/audio/transcriptions errors verified live
Hook 403 on /v1/audio/speech verified live, unchanged
Chat and Responses mid-stream frames verified live
Chat upstream 404 verified live, unchanged
LiteLLM SDK as a client verified live, unchanged
No-deployments 429 verified live, unchanged
Dashboard openai-node transcription verified live
Chat, stream, Messages, fallback, key spend verified live, unchanged
Assistants and RAG streams unit tests
Team callback, login, model metrics unit tests
/key/info unit tests
Integration suites see below

Merge-ref check

8ce7767 merged with main 4ce724e3df answered like the PR on every case it re-ran, the lpr_*.merge files. 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 the None guard pass on that merge. An earlier merge with main b25ea48c4b also showed a pre-existing gap, already filed with engineering

Integration 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

  • A live assistants stream or RAG stream failure, since the rig has no deployment for either
  • A click through the dashboard's transcription page, driven through its openai-node client instead
  • OTEL spans and gateway metric counts for these errors
Bugbot summary

[!NOTE]
Medium Risk
Touches error serialization on many proxy routes (auth, spend, streaming, audio), which is client-visible and marked breaking; logic is centralized but wide blast radius for SDKs and integrations that parsed the old strings.

Overview
Proxy error bodies no longer emit "type":"None" or "param":"None". Missing param is JSON null, and type is derived from status and exception kind via shared helpers (openai_error_param, openai_error_type, route_failure_proxy_exception).

Auth, spend, key health, team callbacks, and DB/JWKS paths replace hard-coded "None" and getattr(..., "None") with param=None or openai_error_param(e). Completions, embeddings, audio, moderations, and SSE mid-stream failures build responses through route_failure_proxy_exception so hook 403s map to permission_error, tag-routing denials to auth_error, and proxy checks mid-stream keep their real status (e.g. 429 not 500). Transcription rejections (file cap, bad metadata) answer 400 instead of 500.

CI adds an AST check check_no_none_string_error_fields (plus unit tests) so new "None" error fields fail lint. Integration and route tests expect param: null and the new typing behavior.

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

…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.
@greptile-apps

greptile-apps Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

This PR standardizes proxy error payloads so absent parameters serialize as JSON null, error types are derived consistently, and selected route failures retain their intended status codes.

  • Centralizes OpenAI-compatible error payload construction across proxy, authentication, spend, key-health, and streaming paths.
  • Preserves client-error statuses for proxy-rejected transcription requests and mid-stream failures.
  • Adds a CI check and updates unit and integration expectations to prevent literal "None" error fields.

Reviews (10) · Last reviewed commit: "test(proxy): build the transcription fil..." · Reviewed by Greptile

@codecov

codecov Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.73684% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/proxy/proxy_server.py 93.75% 1 Missing ⚠️
...proxy/spend_tracking/spend_management_endpoints.py 66.66% 1 Missing ⚠️

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

Copy link
Copy Markdown
Contributor Author

@greptileai

Base automatically changed from litellm_openai_error_payload_non_llm_routes to litellm_internal_staging September 8, 2026 23:41
@mateo-berri
mateo-berri requested a review from a team September 8, 2026 23:41
@yuneng-berri
yuneng-berri deleted the branch main September 13, 2026 04:48
@mateo-berri mateo-berri reopened this Sep 13, 2026
@mateo-berri
mateo-berri changed the base branch from litellm_internal_staging to main September 13, 2026 05:14
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.
@codspeed

codspeed Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 38 untouched benchmarks


Comparing litellm_openai_error_payload_proxy_server_auth_health (8ce7767) with main (fd8b89f)

Open in CodSpeed

@mateo-berri mateo-berri changed the title fix(proxy): stop answering with the literal string "None" on the proxy-server, auth, and health routes fix(proxy): stop answering with the literal string "None" as error type and param on the proxy-server, auth, health, spend, and management routes Oct 21, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

1 similar comment
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@litereview

litereview Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

⚠️ code-review

3/5 · Changes needed

Scope: full · Full PR review.

Completed · Some checks not run.

The integration suite still expects the old "param": "None" body in 13 files. Those tests should fail on main after merge. No other correctness findings.

Medium · Integration contracts still pin "param": "None" and will fail once this merges · tests/integration/spend/test_global_spend_reset.py:107

  1. test_global_spend_reset_zeroes_token_and_team_spend_but_keeps_logs sends POST /global/spend/reset with an internal-user key.
  2. user_api_key_auth raises Exception("Tried to access route=..., which is only for MASTER KEY").
  3. This PR changes _as_proxy_exception in auth_exception_handler.py to build the 401 body with param=openai_error_param(e), which returns None.
  4. The proxy now returns "param": null. The test asserts exact equality with "param": "None", so the test fails.

The same stale literal appears 18 times across 13 files under tests/integration/, covering auth rejections, the JWKS and DB 503 bodies, and team-not-found. Per tests/integration/AGENTS.md, CircleCI runs these groups on main, not on PRs, so the PR's green checks will not catch this. I traced this from the code and reproduced the new body at the function level. I did not run the integration suite itself.

Fix: change each "param": "None" expectation in tests/integration/ to "param": None.

Evidence

grep -rn '"param": "None"' tests/integration → 18 hits in 13 files, including authorization/test_user_self_update_guard.py:41,52,68, authorization/test_team_admin_gate.py:603,749, management/test_health_routing.py:154 (no_db_connection 503), management/test_team_delete_large_membership.py:252, management/test_user_delete_revokes_keys.py:67, observability/test_arize_otel_v2_openinference_sad_edge.py:180, observability/test_presidio_entity_masking.py:328, security/test_config_overrides.py:103,247,389, spend/test_global_spend_reset.py:107

Function-level reproduction at head:

$ python -c "from litellm.proxy.auth.auth_exception_handler import _as_proxy_exception; print(_as_proxy_exception(Exception('Tried to access route=/global/spend/reset, which is only for MASTER KEY')).to_dict())"
{'message': 'Authentication Error, Tried to access route=/global/spend/reset, which is only for MASTER KEY', 'type': <ProxyErrorTypes.auth_error: 'auth_error'>, 'param': None, 'code': '401'}

tests/integration/AGENTS.md: "CircleCI runs on main, not on pull requests"; tests/integration/run.py GROUPS includes authorization, management, spend, observability, security.

The test bodies contain no skip markers. test_global_spend_reset.py skips only test_reset_exhausted_key_is_served_again.

Checks and execution details
  • Passed · Real testing evidence (required): Not applicable: no LLM translation changes in the scoped paths. The PR changes only litellm/proxy/** and tests/unit/proxy/**, with nothing under litellm/llms/** or litellm/litellm_core_utils/prompt_templates/**.
  • Passed · Compatibility requirements (required): Before the change, proxy error bodies on auth, health, spend, management and some LLM routes sent type: "None" and/or param: "None". After the change, param is JSON null and a missing type becomes a status-derived OpenAI type. Status codes and messages stay the same, and constant types such as auth_error and no_db_connection are unchanged. The literal string "None" was a serialization defect, not a documented contract. The OpenAI error schema defines param as nullable, and no in-repo consumer (UI or proxy) branches on "None" (grep found none). I found no supported input, config, default or persisted data that breaks, so the PR needs no ! marker.
  • Passed · Changed behavior and result consistency (required): I read the root AGENTS.md, tests/AGENTS.md, tests/integration/AGENTS.md and README.md, and tests/integration/run.py. I traced openai_error_param, openai_error_type and error_status_code in common_utils/openai_error_payload.py through ProxyException.to_dict and into the auth handler (_as_proxy_exception), JWKS and DB 503 paths, the async_data_generator mid-stream frame, moderations, audio_transcriptions, completion and /spend/calculate. Boundary cases: an exception with no type/param falls back to the status-derived type and null. The string "None" is filtered to the fallback. ProxyException carries its status as a stringified code, and error_status_code parses it. The changed files have no leftover param="None" or getattr(..., "None") in error construction. Reconciliation: the stale integration expectations are reported as a finding.
  • Passed · Changed unit test files (optional): pytest -n 8 over the 9 changed test files plus tests/unit/proxy/common_utils/test_openai_error_payload.py returned 2944 passed. The first run had 2 failures from an ungenerated Prisma client. Both passed after prisma generate --schema litellm/proxy/schema.prisma.
  • Not run · Integration suite (CircleCI groups) (optional): I did not run it. The suite needs the full run_integration.sh stack: an owned proxy, Postgres, Redis and peers. The stale expectations are established from the code plus a function-level reproduction.

View review · Reviewed 17a86d7b2c1e

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

Copy link
Copy Markdown
Contributor Author

@greptileai

…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
@mateo-berri mateo-berri changed the title fix(proxy)!: stop answering with the literal string "None" as error type and param on the proxy-server, auth, health, spend, and management routes fix(proxy)!: stop answering with the literal string "None" as error type and param on the proxy-server, auth, spend, and key health routes Oct 29, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

…d ban the string None as an error type or param
@mateo-berri
mateo-berri requested a review from a team October 29, 2026 12:41
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

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.

Stale Bugbot comment from a previous 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.
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

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.

Stale Bugbot comment from a previous run.

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

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 8ce7767. Configure here.

@mateo-berri mateo-berri reopened this Oct 29, 2026
@mateo-berri mateo-berri reopened this Oct 30, 2026
@mateo-berri
mateo-berri merged commit 636e707 into main Oct 30, 2026
333 of 341 checks passed
@mateo-berri
mateo-berri deleted the litellm_openai_error_payload_proxy_server_auth_health branch October 30, 2026 01:20
yuneng-berri added a commit that referenced this pull request Oct 30, 2026
…ed changes (#49310)

Seven integration tests fail on main for reasons that are not product bugs. Two are order or race bugs in the tests, one reads rows other tests wrote, one passed on an error body, and three still expect behavior that #48644, #39864 and #39540 changed on purpose
devin-ai-integration Bot added a commit that referenced this pull request Nov 21, 2026
…aram_lts_1_108_x

test(auth): expect null error param for blocked keys (#39540) [lts/1.108.x]
mateo-berri pushed a commit to chaznm/litellm that referenced this pull request Nov 21, 2026
Apply the two integration test updates from 636e707 (BerriAI#39540). The LTS responses already use JSON null.
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.

3 participants