Skip to content

feat(python-sdk): budget_check() + BudgetResult model — GOV-38#5

Closed
Shaivpidadi wants to merge 1 commit intomainfrom
feat/1.4c-budget-check
Closed

feat(python-sdk): budget_check() + BudgetResult model — GOV-38#5
Shaivpidadi wants to merge 1 commit intomainfrom
feat/1.4c-budget-check

Conversation

@Shaivpidadi
Copy link
Copy Markdown
Member

Summary

  • Adds BudgetResult model with allowed, remaining_tokens, limit, warning_threshold_hit (auto-computed True when < 10% budget remains)
  • Adds budget_check(org_id, user_id, estimated_tokens) → BudgetResult on GovernsAIClient plus async_budget_check alias
  • Adds async_record_usage alias for record_usage
  • Fixes missing Optional/Dict/Any imports in exceptions/precheck.py

GovernsAI issue

GOV-38

Test plan

  • BudgetResult.from_dict — allowed=True, no warning
  • BudgetResult.from_dict — allowed=False when budget exceeded
  • BudgetResult.from_dictwarning_threshold_hit=True when remaining < 10%
  • BudgetResult.from_dict — warning_threshold_hit=False at exactly 10%
  • BudgetResult.from_dict — camelCase keys normalised
  • budget_check() — correct params sent to /api/v1/budget/context
  • budget_check() — returns denied result with reason
  • budget_check() — warning threshold propagated
  • async_budget_check — is alias
  • record_usage() — UsageRecord passed through
  • record_usage() — dict converted to UsageRecord
  • async_record_usage — is alias
  • 12/12 unit tests passing

- Add BudgetResult model with allowed, remaining_tokens, limit,
  warning_threshold_hit (auto-set when < 10% budget remains)
- Add budget_check(org_id, user_id, estimated_tokens) and async variant
  on GovernsAIClient
- Add async_record_usage() alias
- Fix missing Optional/Dict/Any imports in exceptions/precheck.py
- 12 unit tests covering allowed/denied/warning/async variants

Refs: GOV-38
@Shaivpidadi
Copy link
Copy Markdown
Member Author

Closing: duplicate of PR #7 which implements both record_usage() and budget_check() with a superset of this work.

@Shaivpidadi Shaivpidadi deleted the feat/1.4c-budget-check branch April 20, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant