llm-connect/contracts/functional/account-balance.md
tegwick ed7c632155
All checks were successful
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 1s
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.
2026-08-03 23:49:01 +02:00

44 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Provider Account Balance
`llm_connect.balance` reports **prepaid / key remaining** for a selected
inference **backend**. Balance is never assumed to be OpenRouter unless that
backend is selected (explicitly or as the current default provider).
## Selection rules
```python
from llm_connect import get_account_balance, resolve_balance_provider
resolve_balance_provider(None) # → LLMConfig().provider (today openrouter)
resolve_balance_provider("openrouter") # one-shot; does not mutate defaults
get_account_balance() # default backend
get_account_balance("openrouter") # explicit backend for this call only
```
- Explicit `provider` / CLI `--provider` is **invocation-only**.
- It must not rewrite config files, env, `LLMConfig` class defaults, or
OpenRouter model defaults.
- Unspecified → current default provider via `resolve_balance_provider(None)`.
## Contract
- `AccountBalance` carries optional wallet fields (`credits_*`) and optional
key-limit fields (`limit`, `limit_remaining`, `limit_reset`, `usage`).
- EUR display fields use the same FX resolution as cost estimates.
- `BalanceClientRegistry` maps provider id → client factory.
- Unsupported providers raise `LLMBalanceUnsupportedError` listing supported
backends (do not fall back to OpenRouter).
## OpenRouter (v1)
- `GET /api/v1/credits` → account prepaid: remaining = total_credits total_usage
- `GET /api/v1/auth/key` → key limit remaining / reset policy
- Both are fetched best-effort; one may fail while the other succeeds.
## CLI
```bash
llm-connect balance
llm-connect balance --provider openrouter
llm-connect balance --json
```