new tasks, devnet topup, cli, new model support
This commit is contained in:
@@ -87,6 +87,29 @@ class BillingLedger:
|
||||
def has_funds(self, api_key: str) -> bool:
|
||||
return self.ensure_client(api_key) > 0.0
|
||||
|
||||
def grant_caller_credit(self, api_key: str, account_id: str, amount: float) -> bool:
|
||||
"""Grant the one-time Caller Credit for an account (US-039).
|
||||
|
||||
The event id is derived from the account, not the key, so the grant is
|
||||
idempotent per account — across retries, additional keys, and hive
|
||||
gossip replication alike. Returns True only when credit was applied.
|
||||
"""
|
||||
if amount <= 0:
|
||||
return False
|
||||
event_id = f"caller-credit-{account_id}"
|
||||
with self._lock:
|
||||
if event_id in self._seen_event_ids:
|
||||
return False
|
||||
self._apply_locked({
|
||||
"id": event_id,
|
||||
"type": "credit",
|
||||
"api_key": api_key,
|
||||
"amount": amount,
|
||||
"ts": time.time(),
|
||||
"note": "caller-credit",
|
||||
})
|
||||
return True
|
||||
|
||||
def credit_client(self, api_key: str, amount: float, *, note: str = "deposit") -> float:
|
||||
if amount <= 0:
|
||||
raise ValueError("credit amount must be positive")
|
||||
|
||||
Reference in New Issue
Block a user