Skip to main content

Module fetcher

Module fetcher 

Source
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§

HttpResponse
Raw HTTP response — enough for fetch_usage to classify the outcome without leaking the HTTP crate to callers.
UreqTransport
ureq::Agent-backed UsageTransport. One agent is shared across all fetch_usage calls 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§

UsageTransport
Injected HTTP surface. UreqTransport is the default; tests use a fake to exercise status-handling paths without real I/O. Errors carry io::ErrorKind::TimedOut for timeouts; anything else is treated as a generic network failure in fetch_usage.

Functions§

default_user_agent
Build the User-Agent header 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 UsageError taxonomy per docs/specs/rate-limit-segments.md §Error message table.