Skip to main content

Crate claude_quota

Crate claude_quota 

Source
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

FeatureAddsExtra 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
enabledfetch_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§

ClaudeCliRolesData
Org identity snapshot parsed from GET /api/oauth/claude_cli/roles.
MembershipRaw
One membership entry parsed from GET /api/oauth/account.
OauthAccountData
Account identity and subscription state parsed from GET /api/oauth/account.
OauthUsageData
Response from GET /api/oauth/usage — three period buckets.
PeriodUsage
Per-period quota bucket from the OAuth usage endpoint.
RateLimitData
Rate-limit utilization data parsed from Anthropic API response headers.

Enums§

QuotaError
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/roles into ClaudeCliRolesData.
parse_headers
Parse rate-limit utilization headers using a closure-based header accessor.
parse_oauth_account
Parse the body of GET /api/oauth/account into OauthAccountData.
parse_oauth_usage
Parse the body of GET /api/oauth/usage into OauthUsageData.
select_membership_index
Return the index of the highest-priority membership in memberships.