Expand description
Claude Pro/Max subscription auth (OAuth) for the Anthropic backend.
Implements the same subscription sign-in the community bridges use
(pi-claude-bridge,
anthropic-auth): a PKCE
authorize URL the user opens in a browser, a pasted-back code exchanged
for tokens, and transparent refreshes afterwards. Inference requests then
carry Bearer tokens with the oauth-2025-04-20 beta instead of an API
key, so usage bills to the subscription instead of API credits.
At your own risk. This project is not affiliated with or endorsed by
Anthropic. Using a subscription outsideAnthropic’s official clients may violate their terms and can lead to account restrictions or suspension. The preset stays dormant unless explicitly opted in.
Structs§
- Authorization
- Authorize redirect for one sign-in attempt.
- Callback
- Pasted callback: full redirect URL,
code#state, orcode=&state=pairs. - Issued
Tokens - Freshly issued tokens.
- Loaded
Credentials - Loaded credentials plus where to persist refreshed tokens (
None= don’t). - OAuth
Error - Failure talking to the token endpoint.
- OAuth
Session - Credential set backing one subscription session.
- Pkce
- PKCE pair for the authorize redirect.
Enums§
- Account
Mode - Subscription account type selecting the authorize endpoint.
Constants§
- ANTHROPIC_
VERSION AnthropicAPI version header.- AUTHORIZE_
URL_ CONSOLE - Authorize endpoints by account type.
- AUTHORIZE_
URL_ MAX - Authorize endpoints by account type.
- BASE_
URL_ ENV - Base URL override for subscription inference.
- CLAUDE_
CODE_ USER_ AGENT User-Agentidentifying requests asClaude Code, mirroring the bridges.- CLIENT_
ID OAuthclient id embedded inClaude Code(public, shared by bridges).- CODE_
CALLBACK_ URL - Callback the browser flow redirects to (code is pasted back manually).
- OAUTH_
BETA - Beta flag billing inference to the subscription.
- OAUTH_
SCOPES - Scopes requested at sign-in.
- OPT_
IN_ ENV - Explicit opt-in env var enabling the subscription preset.
- REFRESH_
SCOPE - Narrower scopes sent on refresh.
- REFRESH_
SKEW_ MS - Refresh this far ahead of expiry (5 minutes).
- STATIC_
TOKEN_ ENV - Static bearer token (no refresh); implies opt-in.
- TOKEN_
TIMEOUT - Network timeout for token endpoint calls.
- TOKEN_
URL - Token endpoint for both code exchange and refresh.
- TOKEN_
USER_ AGENT User-Agentused for token endpoint calls.
Functions§
- authorize
- Build the authorize URL, PKCE pair, and
statefor a sign-in attempt. - claude_
code_ credentials_ path - Path of
Claude Code’s credentials file (claude auth logintarget). - ensure_
fresh_ token - Ensure the session holds a fresh bearer token, refreshing when needed.
- exchange_
code - Exchange a verified callback for tokens.
- force_
refresh - Refresh unconditionally and store the result (used after a
401). - load_
credentials - Load subscription credentials: our file first, then
Claude Code’s login. - needs_
refresh - Whether the bearer token should be refreshed before use.
- now_ms
- Current time as unix millis;
0when the clock is unavailable. - own_
credentials_ path - Path of our own credentials file (
~/.infinity/claude-oauth.json). - parse_
callback - Parse pasted callback input, rejecting blank fields.
- store_
login - Persist freshly exchanged login tokens; returns the file path.
Type Aliases§
- OAuth
Session Handle - Shareable handle for concurrent completions.