provider

package
v0.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
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

func Decompress(resp *http.Response) error

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 DoJSON

func DoJSON(client *http.Client, req *http.Request, dst any) error

DoJSON sends req and decodes a 2xx JSON response into dst.

func JWTClaims

func JWTClaims(token string) (map[string]any, error)

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

func ParseCallback(input string) (code, state string)

ParseCallback extracts code and state from a pasted OAuth callback URL, a bare query string, or a raw "code#state" value.

func ParseTime

func ParseTime(v any) *time.Time

ParseTime reads an RFC 3339 timestamp, returning nil when empty or malformed.

func RandomHex

func RandomHex(n int) string

func ReadError

func ReadError(resp *http.Response) error

ReadError drains a failed response into an *HTTPError.

func UUID

func UUID() string

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 HTTPError

type HTTPError struct {
	Status int
	Body   string
	Header http.Header
}

HTTPError is a non-2xx upstream response.

func (*HTTPError) Error

func (e *HTTPError) Error() 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 ModelLister added in v0.9.0

type ModelLister interface {
	ListModels(ctx context.Context, c Credentials) ([]models.Listed, error)
}

ModelLister is a provider that can say which models an account may use.

type PingResult

type PingResult struct {
	Status  int
	Windows []quota.Window
	Plan    string
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL