feat(python-sdk): record_usage() and budget_check() (GOV-38)#7
Closed
Shaivpidadi wants to merge 3 commits intofeat/1.4b-precheck-integration-testfrom
Closed
feat(python-sdk): record_usage() and budget_check() (GOV-38)#7Shaivpidadi wants to merge 3 commits intofeat/1.4b-precheck-integration-testfrom
Shaivpidadi wants to merge 3 commits intofeat/1.4b-precheck-integration-testfrom
Conversation
…, 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
12 tasks
c8f3466 to
a237384
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GovernsAIClient.record_usage(org_id, user_id, tokens, model)→ NoneGovernsAIClient.async_record_usage()— async variantGovernsAIClient.budget_check(org_id, user_id, estimated_tokens)→BudgetResultGovernsAIClient.async_budget_check()— async variantBudgetResultdataclass:allowed,remaining_tokens,limit,warning_threshold_hit,reasonGovernsAI Tracker
GOV-38: 1.4c record_usage() and budget_check()
Test plan