Documentation
¶
Overview ¶
Package openai implements the model_protocol adapter for the OpenAI protocol family (OpenAI chat/completions, DeepSeek, Groq and the OpenAI Responses API).
Index ¶
- type Adapter
- func (a *Adapter) ErrorNormalizer() utils.ErrorNormalizer
- func (a *Adapter) ExtraHeaders() map[string]string
- func (a *Adapter) ExtractUsageFields(data []byte) utils.UsageFields
- func (a *Adapter) InjectAuth(outreq *bfe_http.Request, key string) error
- func (a *Adapter) IsFinalUsageEvent(ev utils.StreamEvent) bool
- func (a *Adapter) IsStreamTerminal(ev utils.StreamEvent) bool
- func (a *Adapter) Key() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter struct{}
Adapter is the OpenAI-family protocol adapter. It is stateless.
func (*Adapter) ErrorNormalizer ¶
func (a *Adapter) ErrorNormalizer() utils.ErrorNormalizer
ErrorNormalizer returns the phase-1 default normalizer (never recognizes errors, callers keep their status-code whitelist).
func (*Adapter) ExtraHeaders ¶
ExtraHeaders returns nil: the OpenAI protocol needs no supplementary headers.
func (*Adapter) ExtractUsageFields ¶
func (a *Adapter) ExtractUsageFields(data []byte) utils.UsageFields
ExtractUsageFields extracts usage fields via the OpenAI main chain plus the DeepSeek and Responses API cache-read fallbacks (see utils.ParseOpenAIUsageFields).
func (*Adapter) InjectAuth ¶
InjectAuth writes the upstream credential as an Authorization: Bearer header. An empty key is a no-op.
func (*Adapter) IsFinalUsageEvent ¶
func (a *Adapter) IsFinalUsageEvent(ev utils.StreamEvent) bool
IsFinalUsageEvent carries the legacy hard-coded final-usage check: an Anthropic message_delta event, the Anthropic non-streaming top-level type "message", or a protocol-agnostic final usage chunk (an OpenAI stream_options.include_usage chunk has no top-level type). The Responses API response.completed event carries the final usage under response.usage (issue #1381). Without "message_delta" a cross-protocol stream (Bearer request detected as openai while the backend answers with an Anthropic body) would lose the final usage and be undercharged; without "message" the final usage of a non-streaming Anthropic JSON body would never be recognized (issue #1364).
func (*Adapter) IsStreamTerminal ¶
func (a *Adapter) IsStreamTerminal(ev utils.StreamEvent) bool
IsStreamTerminal carries the legacy hard-coded termination check that lived in mod_body_process.SSEEvent.GetQuotaUsage: an Anthropic-style message_stop event or the OpenAI [DONE] marker ends the stream. The Responses API terminal event response.completed (issue #1381) joins the rule; its usage arrives in the same event, so the stream is both terminated and finally billed there. The OpenAI adapter is also the registry fallback (unknown/empty auth styles), so it keeps the full combined rule to preserve the previous behavior for every request that does not identify a concrete protocol.