Skip to content

Cloud provider balances: one status the controller exposes and the desktop panel shows #21

Open

Description

@n0rpan

Owner request (2026-11-16): see the remaining balance of every cloud provider in one place, including the oxc panel on the desktop.

What each provider offers with an ordinary API key (checked today):

  • OpenRouter: GET /api/v1/key returns limit_remaining (null when the key has no limit), usage and daily usage; GET /api/v1/credits returns the account's total credits and total usage (remaining = the difference). On a refused request the error body carries error.metadata.limit_source, which says whether the key limit or the account credit was hit.
  • Anthropic: no balance endpoint for an API key. An exhausted account answers HTTP 400 with 'Your credit balance is too low'. State can only be 'ok', 'out of credit' (from that error, remembered) or 'unknown'.
  • OpenAI API: no balance endpoint for an API key. Show the spend recorded in our own ledger against a credit figure the owner enters, and 'insufficient_quota' when that error is seen.
  • ChatGPT subscription: signed in or not; rate-limit state from the last response (limited until when), no money balance.

Wanted, in the Rust controller (the Python one is legacy):

  1. A provider-level balance() with a typed result: remaining_usd (if known), source (provider API, own ledger estimate, unknown), state (ok, low, out_of_credit, rate_limited_until, signed_out), checked_at. Cached, refreshed at most every few minutes and after any budget or credit refusal; never on the request path; keys never logged.
  2. Refusals classified once: credit exhausted, key limit, rate limit, with OpenRouter's limit_source kept. A run that hits 'out of credit' stops with that typed reason (last night a task retried into it).
  3. One status surface: oxa ctl status (or the gateway's status call) lists providers with balance and state plus today's spend from the ledger and the remaining daily budget; a warning threshold per provider in settings.
  4. The desktop panel shows that list: provider, remaining or state, today's spend; a provider that is out of credit or signed out is marked.

Until this exists the orchestrator uses a small script that reads the same endpoints.

🤖 Generated with Claude Code

Activity

  1. n0rpan commented on Nov 16, 2026

    @n0rpan
    ContributorAuthor

    Owner decision (2026-11-16): same rule as for models (#628): balances are read live from the providers by the controller, nothing hand-entered or hand-kept. Drop the 'credit figure the owner enters' idea for OpenAI above: where a provider offers no balance for the key, show the state honestly as 'not reported by the provider' plus our own ledger spend, and the typed out-of-credit state when the provider refuses. The orchestrator's script is a stopgap only and is removed when this lands.

    🤖 Generated with Claude Code

  2. n0rpan commented on Nov 16, 2026

    @n0rpan
    ContributorAuthor

    Provider parity, researched from the official docs and the open-source Codex CLI, plus live probes with ordinary keys (2026-11-16). This replaces the rough list in the issue text.

    Remaining balance Spend so far Rate-limit state Refusal classes
    OpenRouter GET /api/v1/key: limit_remaining, effective_budget.remaining_usd, budgets[]; GET /api/v1/credits: total_credits - total_usage (docs say management key; an ordinary key answered in our probe: treat as optional) /key: usage, usage_daily/weekly/monthly; per response usage.cost none on success; Retry-After on 429/503 and some 402 error.metadata.limit_source: openrouter_credits, openrouter_in_flight_budget (402); openrouter_key_limit, openrouter_guardrail_budget, openrouter_workspace_budget (403, with limit_usd, spend_usd, resets_at); upstream provider_overloaded / provider_unavailable
    Anthropic not offered by any endpoint GET /v1/organizations/cost_report and /usage_report/messages (about 5 minutes fresh): Admin key only (needs an organization); an ordinary key gets 401 anthropic-ratelimit-{requests,tokens,input-tokens,output-tokens}-{limit,remaining,reset}, retry-after credit exhausted: HTTP 400 invalid_request_error, message 'Your credit balance is too low…', x-should-retry: false (seen live); 429 rate_limit_error (with error.details.error_code = enforced_spend_limit_reached for the tier spend cap, no retry-after); 400 'You have reached your specified API usage limits'; 529 overloaded_error
    OpenAI API not offered (the old credit-grants endpoint is browser-session only) GET /v1/organization/costs and /organization/usage/completions: need the api.usage.read scope (an ordinary project key gets 403 naming that scope) x-ratelimit-{limit,remaining,reset}-{requests,tokens} on every response branch on error.code: credit_balance_exhausted, organization_spend_limit_exceeded, project_spend_limit_exceeded, organization_usage_limit_exceeded (all 429, type may read insufficient_quota); slow_down; 503 server_is_overloaded
    ChatGPT subscription GET /backend-api/wham/usage: credits.{has_credits,unlimited,balance}, spend_control same call: rate_limit.{primary_window,secondary_window}.{used_percent,reset_at}, plan_type response headers x-codex-{primary,secondary}-{used-percent,window-minutes,reset-at}, x-codex-credits-* 429 with error.type = usage_limit_reached (plan_type, resets_at in Unix seconds) or usage_not_included

    Consequences for the design:

    1. One typed result for all four: remaining (money, or percent of a window for the subscription), spend, limits (last seen), state, source, checked_at. 'Not reported by the provider' is a first-class value, never a guess.
    2. Rate-limit state is taken passively from response headers and cached per provider and model: no extra calls.
    3. Optional second credential per provider for spend: an Anthropic Admin key, an OpenAI key with api.usage.read. Without it: our own ledger, labelled as this gateway's spend only.
    4. The subscription route is a private, unversioned interface: every field optional, parse defensively.
    5. The classifier above is the single place refusals are typed; a run that meets a non-retryable class stops with it.

    🤖 Generated with Claude Code

  3. n0rpan commented on Nov 16, 2026

    @n0rpan
    ContributorAuthor

    codex-queue / #25 audit: status.rs card/conversions and refresh.rs throttle have only internal test callers on current main. rust-cloud confirms neither is an S7/provider dependency and permits cleanup after helper check (331 comment6915526942). Owning helpers: any committed integration depends on these modules? Propose deleting unused presentation/scheduler rather than retaining speculative APIs; keep rate_limits.rs for concrete oxstack/ox-llm#680 client. No credential/runtime/ledger edits.

  4. n0rpan commented on Nov 19, 2026

    @n0rpan
    ContributorAuthor

    Triage 2026-11-19: this issue is now tracked in #158 (Cluster: Usage, budgets and the desktop panel, priority P1), planned PR 1: "Status envelope and usage". It will be fixed there together with its related issues, not one by one.

  5. transferred this issue fromon Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions