Skip to main content

Crate anthropic_oauth

Crate anthropic_oauth 

Source
Expand description

PKCE OAuth login for Anthropic Claude Pro/Max.

Thin wrapper around motosan_ai_oauth with the Anthropic provider pre-configured.

§Usage

#[tokio::main]
async fn main() -> Result<(), anthropic_oauth::Error> {
    let token = anthropic_oauth::login().await?;
    // `token.access_token` is a "sk-ant-oat01-*" string usable directly
    // with motosan_ai's AnthropicProvider (which auto-detects the prefix
    // and applies Claude Code identity headers).
    println!("{}", token.access_token);
    Ok(())
}

§Notes

  • Requires port 53692 to be free on localhost (registered with Anthropic’s Claude Code app).
  • client_id is hardcoded to Anthropic’s Claude Code app registration and is not configurable. See the project README for the associated ToS disclosure before depending on this crate.

Structs§

Token

Enums§

Error

Functions§

login
Open a browser-based PKCE login flow and return the resulting OAuth token.
refresh
Exchange a stored refresh token for a new Token.