litellm icon indicating copy to clipboard operation
litellm copied to clipboard

Initial budget reset datetime

Open aayush-malviya-acquia opened this issue 1 year ago • 11 comments

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_at field with validation (rejects past dates, handles timezones)
  • Explicit budget_reset_at takes precedence over budget_duration calculation
  • Added validation and integration tests
  • Uses existing schema field

Use case: Align initial user budget resets with specific dates instead of only relative durations.

aayush-malviya-acquia avatar Dec 05 '25 04:12 aayush-malviya-acquia

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Mar 6, 2026 7:15am

Request Review

vercel[bot] avatar Dec 05 '25 04:12 vercel[bot]

why not call it initial_budget_reset_at? @aayush-malviya-acquia seems more accurate, if i understand your goal

ghost avatar Dec 12 '25 12:12 ghost

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- Screenshot 2025-12-17 at 3 05 13 PM Here we are calling it budget_reset_at. So consistency should be maintained, I think.

aayush-malviya-acquia avatar Dec 17 '25 09:12 aayush-malviya-acquia

@krrishdholakia, waiting for your response.

aayush-malviya-acquia avatar Jan 06 '26 11:01 aayush-malviya-acquia

@krrishdholakia, waiting for your response on this.

aayush-malviya-acquia avatar Feb 13 '26 06:02 aayush-malviya-acquia

@krrishdholakia, any updates?

aayush-malviya-acquia avatar Feb 24 '26 05:02 aayush-malviya-acquia

@krrishdholakia, I have renamed param budget_reset_at to initial_budget_reset_at as you suggested.

aayush-malviya-acquia avatar Mar 02 '26 08:03 aayush-malviya-acquia

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_valid helper validates that the provided datetime is not in the past; validators are wired onto both NewUserRequest and UpdateUserRequestNoUserIDorEmail
  • _update_internal_new_user_params renames initial_budget_reset_at → budget_reset_at before forwarding to generate_key_helper_fn (with None guards in place)
  • generate_key_helper_fn receives a new budget_reset_at parameter that, when present, overrides the duration-based reset_at calculation with proper timezone normalization and fallback behavior
  • _update_internal_user_params handles the same renaming for the update path, with explicit precedence guards
  • Response construction correctly echoes the normalized value from generate_key_helper_fn back 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

greptile-apps avatar Mar 02 '26 08:03 greptile-apps

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: write initial_budget_reset_at to 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.

giulio-leone avatar Mar 02 '26 13:03 giulio-leone

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.

github-actions[bot] avatar Jun 05 '26 00:06 github-actions[bot]

@krrish-berri-2, @ishaan-berri, @yuneng-berri, can you take a look at this PR, please?

aayush-malviya-acquia avatar Jun 05 '26 11:06 aayush-malviya-acquia