Repository navigation
refactor(typing): clear basedpyright Any errors across 35 files - #53599
Conversation
…20261121 # Conflicts: # litellm/proxy/hooks/model_max_budget_limiter.py # litellm/proxy/management_helpers/apps.py
…sts reloading proxy_server The SDK list, info and stream helpers return Mapping, Sequence and JsonValue shapes validated by pydantic instead of bare object. The cooldown test fixture no longer reloads litellm.proxy.proxy_server, which swapped the FastAPI app under test_proxy_server's dependency overrides when both files shared a worker.
[Medium impact] The PR appears safe to merge, with no actionable issues found.
|
…oxy client SDK as main has it
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…20261121 # Conflicts: # litellm/integrations/compression_interception/handler.py
|
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 e74b46f. Configure here.
Pass the provider-signed limit to the Rust row builder again after BerriAI#53599 spelled out its arguments, and record BerriAI#53405's two new golden rows with that config key
Handwritten 1-3 sentence description
This replaces loose Any types with real ones in 35 files so the type checker can catch bugs it could not see before. Nothing a user sends or gets back changes
Details
TLDR
Problem this solves:
How it solves it:
User Flow
Before: an admin's key lookup, a user's streamed chat and responses calls, router fallbacks and the metrics page all behave normally
POST https://litellm-domain/v2/key/infowith{"keys": ["sk-..."]}and the master key, and gets 200 with each key's owner, team and budget settings but no raw tokenPOST https://litellm-domain/v1/chat/completionswith"stream": trueand receivesdata:chunks ending indata: [DONE]POST https://litellm-domain/v1/responseswith"stream": trueand receives events throughresponse.completedPOST https://litellm-domain/v1/chat/completionsreturns 200 from the fallback deploymentGET https://litellm-domain/metricsand sees the usual Prometheus series with their labelsAfter: the same five steps return the same status codes, response bodies, stream events and metrics, since this PR only narrows type annotations
Pre-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
Before is the merge base a1df18d and after is c66f8a4, with the same result on every case. Commits 8d9afd4 and e74b46f, a merge with main, carry this proof, as the notes at the end explain.
Both legs ran on one GCE host. Each had two proxies, P and Q, with 2 workers each, sharing the leg's own Postgres and Redis, so state written through P is read back through Q. All provider calls are real (OpenAI
gpt-6.2-sol, Anthropicclaude-haiku-5-5, DashScopeqwen3-rerank).Proxy command, config, env vars and client
Each of the four proxies ran this, from its leg's checkout:
This is the QA rig's command, not the AGENTS.md one. It drops
--reloadand--detailed_debugso both workers serve, and pushes the schema once per leg before boot. Each proxy had 2 worker PIDs, and both trees were clean at the stated commit.Env var names:
OPENAI_API_KEY,ANTHROPIC_API_KEY,DASHSCOPE_API_KEY,DASHSCOPE_API_BASE,LITELLM_MASTER_KEY,LITELLM_SALT_KEY,DATABASE_URL,REDIS_HOST,REDIS_PORT,STORE_MODEL_IN_DB=True,LITELLM_LOCAL_MODEL_COST_MAP=True, andPROMETHEUS_MULTIPROC_DIRper process.The client is
cases.sh, run per leg withPandQset to the two proxies andMKto the master key. It prints every command from the same string it runs (printf '$ %s\n' "$cmd"; eval "$cmd"). Full raw output of both legs is in the gist./v2/key/info, 3 keys and 1 missing/v2/key/infoas key owner[DONE]/v1/responses, OpenAI and Anthropicpongadditional_drop_params/metricsseries and labels5ea32bc35ea32bc3/key/bulk_update/v2/model/infosortByjson.loadsHeadline case:
/v2/key/infoon a DB-backed proxyqa-user-key(userqa-user),qa-mmb(team key with amodel_max_budget) andqa-bl(withbudget_limits)qa-mmbandqa-blwith streaming callsPOST /v2/key/infofor all three keys plus a missing one, as admin, through Qqa-user-key, and for the missing key aloneOn both commits the admin call returns the three keys without a
tokenfield, withmodel_max_budget_usageandbudget_limits_usagefilled in, the owner sees only its own key, and the missing key returnsinfo: [].POST /v2/key/info output, before and after
Before (a1df18d)
After (c66f8a4)
Setup (team, internal user, three keys)
After (c66f8a4)
Before (a1df18d) printed the same lines, apart from response ids, timestamps, rerank scores and ciphertext. It is in the gist.
Team callbacks: POST, GET, disable_logging, DELETE, unknown team
After (c66f8a4)
Before (a1df18d) printed the same lines, apart from response ids, timestamps, rerank scores and ciphertext. It is in the gist.
Streaming /v1/chat/completions
After (c66f8a4)
Before (a1df18d) printed the same lines, apart from response ids, timestamps, rerank scores and ciphertext. It is in the gist.
Streaming /v1/responses
After (c66f8a4)
Before (a1df18d) printed the same lines, apart from response ids, timestamps, rerank scores and ciphertext. It is in the gist.
Fallback after cooldown, plus /metrics deployment counters
After (c66f8a4)
Before (a1df18d), counters only
GET /metrics series and label names
After (c66f8a4)
Before (a1df18d) printed the same lines, apart from response ids, timestamps, rerank scores and ciphertext. It is in the gist.
DashScope /v1/rerank
After (c66f8a4)
Before (a1df18d) printed the same lines, apart from response ids, timestamps, rerank scores and ciphertext. It is in the gist.
POST /key/bulk_update
After (c66f8a4)
Before (a1df18d) printed the same lines, apart from response ids, timestamps, rerank scores and ciphertext. It is in the gist.
/v2/model/info sortBy and /model/info pricing
After (c66f8a4)
Before (a1df18d) printed the same lines, apart from response ids, timestamps, rerank scores and ciphertext. It is in the gist.
litellm-proxy CLI and client SDK calls
After (c66f8a4)
Before (a1df18d), credentials lines only
Focused check: bundled cost map load
Before (a1df18d) and after (c66f8a4) printed the same
This is focused evidence, not e2e. The loader now parses with a pydantic
TypeAdapter. The proxy reads it only for the bundled model count and the Bedrock and Vertex Lyria fallbacks, which this run could not reach live, so this check stands in for them.The SageMaker, Vigil Guard, NLP Cloud and FIPS changes ran only in their unit suites (1334 passed at c66f8a4), since the rig has no setup for them.
Raw logs, the case script and the config are in this gist.
/live-pr-risk at e74b46f
Base a527f1a and head e74b46f ran on the GCE rig with recorders in front of OpenAI and Anthropic. The 40 cells matched on status, body shape, the request sent upstream and the spend row, apart from ids, nonces and timestamps. They covered nested drops and
previous_response_idturns on/v1/responses, the Anthropic bridge with streaming and tools, websocket responses, team callback add, get, disable and delete,/user/info, and a live Deep Agents run. The compression merge resolution sent the same[thinking, text, tool_use]follow-up on both. The management, observability and security integration lanes passed on head (455, 6 and 28 tests). In-process checks of the cost map load,_sort_models,budget_limit_windowsand Vigil Guard matched tooThe one difference is that
AgenticLoopRequestPatch(messages=...)now rejects an iterable that is not a sequence, like a generator, where base turned it into a list. Every producer in the repo passes a list. Code interpreter, Vigil Guard, NLP Cloud, headroom and compresr had no live keys, and the FIPS seal stops at the sameEVP_CIPHER_fetchcall on both, since the box has no FIPS providerScripts and outputs are the
5-lpr-e74b46f8-*files in the gistType counts
Measured by the type gate's whole-tree basedpyright run at 8d9afd4 against a1df18d, where no rule grew.
legacy_spend_log_rows.pystays as main has it, since it is code-ownedMerge with main and test notes
Merge with main. Merging main at a1df18d conflicted in the app budget helper, which keeps main's
app_budget_selectionrename, and the budget limiter, which keeps both import lines. The merge commit also restores an import git dropped from the router cooldown handlers and regenerates the stale OpenAPI snapshot and dashboardschema.d.tsCommit 8d9afd4. It returns the proxy client SDK and vector store types to main's code, gives two public fields read-only types, and copies websearch follow-up messages into plain dicts. Unit suites for those paths pass there (6866 passed), and a new test checks that a tuple of messages still reaches the follow-up call as a list.
Second merge with main. Commit e74b46f merges main at a527f1a. Only the compression interception handler conflicted. The merge keeps this PR's typed message dicts and adds the text blocks main now streams before the retrieval tool call, so the handler behaves as main does. Its unit tests pass at the merge, and
make checkand the code-quality scripts pass too.Timing differences. The fallback case prints the same totals on both legs. The counter lines come out in a different order and split across label sets, because a skipped deployment's failure gets a random
requested_modellabel on both commits. The CLI's firstcredentials listright aftercredentials createshowed[]on one leg per run (after in an earlier run, before in this one). 15 seconds later both legs listqa-cred, so this is a short delay before the other worker sees the new credential, on both commits.Tests. The cooldown test fixture reloaded
litellm.proxy.proxy_server, which broke 14 live-session tests that ran after it in the same process. It no longer reloads the proxy server, which those tests never useType
🧹 Refactoring
Caveats (if any)
Low
AgenticLoopRequestPatch.messagesand Responsesmetadatatake read-onlySequenceandMappingtypes instead ofAnymessagesnow fails validation where base made it a list. Every producer in the repo passes a listobject, likecheck_special_tokens(chunk)andbudget_limit_windows/v2/key/inforows validate up front, and helpers likeTypeAdapter(object)and NLP Cloud's open TypedDict splat only change a static typeFinal Attestation
Bugbot summary