Documentation
¶
Overview ¶
Package provider holds what Claude and Codex accounts have in common: credentials, identity, and the operations the account manager needs from each provider.
Index ¶
- Variables
- func Decompress(resp *http.Response) error
- func DoJSON(client *http.Client, req *http.Request, dst any) error
- func JWTClaims(token string) (map[string]any, error)
- func PKCE() (verifier, challenge string)
- func ParseCallback(input string) (code, state string)
- func ParseTime(v any) *time.Time
- func RandomHex(n int) string
- func ReadError(resp *http.Response) error
- func UUID() string
- type Credentials
- type HTTPError
- type Identity
- type PingResult
- type Pinger
- type Provider
- type RedeemResult
- type Redeemer
- type Subscription
- type SubscriptionSource
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidGrant = errors.New("refresh token rejected; log in again")
ErrInvalidGrant means the refresh token is dead and the account needs a new login.
Functions ¶
func Decompress ¶
Decompress replaces resp.Body with a decoding reader. Needed because we set Accept-Encoding ourselves to match real clients, which disables Go's transparent gzip handling.
func JWTClaims ¶
JWTClaims decodes a JWT payload without verifying it (tokens come straight from the issuer over TLS).
func PKCE ¶
func PKCE() (verifier, challenge string)
PKCE returns a verifier and its S256 challenge.
func ParseCallback ¶
ParseCallback extracts code and state from a pasted OAuth callback URL, a bare query string, or a raw "code#state" value.
Types ¶
type Credentials ¶
type Credentials struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
IDToken string `json:"id_token,omitempty"`
ExpiresAt time.Time `json:"expires_at"`
LastRefresh time.Time `json:"last_refresh"`
// Codex: ChatGPT workspace/account id sent as ChatGPT-Account-Id.
AccountID string `json:"account_id,omitempty"`
// Claude: profile identifiers and a stable device id used in request metadata.
AccountUUID string `json:"account_uuid,omitempty"`
OrgUUID string `json:"organization_uuid,omitempty"`
DeviceID string `json:"device_id,omitempty"`
// WebSession is a claude.ai session cookie, kept in its own column and attached only when
// reading subscription details.
WebSession string `json:"-"`
}
func ParseCredentials ¶
func ParseCredentials(raw string) (Credentials, error)
func (Credentials) Encode ¶
func (c Credentials) Encode() string
type Identity ¶
type Identity struct {
Email string
ExternalID string // stable id used to dedupe re-logins
Plan string
Label string
}
Identity describes the subscription behind a set of credentials.
type PingResult ¶
PingResult is the outcome of a minimal request sent to start a usage window.
type Pinger ¶
type Pinger interface {
Ping(ctx context.Context, c Credentials, model, prompt string) (*PingResult, error)
}
Pinger is a provider that can send the smallest possible model request, used by the session primer. A non-2xx answer is returned as an *HTTPError alongside the result.
type Provider ¶
type Provider interface {
ID() string
// Refresh exchanges the refresh token for new credentials.
Refresh(ctx context.Context, c Credentials) (Credentials, Identity, error)
// RefreshLead is how long before expiry credentials should be refreshed in the background.
RefreshLead() time.Duration
// FetchQuota polls the provider's usage endpoint.
FetchQuota(ctx context.Context, c Credentials) (*quota.Snapshot, error)
}
type RedeemResult ¶
type RedeemResult struct {
Code string `json:"code"`
WindowsReset []string `json:"windowsReset,omitempty"`
}
RedeemResult is the outcome of spending a banked reset. Codes shared by providers: "reset", "already_redeemed", "nothing_to_reset", "no_credit".
type Redeemer ¶
type Redeemer interface {
Redeem(ctx context.Context, c Credentials, requestID, creditID string) (*RedeemResult, error)
}
Redeemer is a provider whose accounts can spend banked resets. requestID makes retries idempotent; an empty creditID lets the provider pick.
type Subscription ¶
type Subscription struct {
Status string `json:"status,omitempty"`
// Since is when the subscription started.
Since *time.Time `json:"since,omitempty"`
// Until is the end of the current paid period, when the provider says so.
Until *time.Time `json:"until,omitempty"`
Billing string `json:"billing,omitempty"`
CheckedAt time.Time `json:"checkedAt"`
// WebError explains why the renewal date couldn't be read through a web session.
WebError string `json:"webError,omitempty"`
// WebExpired means the web session no longer works and needs replacing.
WebExpired bool `json:"webExpired,omitempty"`
// RenewedSession is a fresh web session the provider handed out, to be stored in place
// of the old one.
RenewedSession string `json:"-"`
}
Subscription is what's known about the plan behind an account.
type SubscriptionSource ¶
type SubscriptionSource interface {
Subscription(ctx context.Context, c Credentials) (*Subscription, error)
}
SubscriptionSource is implemented by providers that can report subscription details.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package claude implements Claude (Anthropic OAuth / Claude Code subscription) accounts.
|
Package claude implements Claude (Anthropic OAuth / Claude Code subscription) accounts. |
|
Package codex implements ChatGPT/Codex subscription accounts.
|
Package codex implements ChatGPT/Codex subscription accounts. |