codex

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 codex implements ChatGPT/Codex subscription accounts.

Index

Constants

View Source
const (
	RedirectURI = "http://localhost:1455/auth/callback"

	DeviceVerifyURL = "https://auth.openai.com/codex/device"
)

Variables

View Source
var ErrPending = errors.New("authorization pending")

ErrPending means the user hasn't approved the device code yet.

Functions

func AppendImageTool

func AppendImageTool(body []byte, plan string) []byte

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

func ImportCredentials(raw []byte) (provider.Credentials, provider.Identity, error)

ImportCredentials accepts maitake's format, CLIProxyAPI auth files, and Codex CLI's ~/.codex/auth.json.

func PrepareResponses

func PrepareResponses(body []byte, baseModel, effort, cacheKey string) ([]byte, error)

PrepareResponses normalizes a Responses API request for the Codex backend.

func UsageLimitReset

func UsageLimitReset(body string) (resetUnix int64, isUsageLimit bool)

UsageLimitReset extracts the reset time (unix seconds) from a usage_limit_reached error body.

func WindowsFromHeaders

func WindowsFromHeaders(h http.Header, now time.Time) (windows []quota.Window, plan string)

WindowsFromHeaders reads x-codex-{primary,secondary}-* headers from a Codex response.

Types

type DeviceCode

type DeviceCode struct {
	DeviceAuthID string
	UserCode     string
	Interval     time.Duration
}

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 New

func New(client *http.Client) *Provider

func (*Provider) AuthURL

func (p *Provider) AuthURL(state, challenge string) string

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) Exchange

func (p *Provider) Exchange(ctx context.Context, code, verifier string) (provider.Credentials, provider.Identity, error)

func (*Provider) FetchQuota

func (p *Provider) FetchQuota(ctx context.Context, c provider.Credentials) (*quota.Snapshot, error)

FetchQuota polls /wham/usage (the data behind ChatGPT's Codex usage page) plus banked reset credits.

func (*Provider) ID

func (p *Provider) ID() string

func (*Provider) ListModels added in v0.9.0

func (p *Provider) ListModels(ctx context.Context, c provider.Credentials) ([]models.Listed, error)

ListModels reports the models this account can use. Anything not "list" visibility counts as a preview.

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

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 (*Provider) RefreshLead

func (p *Provider) RefreshLead() time.Duration

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

Subscription reads the plan period from the id_token's ChatGPT claims; no request needed.

Jump to

Keyboard shortcuts

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