responses

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 11 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 responses models the Codex Responses request as the proxy sees it: the body fields the router reads or rewrites (model, reasoning.effort, input items), the turn metadata header, the request kind, and the usage reported in the response.completed SSE event. Every other byte passes through.

Index

Constants

View Source
const (
	TypeMessage              = "message"
	TypeFunctionCall         = "function_call"
	TypeFunctionCallOutput   = "function_call_output"
	TypeCustomToolCall       = "custom_tool_call"
	TypeCustomToolCallOutput = "custom_tool_call_output"
	TypeLocalShellCall       = "local_shell_call"
	TypeReasoning            = "reasoning"
)

Input item types the router decodes. Other types keep only Type.

View Source
const (
	HeaderTurnMetadata = "X-Codex-Turn-Metadata"
	HeaderSubagent     = "X-Openai-Subagent"
	// HeaderAccount is the ChatGPT account the request bills to. Only its
	// hash (Meta.Account) leaves the proxy; the raw value goes upstream only.
	HeaderAccount = "ChatGPT-Account-ID"
)

Request headers the proxy reads.

View Source
const (
	HeaderModel  = "Openai-Model"
	HeaderXModel = "X-Openai-Model"
)

Response headers the proxy strips: Codex reads them as the served model and warns on a mismatch (research §3.1).

View Source
const RequestKindTurn = "turn"

RequestKindTurn is the x-codex-turn-metadata request_kind of a user step. Compaction (local and remote v2) sends "compaction" (research §9, spike 1c).

View Source
const ThreadSourceUser = "user"

ThreadSourceUser is the x-codex-turn-metadata thread_source of a thread the user started. Codex 0.162.1 runs side work in its own threads with another source: subagent, guardian_review, memory_consolidation, or a feature name such as thread_title (the footer's title, generated after the first prompt).

Variables

This section is empty.

Functions

func AccountHash added in v0.3.0

func AccountHash(id string) string

AccountHash is the first 12 hex of sha256(id), or "" for an empty id (plan M12). Engines and link frames see only this, never the raw id.

Types

type Item

type Item struct {
	Type      string
	Role      string
	ID        string
	Name      string
	CallID    string
	Text      string
	Output    string
	Arguments string
}

Item is one input item, flattened. Fields not used by a type stay empty; unknown types keep only Type.

type Kind

type Kind string

Kind says whether a request is a routable user step or must pass through unchanged (compaction, subagent, any other or unknown request kind).

const (
	KindUserStep    Kind = "user-step"
	KindPassthrough Kind = "passthrough"
)

func Classify

func Classify(m Meta) Kind

Classify applies plan decision D5 as spike 1c settled it: only a main-thread turn request is a user step. Compaction, any other request kind, missing metadata, a missing turn ID, every subagent request and a thread of any source but the user's pass through. A missing thread source counts as the user's.

type Meta

type Meta struct {
	SessionID    string
	ThreadID     string
	TurnID       string
	RequestKind  string
	ThreadSource string
	Subagent     string
	Account      string
}

Meta is the parsed x-codex-turn-metadata header plus the subagent header. RequestKind is "turn" for a user step, "compaction" for a compaction request. ThreadSource says who started the thread. Account is AccountHash of the ChatGPT-Account-ID header, empty when it is missing.

func ParseMeta

func ParseMeta(h http.Header) Meta

ParseMeta reads the turn metadata, subagent and account headers. A missing or unparseable turn metadata header leaves the metadata fields empty.

type Request

type Request struct {
	Model  string
	Effort config.Effort
	Input  []Item
	Bytes  int
	// contains filtered or unexported fields
}

Request is the parsed body. Bytes is the raw body length; the raw body is kept inside for Apply.

func Parse

func Parse(body []byte) (*Request, error)

Parse reads model, reasoning.effort and input items from a Responses request body. The body must be a JSON object with a string model.

func (*Request) Apply

func (r *Request) Apply(rw Rewrite) ([]byte, error)

Apply returns the body with model and reasoning.effort set from rw. Only those values change; every other byte, including key order and whitespace, stays as Codex sent it. An absent reasoning object is added with the effort only. A no-op rewrite returns the original body, which the caller must not modify.

func (*Request) Body added in v0.3.0

func (r *Request) Body() []byte

Body returns the raw body Parse read, which the caller must not modify.

func (*Request) Fingerprint

func (r *Request) Fingerprint(m Meta) string

Fingerprint identifies one request of a turn. Retries of a request resend the same body, so they share it; each later step of the turn appends items, so it changes. It hashes the original model, not a rewrite.

type Rewrite

type Rewrite struct {
	Model  string
	Effort config.Effort
}

Rewrite is what the router changes: model and reasoning.effort. An empty Effort keeps the effort Codex sent.

type Usage

type Usage struct {
	InputTokens       int
	CachedInputTokens int
	OutputTokens      int
	TotalTokens       int
}

Usage is the usage block of response.completed.

func UsageFromSSE

func UsageFromSSE(event []byte) (Usage, string, bool)

UsageFromSSE reads one SSE event, either the whole event block ("event: …\ndata: {…}") or just its data payload. For response.completed it returns the usage, the served model and true; for any other event, false.

Jump to

Keyboard shortcuts

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