Expand description
claude_quota — Anthropic API quota HTTP transports.
Provides rate-limit header types and OAuth usage endpoint types as library
types (always available), with network functions gated behind the enabled feature.
§Feature Flags
| Feature | Adds | Extra dep |
|---|---|---|
| (none) | RateLimitData, OauthUsageData, OauthAccountData, MembershipRaw, ClaudeCliRolesData, PeriodUsage, QuotaError | — |
| (none) | parse_headers, parse_oauth_usage, parse_oauth_account, parse_claude_cli_roles, select_membership_index, iso_to_unix_secs | — |
enabled | fetch_rate_limits(token), fetch_oauth_usage(token), fetch_oauth_account(token), fetch_claude_cli_roles(token) | ureq |
§Testability
parse_headers accepts Fn(&str) -> Option<String> so unit tests pass a
HashMap-backed closure — no live network, no ureq in dev-dependencies.
parse_oauth_usage operates on a raw &str body for the same reason.
Structs§
- Claude
CliRoles Data - Org identity snapshot parsed from
GET /api/oauth/claude_cli/roles. - Membership
Raw - One membership entry parsed from
GET /api/oauth/account. - Oauth
Account Data - Account identity and subscription state parsed from
GET /api/oauth/account. - Oauth
Usage Data - Response from
GET /api/oauth/usage— three period buckets. - Period
Usage - Per-period quota bucket from the OAuth usage endpoint.
- Rate
Limit Data - Rate-limit utilization data parsed from Anthropic API response headers.
Enums§
- Quota
Error - Errors produced by the quota HTTP transport.
Constants§
- ANTHROPIC_
BETA - OAuth beta header value — must match the Claude binary’s OAuth implementation.
- ANTHROPIC_
VERSION - Anthropic API version header value.
- API_URL
- Anthropic messages endpoint used for quota checks.
- CLAUDE_
CLI_ ROLES_ URL - Claude CLI roles URL — GET endpoint returning org and workspace identity.
- OAUTH_
ACCOUNT_ URL - OAuth account URL — GET endpoint returning account identity and org membership.
- OAUTH_
USAGE_ URL - OAuth usage URL — GET endpoint returning per-period quota buckets.
Functions§
- iso_
to_ unix_ secs - Convert an ISO-8601 UTC timestamp to Unix seconds.
- parse_
claude_ cli_ roles - Parse the body of
GET /api/oauth/claude_cli/rolesintoClaudeCliRolesData. - parse_
headers - Parse rate-limit utilization headers using a closure-based header accessor.
- parse_
oauth_ account - Parse the body of
GET /api/oauth/accountintoOauthAccountData. - parse_
oauth_ usage - Parse the body of
GET /api/oauth/usageintoOauthUsageData. - select_
membership_ index - Return the index of the highest-priority membership in
memberships.