fix(proxy/auth): handle tz-aware temp_budget_expiry - #33840
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Greptile SummaryThis PR fixes a
Confidence Score: 5/5Safe to merge — the change is small, targeted to the comparison in a single helper function, and the fix matches the documented format contract. The two-line change is correct: it normalises a tz-naive parsed expiry to UTC and compares against No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/proxy/auth/user_api_key_auth.py | Adds tz-normalization to _get_temp_budget_increase: naive stored expiry is coerced to UTC before comparison with datetime.now(timezone.utc), fixing the TypeError raised when tz-aware ISO strings (e.g. 2026-01-20T00:00:00Z) were stored. timezone was already imported at line 16, so no new import needed. |
| tests/proxy_unit_tests/test_proxy_utils.py | Adds test_get_temp_budget_increase_tz_aware_expiry covering the future-expiry (returns increase) and past-expiry (returns None) cases using tz-aware ISO strings. The existing test_get_temp_budget_increase continues to cover the naive-datetime path. |
Reviews (1): Last reviewed commit: "fix(proxy/auth): handle tz-aware temp_bu..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Co-authored-by: shivam <shivam@berri.ai> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> (cherry picked from commit 10d2a27)
Co-authored-by: shivam <shivam@berri.ai> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> (cherry picked from commit 10d2a27)
Relevant issues
Linear ticket
Resolves LIT-4576
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
Screenshots / Proof of Fix
/key/updatedocumentstemp_budget_expiryas ISO-8601 with timezone (e.g."2026-01-20T00:00:00Z"). Setting it that way stored a tz-aware value and bricked the key on the next request. Reproduced end to end against a live proxy onlocalhost:4000hitting a real Anthropic model (anthropic/claude-haiku-4-5)Same script for both runs:
Before (commit fdf380d, pre-fix)
Proxy traceback:
After (commit 6261056, this PR)
Type
🐛 Bug Fix
Changes
UpdateKeyRequest.temp_budget_expiry: Optional[datetime]accepts theZsuffix and Pydantic parses it to a tz-aware UTC datetime;prepare_metadata_fieldsstoresv.isoformat(), which keeps the+00:00offset. On the next request_get_temp_budget_increaserandatetime.fromisoformat(...) > datetime.now(), and the aware-vs-naive comparison raised_get_temp_budget_increaseinlitellm/proxy/auth/user_api_key_auth.pynow treats a naive parsed expiry as UTC and always compares againstdatetime.now(timezone.utc):The naive branch keeps the previous behavior for any legacy metadata written without a timezone
tests/proxy_unit_tests/test_proxy_utils.pyaddstest_get_temp_budget_increase_tz_aware_expirycovering both the future-expiry (returns the increase) and past-expiry (returnsNone) branches using the documented"...Z"input format. The test fails before this change with the sameTypeErrorand passes afterFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/29199d8f443e46a79091b097e31176f7
Requested by: @shivamrawat1