openai

package
v1.8.7 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: Apache-2.0 Imports: 4 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 openai implements the model_protocol adapter for the OpenAI protocol family (OpenAI chat/completions, DeepSeek, Groq and the OpenAI Responses API).

Index

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 New

func New() *Adapter

New returns the OpenAI-family protocol adapter.

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

func (a *Adapter) ExtraHeaders() map[string]string

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

func (a *Adapter) InjectAuth(outreq *bfe_http.Request, key string) error

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). 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 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.

func (*Adapter) Key

func (a *Adapter) Key() string

Jump to

Keyboard shortcuts

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