Documentation
¶
Overview ¶
Package openairesponses is a reference backend emulator for the OpenAI Responses API. It serves POST /v1/responses (or any path suffix /responses) with JSON or SSE bodies compatible with github.com/openai/openai-go/v3.
Index ¶
- func CheckInputItems(body []byte, want []InputItemExpect) error
- func CheckReasoningInput(body []byte, want []ReasoningInputExpect) error
- func NewHandler(cfg Config) http.Handler
- func ScriptedTurnJSON(turn ScriptedTurn) string
- func ScriptedTurnSSE(turn ScriptedTurn) string
- type Config
- type EncryptedPresence
- type InputItemExpect
- type OracleLedger
- type ReasoningInputExpect
- type ReasoningOutputItem
- type Request
- type RequestValidator
- type Responder
- type Response
- type ScriptedPart
- type ScriptedTurn
- type TextPart
- type ToolCall
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckInputItems ¶
func CheckInputItems(body []byte, want []InputItemExpect) error
func CheckReasoningInput ¶
func CheckReasoningInput(body []byte, want []ReasoningInputExpect) error
func NewHandler ¶
NewHandler returns an http.Handler that emulates POST …/responses for the official SDK.
func ScriptedTurnJSON ¶
func ScriptedTurnJSON(turn ScriptedTurn) string
func ScriptedTurnSSE ¶
func ScriptedTurnSSE(turn ScriptedTurn) string
Types ¶
type Config ¶
type Config struct {
// AllowMissingBearer, if true, skips the Authorization: Bearer check.
AllowMissingBearer bool
// OnAuthorizedCredential is invoked after local auth passes with the raw bearer
// secret (Authorization without the "Bearer " prefix). Do not log this value.
OnAuthorizedCredential func(secret string)
// ForcedHTTPStatus, when http.StatusUnauthorized or http.StatusTooManyRequests, returns
// that status with a provider-shaped JSON error instead of success (stream or JSON).
ForcedHTTPStatus int
// ForcedRetryAfter is sent as Retry-After when ForcedHTTPStatus is 429.
ForcedRetryAfter string
// ForcedErrorJSON overrides the forced-error JSON body; when empty a minimal default is used.
ForcedErrorJSON string
// OnRequestBody is invoked with the full request body after a successful route/auth
// check and before the response is written.
OnRequestBody func(body []byte)
// Responder, when non-nil and ForcedHTTPStatus is zero, builds the HTTP response
// per request. Must be safe for concurrent use.
Responder Responder
// NonStreamJSON overrides the JSON body for non-streaming responses. When empty, a
// minimal completed response is returned.
NonStreamJSON string
// StreamSSE overrides the full SSE payload for streaming responses. When empty, a
// minimal response.completed plus [DONE] stream is returned.
StreamSSE string
}
Config tunes the emulator handler.
Response precedence after route/auth succeed:
- ForcedHTTPStatus (when non-zero) — Responder is not invoked
- Responder (when non-nil) — overrides NonStreamJSON / StreamSSE / defaults
- NonStreamJSON / StreamSSE fixed overrides
- built-in default JSON / SSE bodies
type EncryptedPresence ¶
type EncryptedPresence string
const ( EncryptedAbsent EncryptedPresence = "absent" EncryptedNull EncryptedPresence = "null" EncryptedEmpty EncryptedPresence = "empty" EncryptedValue EncryptedPresence = "value" )
type InputItemExpect ¶
type InputItemExpect struct {
Kind string // reasoning|message|function_call
Label string
ToolName string
Reasoning *ReasoningInputExpect
}
type OracleLedger ¶
type OracleLedger struct {
// contains filtered or unexported fields
}
func NewOracleLedger ¶
func NewOracleLedger(validators ...RequestValidator) *OracleLedger
func (*OracleLedger) Count ¶
func (l *OracleLedger) Count() int
func (*OracleLedger) Err ¶
func (l *OracleLedger) Err() error
func (*OracleLedger) Hook ¶
func (l *OracleLedger) Hook() func([]byte)
func (*OracleLedger) Observe ¶
func (l *OracleLedger) Observe(body []byte)
type ReasoningInputExpect ¶
type ReasoningOutputItem ¶
type RequestValidator ¶
func ExpectInputItems ¶
func ExpectInputItems(want []InputItemExpect) RequestValidator
func ExpectNoReasoningInput ¶
func ExpectNoReasoningInput() RequestValidator
func ExpectReasoningInput ¶
func ExpectReasoningInput(want []ReasoningInputExpect) RequestValidator
type Responder ¶
func ScriptedResponder ¶
func ScriptedResponder(turns []ScriptedTurn) Responder
type ScriptedPart ¶
type ScriptedPart struct {
Reasoning *ReasoningOutputItem
Message string
Tool *ToolCall
}
ScriptedPart is one ordered output item. Exactly one of Reasoning, Message, or Tool is set.
type ScriptedTurn ¶
type ScriptedTurn struct {
ResponseID string
Parts []ScriptedPart
Reasoning []ReasoningOutputItem
VisibleText string
Tool *ToolCall
}
Click to show internal directories.
Click to hide internal directories.