Skip to content

feat(python-sdk): record_usage() and budget_check() (GOV-38)#7

Closed
Shaivpidadi wants to merge 3 commits intofeat/1.4b-precheck-integration-testfrom
feat/1.4c-usage-budget
Closed

feat(python-sdk): record_usage() and budget_check() (GOV-38)#7
Shaivpidadi wants to merge 3 commits intofeat/1.4b-precheck-integration-testfrom
feat/1.4c-usage-budget

Conversation

@Shaivpidadi
Copy link
Copy Markdown
Member

Summary

  • GovernsAIClient.record_usage(org_id, user_id, tokens, model) → None
  • GovernsAIClient.async_record_usage() — async variant
  • GovernsAIClient.budget_check(org_id, user_id, estimated_tokens)BudgetResult
  • GovernsAIClient.async_budget_check() — async variant
  • BudgetResult dataclass: allowed, remaining_tokens, limit, warning_threshold_hit, reason
  • 5 unit tests: correct payload shape, allowed/denied, warning threshold (< 10% remaining)

GovernsAI Tracker

GOV-38: 1.4c record_usage() and budget_check()

Test plan

  • Unit test: record_usage() sends correct payload (orgId, userId, inputTokens, model)
  • Unit test: async_record_usage() sends correct payload
  • Unit test: budget_check() → allowed=True, warning_threshold_hit=False
  • Unit test: budget_check() → allowed=False when over budget
  • Unit test: budget_check() → warning_threshold_hit=True when remaining < 10%

…, memory clients

- GovernAIClient with precheck() and async_precheck()
- Type definitions mirroring TypeScript SDK surface
- Integration test scaffold
- pyproject.toml with dev dependencies
- tests/integration/test_precheck_integration.py: proper pytest tests
  (sync and async) marked @pytest.mark.integration
- pyproject.toml: register integration marker, add src pythonpath,
  switch to --import-mode=importlib so src/ takes priority over
  legacy root-level governs_ai/ directory
- conftest.py: insert src/ at sys.path[0] as safety fallback
- governs_ai/exceptions/precheck.py: add missing Optional/Dict/Any
  imports (Python 3.13 compat)

Refs: GOV-37
- client.record_usage(org_id, user_id, tokens, model) → None
- client.async_record_usage() — async variant
- client.budget_check(org_id, user_id, estimated_tokens) → BudgetResult
- client.async_budget_check() — async variant
- BudgetResult: allowed, remaining_tokens, limit, warning_threshold_hit, reason
- 5 unit tests: correct payload, allowed/denied, warning threshold (< 10%)

Refs: GOV-38
@Shaivpidadi Shaivpidadi force-pushed the feat/1.4b-precheck-integration-test branch from c8f3466 to a237384 Compare April 20, 2026 17:00
@Shaivpidadi Shaivpidadi deleted the branch feat/1.4b-precheck-integration-test April 20, 2026 17:01
@Shaivpidadi Shaivpidadi deleted the feat/1.4c-usage-budget 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