skip

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 2 Imported by: ? 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 skip answers one host question: should the host call accountant.Request.Compute for a finished request, and if not, why (the host wiring document in docs/, W6.1)? Every provider-API proxy built on accountant asks it, and each wrote the same answer on its own before this package existed (accountant#150).

The decision is structural: it reads only facts the host already knows before the library prices anything -- the upstream status, the number of upstream rounds, whether the request has a session, whether the prompt history is held at the provider, and whether a body rewrite could not be placed. It does NOT read the usage, nor whether the figure is priceable: that is a separate axis the two hosts order differently, so it stays with the host (see Reason's doc comment).

This module is separate from the accountant root module because ServerHeldHistory parses a wire body with gjson, and the root module imports only the standard library (R3). The package still knows no host: no sweep, no preset, no host component name, only generic request facts.

Index

Constants

View Source
const (
	// ReasonNoRecord: the request opened no accounting record, because it has no session. The thread
	// key (design §5.4) needs one. A request with no record is skipped before its status matters.
	ReasonNoRecord = "no_record"
	// ReasonServerHeldHistory: an OpenAI Responses request whose prompt history the provider holds
	// (previous_response_id, conversation, or an item_reference input item). The body the host sees
	// holds only the new turn, and the library would read the missing history as a client edit
	// (W6.1). It is a fact of the request's shape, known before the response, so it is skipped before
	// either upstream-rejection reason.
	ReasonServerHeldHistory = "server_held_history"
	// ReasonRejectedStatus: the provider answered with a status that is not 2xx and not 0. The
	// provider billed none of the request, so it saved nothing. A 4xx or 5xx body can still carry a
	// usage object; the saving is still zero.
	ReasonRejectedStatus = "rejected_status"
	// ReasonDeferralUnplaced: a body rewrite (a host's tool deferral, or a plugin's billed-body hook)
	// could not be described to the library. Computing on the bodies as they are would fail the
	// library's sum check, so no figure is computed.
	ReasonDeferralUnplaced = "deferral_unplaced"
)

The reasons Reason returns. Where a host already logs a reason detail string for one of these cases, it is kept the same, so a reader who greps that host's log line for a reason finds the same string here. upstream_rounds carries the round count, so it has a prefix, not a fixed string.

Variables

This section is empty.

Functions

func Reason

func Reason(in Input) string

Reason says why Compute must not be called for this request, or "" to say it should be called.

The ORDER of the tests is load-bearing, not cosmetic, and both hosts share it:

  1. No session first: a request with no session opened no record at all, so no later reason can apply to a record that does not exist. A rejected request with no session is still ReasonNoRecord, not ReasonRejectedStatus.
  2. Server-held history next: it is a fact of the request's shape, known before the response is, so it is decided before either reason that reads the status.
  3. Then the rejection, then the unplaced deferral, then the multi-round count.

Reason does NOT test the usage. Whether the response reported a usable, priceable usage is a separate pricing-gate axis (the host wiring document's W6.5, "unpriced"), and the two hosts order it differently against these structural reasons: one checks usage before any of these reasons, another checks usage only after Reason passes. So each host applies its own usage check at its own call site, around Reason's answer; this package stays structural and generic. A library panic is the same: it is the result of the Compute call, caught by the host's own recover wrapper, not a fact known before the call, so it is a host reason, not an Input field.

func Rejected

func Rejected(status int) bool

Rejected reports whether the provider rejected the request: a status that is not 0 and not 2xx. Status 0 means no provider was reached (a request the proxy answered itself), which is not a rejection. It is exported because both hosts call it on its own, not only inside Reason (for example, to skip booking a cache miss for a rejected response).

func ServerHeldHistory

func ServerHeldHistory(body []byte) bool

ServerHeldHistory reports whether an OpenAI Responses body leaves part of its prompt on the provider's side, so the host cannot see the prefix the provider reads. It is true for:

  • previous_response_id (the earlier turns of a response chain);
  • conversation (a stored conversation's items, a string id or an object);
  • an input item of type item_reference (an item the provider expands from its own store).

A host passes the result as Input.ServerHeldHistory. The host decides first that the request is on the Responses wire (its own routing knows the dialect); this function then reads only the body.

Types

type Input

type Input struct {
	// Status is the upstream response status. 0 means no provider answered (for example, a request
	// the host answered itself): that is not a rejection.
	Status int
	// Rounds is the number of upstream round trips this one client request caused. More than one
	// means a single usage object does not describe a single forwarded body.
	Rounds int
	// SessionID is empty when the request has no session. Then it opened no accounting record at all,
	// and Reason returns ReasonNoRecord regardless of every other field.
	SessionID string
	// ServerHeldHistory is true when the provider holds part of the prompt (see
	// ReasonServerHeldHistory). ServerHeldHistory in this package computes it from the body.
	ServerHeldHistory bool
	// UnplacedDeferral is true when a body rewrite could not be described to the library (see
	// ReasonDeferralUnplaced).
	UnplacedDeferral bool
}

Input is what the host knows about a finished request before it decides whether to call accountant.Request.Compute (W6.1). Every field is a plain, generic fact; a host maps its own concepts onto them.

Jump to

Keyboard shortcuts

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