codex

package
v2.1.0-alpha.23 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package codex provides a raw model.Provider for ChatGPT-backed Codex subscription access. It targets a private and volatile wire contract at a fixed trusted endpoint. Applications own login, token refresh, persistence, and credential policy and inject current credentials for each request.

The provider supports SSE, fresh-per-request WebSockets, and WebSocket-first automatic selection with one safe pre-output SSE fallback. It does not read environment variables, Codex CLI state, home-directory files, or keychains, and it does not implement model.TokenCounter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client implements model.Provider through the private ChatGPT Codex Responses wire contract. It intentionally does not implement model.TokenCounter.

func New

func New(options Options) (*Client, error)

New constructs a Codex subscription provider with injected credentials.

func (*Client) Complete

func (c *Client) Complete(ctx context.Context, request *model.Request) (*model.Response, error)

Complete consumes a Codex stream to literal EOF and returns its terminal response.

func (*Client) Stream

func (c *Client) Stream(ctx context.Context, request *model.Request) (model.Streamer, error)

Stream validates and starts a raw Codex stream.

type CredentialSource

type CredentialSource interface {
	Credentials(context.Context) (Credentials, error)
}

CredentialSource resolves current Codex credentials for each logical request.

type CredentialSourceFunc

type CredentialSourceFunc func(context.Context) (Credentials, error)

CredentialSourceFunc adapts a function into a CredentialSource.

func (CredentialSourceFunc) Credentials

func (f CredentialSourceFunc) Credentials(ctx context.Context) (Credentials, error)

Credentials resolves credentials through f.

type Credentials

type Credentials struct {
	AccessToken string
	AccountID   string
	Residency   string
}

Credentials contains application-owned credentials for one Codex request.

type Options

type Options struct {
	CredentialSource  CredentialSource
	HTTPClient        *http.Client
	WebSocketDialer   *websocket.Dialer
	Transport         Transport
	ClientVersion     string
	ResponsesLite     bool
	StreamIdleTimeout time.Duration
	DefaultModel      string
	HighModel         string
	SmallModel        string
}

Options configures the Codex subscription provider.

type Transport

type Transport uint8

Transport selects the Codex streaming transport.

const (
	// TransportAuto prefers WebSocket and safely falls back to SSE before output.
	TransportAuto Transport = iota
	// TransportSSE uses streamable HTTP server-sent events.
	TransportSSE
	// TransportWebSocket uses one fresh WebSocket per request.
	TransportWebSocket
)

Jump to

Keyboard shortcuts

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