Rho.Usage.Fetch (rho v0.1.0)

Copy Markdown View Source

Asks a provider's OAuth usage endpoint what its subscription has left, with the sign-in's access token (Rho.Auth.credential/1), as omp does (subscriptions only: an API key has no such endpoint):

  • Claude: GET https://api.anthropic.com/api/oauth/usage with the oauth-2025-04-20 beta and Claude Code's user agent
  • ChatGPT: GET https://chatgpt.com/backend-api/wham/usage with the chatgpt-account-id

refresh/3 stores the result (Rho.Usage.put_endpoint/5). The token goes only into the request's authorization header; errors never include it.

Summary

Functions

provider's usage JSON, or why there is none: signed out, an API key (no subscription), an expired sign-in, or the endpoint's HTTP status and message (it answers 429 when asked too often).

Fetches and stores provider's windows. opts: :credential (default Rho.Auth.credential/1), :respond (a test's fake response for the Req.Request), :now.

Functions

fetch(provider, opts \\ [])

@spec fetch(Rho.Auth.provider(), keyword()) :: {:ok, map()} | {:error, String.t()}

provider's usage JSON, or why there is none: signed out, an API key (no subscription), an expired sign-in, or the endpoint's HTTP status and message (it answers 429 when asked too often).

refresh(dir, provider, opts \\ [])

@spec refresh(Path.t(), Rho.Auth.provider(), keyword()) :: :ok | {:error, String.t()}

Fetches and stores provider's windows. opts: :credential (default Rho.Auth.credential/1), :respond (a test's fake response for the Req.Request), :now.