codex

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Overview

Package codex is a provider speaking the Responses API.

Index

Constants

View Source
const (
	Endpoint = "https://chatgpt.com/backend-api/codex/responses"
	Model    = "gpt-5.6-sol"
	Effort   = "high"
	Summary  = "auto" // defined as the "most detailed summarizer available for a model"

	Originator = "io" // who we?
)

https://platform.openai.com/docs/api-reference/responses/create https://platform.openai.com/docs/guides/reasoning

Variables

View Source
var ErrIncomplete = errors.New("the response was cut short")

ErrIncomplete is a response the endpoint cut short, usually against a limit.

View Source
var ErrTruncated = sse.ErrTruncated

ErrTruncated is a stream that stopped without ever saying it was finished, which means the wire went quiet mid-turn rather than the model reaching an end.

View Source
var TokenURL string

TokenURL is the address credentials are traded at, and is the real one when left empty.

Functions

func CredentialsPath

func CredentialsPath() string

CredentialsPath is where Login writes and Auth reads.

func Login

func Login() error

Login authorises against a ChatGPT subscription and stores the credentials, printing the URL to visit and opening it where it can.

Types

type Client

type Client struct {
	URL    string // the endpoint address
	Model  string // the model to ask
	Effort string // how hard the model should reason
	// contains filtered or unexported fields
}

Client speaks the Responses API: one request per turn, answered as a stream of events.

https://platform.openai.com/docs/api-reference/responses/create https://platform.openai.com/docs/api-reference/responses-streaming https://platform.openai.com/docs/guides/conversation-state

func Auth

func Auth() *Client

Auth is a client on the credentials the login command stored.

func New

func New(tokens TokenSource) *Client

New builds a client that authorises every request with the given source.

https://platform.openai.com/docs/guides/prompt-caching

func (*Client) AddToolResults

func (self *Client) AddToolResults(results []agent.ToolResult)

AddToolResults appends this turn's tool call results to the conversation.

https://platform.openai.com/docs/guides/function-calling

func (*Client) AddUserMessage

func (self *Client) AddUserMessage(prompt string)

AddUserMessage appends a prompt to the conversation.

https://platform.openai.com/docs/guides/conversation-state

func (*Client) Configure

func (self *Client) Configure(instructions string, tools []tool.Definition)

Configure takes what every request in the session carries.

https://platform.openai.com/docs/guides/function-calling

func (*Client) Dump

func (self *Client) Dump() []json.RawMessage

Dump hands over the conversation so far, one item per entry, in the order the endpoint expects them back. New state is appended and earlier items are never replaced.

https://platform.openai.com/docs/guides/conversation-state

func (*Client) Load

func (self *Client) Load(items []json.RawMessage)

Load takes a conversation back, replacing whatever this client held.

func (*Client) Send

func (self *Client) Send(ctx context.Context, yield agent.Yield) (agent.Reply, error)

Send posts the conversation so far and reads the response.

https://platform.openai.com/docs/api-reference/responses-streaming

type Credentials

type Credentials struct {
	Access    string `json:"access"`     // the access token
	Refresh   string `json:"refresh"`    // the refresh token
	ExpiresAt int64  `json:"expires_at"` // when access expires
	AccountID string `json:"account_id"` // the ChatGPT account
}

Credentials are what a ChatGPT subscription was authorised as.

type Token

type Token struct {
	Access    string // the bearer token
	AccountID string // the ChatGPT account
}

Token is what one request is authorised with.

type TokenSource

type TokenSource interface {
	Token() (Token, error)
}

TokenSource hands over a token to make a request with.

func Static

func Static(access string, accountID string) TokenSource

Static is a token that is already held, and never changes.

func StoredCredentials

func StoredCredentials() TokenSource

StoredCredentials reads and refreshes credentials written by Login.

func StoredCredentialsAt

func StoredCredentialsAt(path string) TokenSource

StoredCredentialsAt reads credentials from path.

Jump to

Keyboard shortcuts

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