Initial budget reset datetime
Title
Implement: [Feature]: Set the initial budget reset datetime for a user during creation #16431
Relevant issues
N/A
Pre-Submission checklist
- [x] I have added testing in the
tests/litellm/directory - [x] I have added a screenshot of my new test passing locally
- [ ] My PR passes all unit tests on
make test-unit(note: pre-existing errors unrelated to this PR) - [x] My PR's scope is isolated - adds one specific feature
Type
🆕 New Feature
Changes
Adds budget_reset_at parameter to /user/new endpoint for manual budget reset scheduling.
- Added
budget_reset_atfield with validation (rejects past dates, handles timezones) - Explicit
budget_reset_attakes precedence overbudget_durationcalculation - Added validation and integration tests
- Uses existing schema field
Use case: Align initial user budget resets with specific dates instead of only relative durations.
The latest updates on your projects. Learn more about Vercel for GitHub.
| Project | Deployment | Actions | Updated (UTC) |
|---|---|---|---|
| litellm | Preview, Comment | Mar 6, 2026 7:15am |
why not call it initial_budget_reset_at? @aayush-malviya-acquia seems more accurate, if i understand your goal
why not call it
initial_budget_reset_at? @aayush-malviya-acquia seems more accurate, if i understand your goal
We can call it that. But take a look at the /budget/new endpoint-
Here we are calling it budget_reset_at. So consistency should be maintained, I think.
@krrishdholakia, waiting for your response.
@krrishdholakia, waiting for your response on this.
@krrishdholakia, any updates?
@krrishdholakia, I have renamed param budget_reset_at to initial_budget_reset_at as you suggested.
Greptile Summary
This PR adds an initial_budget_reset_at parameter to the /user/new and /user/update endpoints, allowing callers to specify an exact datetime for the first budget reset instead of relying solely on a relative budget_duration interval. When both are provided, the explicit date takes precedence for the initial reset while subsequent resets continue to follow the budget_duration interval.
Key implementation details:
_assert_initial_budget_reset_at_validhelper validates that the provided datetime is not in the past; validators are wired onto bothNewUserRequestandUpdateUserRequestNoUserIDorEmail_update_internal_new_user_paramsrenamesinitial_budget_reset_at→budget_reset_atbefore forwarding togenerate_key_helper_fn(with None guards in place)generate_key_helper_fnreceives a newbudget_reset_atparameter that, when present, overrides the duration-basedreset_atcalculation with proper timezone normalization and fallback behavior_update_internal_user_paramshandles the same renaming for the update path, with explicit precedence guards- Response construction correctly echoes the normalized value from
generate_key_helper_fnback to the caller - Test coverage includes Pydantic validation for all three request types plus integration tests for both the creation and update paths with fully-mocked DB and license-check dependencies
Confidence Score: 5/5
- This PR is safe to merge — the change is additive, backwards-compatible, and all previously raised review concerns have been addressed or verified as non-issues.
- The implementation correctly handles the feature across both the creation and update paths, with proper timezone normalization, precedence logic, and defensive fallback behavior. All changed files have been thoroughly reviewed: validation logic is sound, Pydantic models are correctly structured, request/response mapping is accurate, and test coverage is comprehensive for all request types and paths. No outstanding issues or edge cases remain unaddressed.
- No files require special attention — all changed files are sound.
Last reviewed commit: ff421f6
Automated patch bundle from top-50 unresolved backlog scan.\nGenerated due limited direct branch-write access; please apply/cherry-pick the proposed minimal edits below.\n\n## PR #17520 — initial_budget_reset_datetime
Unresolved threads summary
- greptile-apps, litellm/proxy/management_endpoints/key_management_endpoints.py:586, initial_budget_reset_at sets user reset, not key reset.
- greptile-apps, litellm/proxy/management_endpoints/key_management_endpoints.py:2098, Silent fallback on parse failure hides errors.
- greptile-apps, litellm/proxy/management_endpoints/internal_user_endpoints.py:784, Silent fallback on parse failure hides errors.
- greptile-apps, litellm/proxy/management_endpoints/internal_user_endpoints.py:431, Response construction may trigger past-date validation.
- greptile-apps, tests/test_litellm/proxy/management_endpoints/test_initial_budget_reset_at.py:93, Misspelled exception: AssertionError.
Concrete patch proposal
-
litellm/proxy/management_endpoints/key_management_endpoints.py: writeinitial_budget_reset_atto the key reset field (not user reset field); validate/parse input explicitly and raise typed 400 errors on parse failures. -
litellm/proxy/management_endpoints/internal_user_endpoints.py: validate/parse input explicitly and raise typed 400 errors on parse failures; construct response DTO without re-triggering past-date validation. -
tests/test_litellm/proxy/management_endpoints/test_initial_budget_reset_at.py: fix the expected exception type/message in the test.
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
@krrish-berri-2, @ishaan-berri, @yuneng-berri, can you take a look at this PR, please?