Skip to content

fix(proxy): stop key creation with per-model limits in an organization from returning 500 - #53447

Merged
mateo-berri merged 1 commit into
mainfrom
litellm_flakeheal_20261121_test_check_org_key_limits_model_specific
Nov 21, 2026
Merged

mateo-berri merged 1 commit into
mainfrom
litellm_flakeheal_20261121_test_check_org_key_limits_model_specific

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

Creating a key inside an organization with per-model rate limits has been failing with a 500 error instead of creating the key or saying the organization limit is exceeded. This makes the organization limit check read those limits from where key creation has already moved them, so the request succeeds or returns the proper 400 again

Details

Link to Devin session: https://app.devin.ai/sessions/3fae0adaf7dd4860a54336dede4a6de5
Open in Devin Desktop: https://app.devin.ai/desktop/session/3fae0adaf7dd4860a54336dede4a6de5?variant=devin
Requested by: @mateo-berri

TLDR

Problem this solves:

How it solves it:

CI evidence

  • Failed 8 times in the last 24h of scheduled integration runs on main, newest Job (integration management)
  • Failure: 'GenerateKeyRequest' object has no attribute 'model_rpm_limit' returned as a 500 from POST /key/generate
  • Mechanism: key generation moves model_rpm_limit and model_tpm_limit into metadata and deletes the attributes from the request object before the organization check runs. refactor(typing): clear 1146 basedpyright Any errors across 365 files #52768 changed _check_key_model_specific_limits from getattr(data, ..., None) to data.model_rpm_limit, which raises once the attribute is gone
  • Fix: read both attributes with attribute_or_none, so the existing metadata fallback applies

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally
  • My PR passes all required CI/CD checks
  • 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

Screenshots / Proof of Fix

At 3570ed154b16256fa4cbcdec05a1f9624d511468

  1. Integration, local rig (real proxy, Postgres, Redis, 2 isolated workers) via tests/integration/run.py management tests/integration/management/test_key_budget_limits.py::test_check_org_key_limits_model_specific: origin/main product code 4 failed with the 500 above, with the fix 4 passed
  2. New unit test test_check_org_key_model_specific_limits_reads_limits_already_moved_into_metadata (rpm and tpm), -n 0 --reruns 0: 2 failed on origin/main product code with the same AttributeError, 2 passed with the fix, five runs
  3. Whole tests/unit/proxy/management_endpoints/test_key_management_endpoints.py: 1010 passed
  4. ruff check and ruff format --check on the product file, test_quality_gate.py --base origin/main: passed. basedpyright on the product file: 466 errors before and after

Not proven in CI before merge: a workflow_dispatch of the integration workflow on this branch (run) was rejected by the integration-license environment's branch rules before any step ran, so the integration proof above is local only and the next scheduled main run after merge is the first CI run of it

Type

🐛 Bug Fix

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

@veria-ai

veria-ai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

@mateo-berri
mateo-berri enabled auto-merge (squash) November 21, 2026 21:56
Key generation moves model_rpm_limit and model_tpm_limit into metadata and deletes
the request attributes before the organization limit check runs, so reading them
directly raised AttributeError and /key/generate returned 500

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
devin-ai-integration Bot force-pushed the litellm_flakeheal_20261121_test_check_org_key_limits_model_specific branch from 3570ed1 to 0e3b2d2 Compare November 21, 2026 21:59
@mateo-berri
mateo-berri merged commit bec8b46 into main Nov 21, 2026
48 checks passed
@mateo-berri
mateo-berri deleted the litellm_flakeheal_20261121_test_check_org_key_limits_model_specific branch November 21, 2026 22:06
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.

1 participant