Implement LLM-WP-0008: provider-scoped account balance CLI
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:
parent
c0d5c4ad08
commit
ed7c632155
11 changed files with 783 additions and 14 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue