Repository navigation
fix(proxy): validate model credential name only when it changes - #42701
Merged
Merged
Conversation
PATCH /model/{id}/update rejected read-modify-write edits that resent an unchanged but dangling litellm_credential_name. Existence validation now runs only when the requested name differs from the stored one; empty string and non-admin detach rejections are unchanged
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Contributor
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
yuneng-berri
approved these changes
Sep 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TLDR
Problem this solves:
How it solves it:
User Flow
Before: an admin wants to raise a model's rpm from an API client that reads the model, edits one field, and sends the whole object back, but the update is refused because of a field they never touched
"rpm": 5and"litellm_credential_name": "dangling-demo-6f227715", a credential that was deleted earlier{"litellm_params": {"litellm_credential_name": "dangling-demo-6f227715", "rpm": 7}}Credential 'dangling-demo-6f227715' not found. Create it via /credentials before attaching it to a model.and rpm stays at 5After: the same edit goes through, and the credential checks that #42291 added still fire on a real change
"rpm": 5and the same dangling credential name"rpm": 7"rpm": 7with the credential name still attached"litellm_credential_name": "does-not-exist-475415cd"still returns HTTP 400 not found, and""still returns HTTP 400 empty string"litellm_credential_name": nullstill gets HTTP 403Relevant issues
Follow-up to #42291
Affected release
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<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@greptileaito re-request a review after pushing changes)Screenshots / Proof of Fix
Shared setup: the tests/integration rig (real proxy on 127.0.0.1:4000 with Postgres and Redis,
STORE_MODEL_IN_DB=True, master keysk-integration-master). Each run creates a credential, creates a model that uses it, then deletes the credential so the model holds a dangling nameBefore (40ec84c)
curl -s -X POST http://127.0.0.1:4000/credentials -H 'Authorization: Bearer sk-integration-master' -H 'Content-Type: application/json' -d '{"credential_name":"dangling-demo-6f227715","credential_values":{"api_key":"sk-demo"},"credential_info":{}}'-> HTTP 200curl -s -X POST http://127.0.0.1:4000/model/new ... -d '{"model_name":"demo-55c4639d","litellm_params":{"model":"openai/gpt-4o-mini","api_base":"http://127.0.0.1:8190/v1","litellm_credential_name":"dangling-demo-6f227715","rpm":5},"model_info":{}}'-> HTTP 200, idaf3b1260-1cb6-45bb-8c24-1c87e07bd6bacurl -s -X DELETE http://127.0.0.1:4000/credentials/dangling-demo-6f227715 -H 'Authorization: Bearer sk-integration-master'-> HTTP 200curl -s 'http://127.0.0.1:4000/model/info?litellm_model_id=af3b1260-1cb6-45bb-8c24-1c87e07bd6ba' -H 'Authorization: Bearer sk-integration-master'->"litellm_params":{"api_base":"http://127.0.0.1:8190/v1","rpm":5,"litellm_credential_name":"dangling-demo-6f227715",...}curl -s -i -X PATCH http://127.0.0.1:4000/model/af3b1260-1cb6-45bb-8c24-1c87e07bd6ba/update -H 'Authorization: Bearer sk-integration-master' -H 'Content-Type: application/json' -d '{"litellm_params":{"litellm_credential_name":"dangling-demo-6f227715","rpm":7}}'After (648f475)
curl -s -X POST http://127.0.0.1:4000/credentials ... -d '{"credential_name":"dangling-demo-191012fe","credential_values":{"api_key":"sk-demo"},"credential_info":{}}'-> HTTP 200curl -s -X POST http://127.0.0.1:4000/model/new ... -d '{"model_name":"demo-6e5ab0d5","litellm_params":{"model":"openai/gpt-4o-mini","api_base":"http://127.0.0.1:8190/v1","litellm_credential_name":"dangling-demo-191012fe","rpm":5},"model_info":{}}'-> HTTP 200, id704037ef-108c-4daa-b9ea-76b88a1884e0curl -s -X DELETE http://127.0.0.1:4000/credentials/dangling-demo-191012fe -H 'Authorization: Bearer sk-integration-master'-> HTTP 200curl -s 'http://127.0.0.1:4000/model/info?litellm_model_id=704037ef-108c-4daa-b9ea-76b88a1884e0' -H 'Authorization: Bearer sk-integration-master'->"litellm_params":{"api_base":"http://127.0.0.1:8190/v1","rpm":5,"litellm_credential_name":"dangling-demo-191012fe",...}curl -s -i -X PATCH http://127.0.0.1:4000/model/704037ef-108c-4daa-b9ea-76b88a1884e0/update -H 'Authorization: Bearer sk-integration-master' -H 'Content-Type: application/json' -d '{"litellm_params":{"litellm_credential_name":"dangling-demo-191012fe","rpm":7}}'curl -s 'http://127.0.0.1:4000/model/info?litellm_model_id=704037ef-108c-4daa-b9ea-76b88a1884e0' -H 'Authorization: Bearer sk-integration-master'->"litellm_params":{"api_base":"http://127.0.0.1:8190/v1","rpm":7,"litellm_credential_name":"dangling-demo-191012fe",...}curl -s -i -X PATCH .../model/704037ef-108c-4daa-b9ea-76b88a1884e0/update ... -d '{"litellm_params":{"litellm_credential_name":"does-not-exist-475415cd"}}'curl -s -i -X PATCH .../model/704037ef-108c-4daa-b9ea-76b88a1884e0/update ... -d '{"litellm_params":{"litellm_credential_name":""}}'Regression test red on unfixed main (40ec84c)
tests/integration/management/test_model_credential_name_updates.pyagainst the same rig, before the fix. The two preservation nodes pass on main as expected, the read-modify-write node fails on its assertionMutation proof
Deleted the two-line early return in
_raise_on_invalid_credential_name, restarted the proxy, and rantest_unrelated_patch_succeeds_when_resent_credential_name_is_danglingRestored the lines, restarted, same node:
1 passed in 0.29s. Full file at the fixed tip:3 passed in 0.94s. Mapped unit filetests/test_litellm/proxy/management_endpoints/test_model_management_endpoints.py:318 passedType
🐛 Bug Fix
Caveats (if any)
Low
Final Attestation
Link to Devin session: https://app.devin.ai/sessions/f5459494023c45dfbab2637ad6119a5b
Open in Devin Desktop: https://app.devin.ai/desktop/session/f5459494023c45dfbab2637ad6119a5b?variant=devin