Expand description
OAuth /api/oauth/usage HTTP client.
Lowest layer of the rate-limit data pipeline. Talks HTTP to the
Anthropic endpoint, classifies the response, and returns a parsed
UsageApiResponse on success. Retry / stale-serve / JSONL
fallback behavior lives in the orchestrator above this layer;
this module has no knowledge of the usage-data cache stack.
(The ureq::Agent held by UreqTransport maintains an internal
connection pool — that’s a transport-level concern, separate from
the response cache.)
Canonical spec: docs/adrs/0011-rate-limit-data-source.md
§Endpoint contract and §Cache stack (Retry-After rules).
Structs§
- Http
Response - Raw HTTP response — enough for
fetch_usageto classify the outcome without leaking the HTTP crate to callers. - Ureq
Transport ureq::Agent-backedUsageTransport. One agent is shared across allfetch_usagecalls so connection pooling / keepalive applies.
Constants§
- DEFAULT_
TIMEOUT - Default per-request timeout per ADR-0011 §Endpoint contract.
- OAUTH_
USAGE_ PATH - Endpoint path appended to the configured
usage.api_base_url.
Traits§
- Usage
Transport - Injected HTTP surface.
UreqTransportis the default; tests use a fake to exercise status-handling paths without real I/O. Errors carryio::ErrorKind::TimedOutfor timeouts; anything else is treated as a generic network failure infetch_usage.
Functions§
- default_
user_ agent - Build the
User-Agentheader value from the compile-time package version. Exposed for regression tests that pin the format contract. - fetch_
usage - Fetch usage data for the given credentials. Maps transport errors
and HTTP status codes onto the
UsageErrortaxonomy perdocs/specs/rate-limit-segments.md§Error message table.