Documentation
¶
Overview ¶
Package codex implements ChatGPT/Codex subscription accounts.
Index ¶
- Constants
- Variables
- func AppendImageTool(body []byte, plan string) []byte
- func ImportCredentials(raw []byte) (provider.Credentials, provider.Identity, error)
- func PrepareResponses(body []byte, baseModel, effort, cacheKey string) ([]byte, error)
- func UsageLimitReset(body string) (resetUnix int64, isUsageLimit bool)
- func WindowsFromHeaders(h http.Header, now time.Time) (windows []quota.Window, plan string)
- type DeviceCode
- type Provider
- func (p *Provider) AuthURL(state, challenge string) string
- func (p *Provider) ClientModels(ctx context.Context, c provider.Credentials, clientVersion string) ([]byte, error)
- func (p *Provider) Compact(ctx context.Context, c provider.Credentials, body []byte, ...) (*http.Response, error)
- func (p *Provider) Exchange(ctx context.Context, code, verifier string) (provider.Credentials, provider.Identity, error)
- func (p *Provider) FetchQuota(ctx context.Context, c provider.Credentials) (*quota.Snapshot, error)
- func (p *Provider) ID() string
- func (p *Provider) Ping(ctx context.Context, c provider.Credentials, model, prompt string) (*provider.PingResult, error)
- func (p *Provider) PollDevice(ctx context.Context, dc *DeviceCode) (provider.Credentials, provider.Identity, error)
- func (p *Provider) Redeem(ctx context.Context, c provider.Credentials, requestID, creditID string) (*provider.RedeemResult, error)
- func (p *Provider) Refresh(ctx context.Context, c provider.Credentials) (provider.Credentials, provider.Identity, error)
- func (p *Provider) RefreshLead() time.Duration
- func (p *Provider) ResetCredits(ctx context.Context, c provider.Credentials) ([]quota.BankedCredit, error)
- func (p *Provider) Send(ctx context.Context, c provider.Credentials, body []byte, ...) (*http.Response, error)
- func (p *Provider) SendSearch(ctx context.Context, c provider.Credentials, body []byte, ...) (*http.Response, error)
- func (p *Provider) StartDevice(ctx context.Context) (*DeviceCode, error)
- func (p *Provider) Subscription(_ context.Context, c provider.Credentials) (*provider.Subscription, error)
Constants ¶
const ( RedirectURI = "http://localhost:1455/auth/callback" DeviceVerifyURL = "https://auth.openai.com/codex/device" )
Variables ¶
var ErrPending = errors.New("authorization pending")
ErrPending means the user hasn't approved the device code yet.
Functions ¶
func AppendImageTool ¶
AppendImageTool adds the image_generation tool so the model can draw, unless the plan or model can't use it or the request already has it.
func ImportCredentials ¶
ImportCredentials accepts maitake's format, CLIProxyAPI auth files, and Codex CLI's ~/.codex/auth.json.
func PrepareResponses ¶
PrepareResponses normalizes a Responses API request for the Codex backend.
func UsageLimitReset ¶
UsageLimitReset extracts the reset time (unix seconds) from a usage_limit_reached error body.
Types ¶
type DeviceCode ¶
DeviceCode is an in-progress device login.
type Provider ¶
type Provider struct {
// BackendBase is overridable for tests.
BackendBase string
// contains filtered or unexported fields
}
func (*Provider) ClientModels ¶
func (p *Provider) ClientModels(ctx context.Context, c provider.Credentials, clientVersion string) ([]byte, error)
ClientModels fetches the model catalog the Codex CLI shows, as ChatGPT serves it for a client version: per-model instructions, reasoning levels and tool settings.
func (*Provider) Compact ¶
func (p *Provider) Compact(ctx context.Context, c provider.Credentials, body []byte, clientHeaders http.Header) (*http.Response, error)
Compact posts to the non-streaming compaction endpoint and returns its JSON response.
func (*Provider) FetchQuota ¶
FetchQuota polls /wham/usage (the data behind ChatGPT's Codex usage page) plus banked reset credits.
func (*Provider) Ping ¶
func (p *Provider) Ping(ctx context.Context, c provider.Credentials, model, prompt string) (*provider.PingResult, error)
Ping sends the smallest Responses request the Codex backend accepts. model may carry an effort suffix, e.g. "gpt-5.6-luna(low)".
func (*Provider) PollDevice ¶
func (p *Provider) PollDevice(ctx context.Context, dc *DeviceCode) (provider.Credentials, provider.Identity, error)
PollDevice checks once whether the device code was approved and, if so, completes the login.
func (*Provider) Redeem ¶
func (p *Provider) Redeem(ctx context.Context, c provider.Credentials, requestID, creditID string) (*provider.RedeemResult, error)
Redeem spends one banked reset. requestID makes retries idempotent.
func (*Provider) Refresh ¶
func (p *Provider) Refresh(ctx context.Context, c provider.Credentials) (provider.Credentials, provider.Identity, error)
func (*Provider) RefreshLead ¶
func (*Provider) ResetCredits ¶
func (p *Provider) ResetCredits(ctx context.Context, c provider.Credentials) ([]quota.BankedCredit, error)
func (*Provider) Send ¶
func (p *Provider) Send(ctx context.Context, c provider.Credentials, body []byte, clientHeaders http.Header) (*http.Response, error)
Send posts a prepared Responses body to the Codex backend; the response is always SSE.
func (*Provider) SendSearch ¶
func (p *Provider) SendSearch(ctx context.Context, c provider.Credentials, body []byte, clientHeaders http.Header) (*http.Response, error)
SendSearch forwards a Codex CLI /alpha/search request.
func (*Provider) StartDevice ¶
func (p *Provider) StartDevice(ctx context.Context) (*DeviceCode, error)
func (*Provider) Subscription ¶
func (p *Provider) Subscription(_ context.Context, c provider.Credentials) (*provider.Subscription, error)
Subscription reads the plan period from the id_token's ChatGPT claims; no request needed.