feat(llm): alert when Venice credits run low - #398
Merged
Merged
Conversation
The Venice account ran out of credits and every AI explanation silently degraded to no summary. Check the key's balance at the start of each Safe and timelock run and send an ops alert when USD + DIEM drops below $1 (LLM_CREDIT_ALERT_THRESHOLD_USD) or access is blocked. Deduped to once per 24h while low; a top-up resets the cooldown. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Venice's per-key balance is the lower of the account balance and what is left of the key's daily spend limit, so a low reading can also mean the daily cap is nearly used. Say so in the alert and show when it resets. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Venice keys spend DIEM, then bundled credits, then USD, so bundled credits belong in the spendable balance. Catch every failure in the check (alert send, cooldown state, threshold parsing) so a diagnostic can never stop the Safe/timelock monitors from running; a failed send retries next run. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Fixes GHSA-8988-9cw3-xx77, GHSA-gh4c-6fx4-qh6g and GHSA-vxq7-64xx-v4gw, which fail the audit job. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Why
The Venice account ran out of credits. Every AI explanation failed, and the only trace was a log line. Safe and timelock alerts went out without an AI summary, and nothing reported it.
What
utils/llm/credits.py. It reads the key's balance fromGET /api_keys/rate_limitsbecause/billing/balanceneeds an admin key./billing/balanceneeds an admin key.main()inprotocols/safe/main.py(every 20 min) andprotocols/timelock/timelock_alerts.py(hourly).LLM_CREDIT_ALERT_THRESHOLD_USD(default$1), or when Venice reportsaccessPermitted: false.send_error_messagewith notification sound on. It's labelledyearnand stored underyearn-internal, so it stays off public pages.Testing
tests/test_llm_credits.py: 12 cases covering the threshold, DIEM, bundled credits, blocked access, the env override, cooldown, top-up reset, fetch failure, send failure, a bad threshold value and the skip conditions.tests/test_safe_main.py: the quota tests that runmain()now stub the check so they don't make real calls.usd=2.83. The account held $24.75 at the time, so that figure is what was left of the key's $5 daily limit.test_safe_main.pyfail locally both on this branch and on unchangedmain, so this PR didn't introduce them.🤖 Generated with Claude Code