codexauth

package
v0.4.2-rc.2 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package codexauth signs a codeaf profile in to a ChatGPT plan in the same way the Codex CLI does, and adapts that plan's Responses API for codeaf's provider client. OpenAI's terms for a ChatGPT plan apply to work run on it.

Index

Constants

View Source
const (
	DefaultIssuer  = "https://auth.openai.com"
	DefaultBackend = "https://chatgpt.com/backend-api/codex"
	ClientID       = "app_EMoamEEZ73f0CkXaXp7hrann"
	Sentinel       = "chatgpt"
	Originator     = "codex_cli_rs"
)
View Source
const FallbackContextWindow = 272000

FallbackContextWindow is the window the account's own model list gave every visible model when it was last observed (2026-09-21, a Pro account: `"context_window": 272000` on each row). It is ONE figure because the fallback rows below are one observation, and a row that carried no window would leave a conversation that moved onto it compacting at its previous model's figure.

View Source
const QuotaWords = "codex reached your chatgpt plan's usage limit · it resets on its own"

QuotaWords is the person-facing outcome for a ChatGPT plan window that has been spent. The plan owns its reset, so there is no billing action to offer.

Variables

View Source
var ErrSignInExpired error = &signInExpiredError{}

ErrSignInExpired is the one actionable sentence returned when the issuer no longer accepts a profile's rotating refresh token.

View Source
var FallbackModels = []Model{
	{ID: "gpt-5.5", ContextLength: FallbackContextWindow},
	{ID: "gpt-5.6-sol", ContextLength: FallbackContextWindow},
	{ID: "gpt-5.6-terra", ContextLength: FallbackContextWindow},
	{ID: "gpt-5.6-luna", ContextLength: FallbackContextWindow},
}

FallbackModels is the last observed public list used when a fresh account listing cannot be reached during connection.

Functions

func Backend

func Backend() string

Backend returns the configured ChatGPT backend used by both listing and turns.

func Client

func Client(profileDir string) *http.Client

Client returns the refreshing and translating client for one profile.

func ClientWithOptions

func ClientWithOptions(profileDir string, options Options) *http.Client

ClientWithOptions returns the same client with deterministic test edges.

func Connected

func Connected(profileDir string) bool

Connected reports whether a usable sign-in currently exists.

func Issuer

func Issuer() string

Issuer returns the configured issuer without changing the fixed callback.

func ModelsPath

func ModelsPath(profileDir string) string

ModelsPath names the non-secret listing cached beside the tokens.

func Path

func Path(profileDir string) string

Path names the owner-readable token file in a profile.

func Remove

func Remove(profileDir string) error

Remove forgets the browser sign-in and its model listing.

func Save

func Save(profileDir string, tokens Tokens) error

Save replaces the token file with an owner-only file.

func Translate

func Translate(profileDir string, options Options) http.RoundTripper

Translate authenticates every backend request and translates the provider client's chat-completions path into the ChatGPT Responses API.

Types

type Flow

type Flow struct {
	// contains filtered or unexported fields
}

Flow is one browser connection whose fixed loopback listener is already standing when Begin returns.

func Begin

func Begin(ctx context.Context, options Options) (*Flow, error)

Begin starts the exact S256 loopback flow registered for the Codex CLI, trying its primary port and then its one fallback.

func (*Flow) Cancel

func (f *Flow) Cancel()

Cancel releases the fixed loopback listener. It is safe after Wait.

func (*Flow) URL

func (f *Flow) URL() string

URL is the one sign-in address the person opens.

func (*Flow) Wait

func (f *Flow) Wait(ctx context.Context) (Tokens, error)

Wait returns the token set after the browser has returned once.

type Model

type Model struct {
	ID string `json:"id"`
	// ContextLength is the listing's own `context_window`, zero when the row
	// carried none. It is what the session compacts against and what the status
	// line's meter is a share of, so a Codex model that dropped it kept whatever
	// window the conversation's previous model had (#1383).
	ContextLength   int      `json:"context_length,omitempty"`
	ReasoningLevels []string `json:"reasoning_levels,omitempty"`
}

Model is one model the signed-in account may choose, with how many tokens it accepts and the reasoning levels the request translator is allowed to send for it.

func List

func List(ctx context.Context, profileDir string, options Options) ([]Model, error)

List asks the account's own backend which models are visible and remembers the reasoning levels needed by later turns.

type Options

type Options struct {
	Issuer     string
	Backend    string
	HTTPClient *http.Client
	Random     io.Reader
	Listen     func(network, address string) (net.Listener, error)
	Now        func() time.Time
	SessionID  string
}

Options holds every replaceable edge of a Codex browser sign-in and its later backend calls. The zero value is the shipped service.

type Tokens

type Tokens struct {
	AccessToken  string    `json:"access_token"`
	RefreshToken string    `json:"refresh_token"`
	IDToken      string    `json:"id_token"`
	AccountID    string    `json:"account_id"`
	Email        string    `json:"email"`
	Plan         string    `json:"plan"`
	ExpiresAt    time.Time `json:"expires_at"`
	LastRefresh  time.Time `json:"last_refresh"`
}

Tokens is the complete durable answer from one browser sign-in.

func Load

func Load(profileDir string) (Tokens, error)

Load reads the current token set and immediately registers every credential with the record scrubber.

Jump to

Keyboard shortcuts

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