Implement LLM-WP-0008: provider-scoped account balance CLI
All checks were successful
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 1s

Add pluggable balance registry, OpenRouter credits/key limit client,
and llm-connect balance with one-shot --provider that does not change
library defaults.
This commit is contained in:
tegwick 2026-08-03 23:49:01 +02:00
parent c0d5c4ad08
commit ed7c632155
11 changed files with 783 additions and 14 deletions

View file

@ -38,7 +38,36 @@ def post_json(
headers={"Content-Type": "application/json", **(headers or {})},
method="POST",
)
return _read_json_response(url, req, timeout=timeout)
def get_json(
url: str,
headers: Optional[Dict[str, str]] = None,
timeout: int = 60,
) -> Dict[str, Any]:
"""GET *url* and return the parsed JSON response body.
Raises:
LLMRateLimitError: on HTTP 429
LLMAPIError: on other non-2xx responses
LLMTimeoutError: on socket / read timeout
"""
record_provider_request(url=url, payload=None, headers=headers or {})
req = urllib.request.Request(
url,
headers={**(headers or {})},
method="GET",
)
return _read_json_response(url, req, timeout=timeout)
def _read_json_response(
url: str,
req: urllib.request.Request,
*,
timeout: int,
) -> Dict[str, Any]:
try:
with urllib.request.urlopen(req, timeout=timeout) as resp:
body = resp.read().decode()