Documentation
¶
Overview ¶
Package provbalance reads a model provider's balance through the seat's key: the transport of the sprint's balance poll (internal/sprint balance.go; nova-tools#5199). It decides nothing: it answers what the provider said, or that its balance is unknown and why, and never says the key.
Index ¶
Constants ¶
const OpenRouterKeyURL = "https://openrouter.ai/api/v1/key"
OpenRouterKeyURL is openrouter's key endpoint: GET with the key as a bearer token answers {"data": {"usage_daily": <dollars the key used today, the UTC day>, ...}}, the provider's own count the cost reconciliation sets beside the sprint's records (sprint.CostReconcile).
const OpenRouterURL = "https://openrouter.ai/api/v1/credits"
OpenRouterURL is openrouter's credits endpoint: GET with the key as a bearer token answers {"data": {"total_credits": <dollars bought>, "total_usage": <dollars used>}}.
const Timeout = 15 * time.Second
Timeout bounds one read: a provider that does not answer leaves the balance unknown.
Variables ¶
var KeyEnv = map[string]string{"openrouter": "OPENROUTER_API_KEY"}
KeyEnv is the variable each provider's key is in, as nova-secrets exec delivers it to the run loop (`nova-secrets exec --only OPENROUTER_API_KEY -- nova-sprint run ...`).
Functions ¶
This section is empty.
Types ¶
type ProviderRead ¶
type ProviderRead struct {
Provider string
Known bool
Balance float64
HasUsed bool
Used float64
Note string
}
ProviderRead is one balance the poll read: the provider, the dollars left (Known false with Note saying why when there is none to read), and its count of dollars used (HasUsed false when it keeps none). The sprint's balance poll names it ProviderRead.
func Read ¶
func Read(ctx context.Context, rt http.RoundTripper, provider string, getenv func(string) string) ProviderRead
Read is the provider's balance over the transport (nil is http.DefaultTransport), its key read from getenv; a provider with no endpoint, no key, or an answer that is not its shape is unknown with why.
type UsageRead ¶
type UsageRead struct {
Provider string
Known bool
Day string // the UTC day the count is of, 2006-01-02
Used float64
Note string
}
UsageRead is one provider's own count of a UTC day's usage as the run loop read it: Known false with Note saying why when there was none to read. The sprint's cost reconciliation names it UsageRead.
func ReadUsage ¶
func ReadUsage(ctx context.Context, rt http.RoundTripper, provider, day string, getenv func(string) string) UsageRead
ReadUsage is the provider's own count of the UTC day's usage over the transport (nil is http.DefaultTransport), its key read from getenv; day is the UTC day the count is of, 2006-01-02. A provider with no usage endpoint, no key, or an answer that is not its shape is unknown with why, and the key is never in the why.