Documentation
¶
Overview ¶
Package compat contains the deliberately small shared core used by documented providers whose public endpoint is compatible with one of the bundled request codecs. Provider packages still own identity, defaults, authentication policy, options, and any provider-specific response normalization.
Index ¶
- func New(selected model.Model, config Config) (inference.Client, error)
- func NewProvider(selected model.Model, key auth.APIKey, definition Definition, ...) (inference.Client, error)
- func NormalizeOpenAIReasoning(body []byte) ([]byte, error)
- func NormalizeOpenAIReasoningStream(response *http.Response) (*http.Response, error)
- func UnsupportedCounter(provider llm.Provider, apiFormat model.APIFormat) (contextcount.ContextCounter, error)
- type Config
- type Definition
- type MissingAuthenticatorError
- type Option
- type ProviderOptions
- type UnsupportedAuthenticationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New constructs a transport-backed client for an already validated provider model. The model's APIFormat selects the bundled semantic codec; Path may override the codec's conventional route when a compatible provider uses a documented proxy path.
func NewProvider ¶
func NewProvider(selected model.Model, key auth.APIKey, definition Definition, options ...Option) (inference.Client, error)
NewProvider resolves the selected model's default endpoint, builds the appropriate generic authenticator, and delegates semantic encoding/decoding to New. It supports only AuthNone and AuthAPIKey; special credential providers must use their own constructors.
func NormalizeOpenAIReasoning ¶
NormalizeOpenAIReasoning accepts the common provider aliases used by OpenAI-compatible gateways and emits the shared inference codec's canonical reasoning_content field. It is deliberately scoped to string aliases used in Chat Completions responses; Responses API reasoning has its own codec.
func NormalizeOpenAIReasoningStream ¶
NormalizeOpenAIReasoningStream applies the same normalization lazily to SSE data frames, preserving streaming instead of buffering the provider response.
func UnsupportedCounter ¶
func UnsupportedCounter(provider llm.Provider, apiFormat model.APIFormat) (contextcount.ContextCounter, error)
UnsupportedCounter returns the explicit exact-counter boundary shared by providers that document no matching token-count endpoint.
Types ¶
type Config ¶
type Config struct {
Authenticator auth.Authenticator
Headers http.Header
Path string
PatchHeaders func(inference.Request, http.Header)
PatchRequest func(map[string]json.RawMessage) error
NormalizeResponse func([]byte) ([]byte, error)
NormalizeStream func(*http.Response) (*http.Response, error)
}
Config customizes one compatibility-backed provider client. Provider packages should construct this value from their public options rather than exposing it directly as their own public API.
type Definition ¶
type Definition struct {
Provider llm.Provider
DefaultBaseURL string
DefaultPath string
Authentication auth.AuthKind
KeyHeader string
Authenticator func(auth.APIKey) (auth.Authenticator, error)
PatchHeaders func(inference.Request, http.Header)
NormalizeResponse func([]byte) ([]byte, error)
NormalizeStream func(*http.Response) (*http.Response, error)
}
Definition contains immutable wire and policy facts for one simple provider. It is intentionally assembled by a public provider package, never discovered from an arbitrary model string.
type MissingAuthenticatorError ¶
type MissingAuthenticatorError struct{}
MissingAuthenticatorError reports a provider construction bug before any transport is created. Passing auth.None() is the explicit no-auth choice.
func (*MissingAuthenticatorError) Error ¶
func (e *MissingAuthenticatorError) Error() string
type Option ¶
type Option func(*ProviderOptions)
Option customizes ProviderOptions.
func WithBodyField ¶
WithBodyField adds one JSON body field. The value is marshaled when the option is applied; unsupported values are retained as an option error and returned by NewProvider before any client is built.
func WithBodyPatch ¶
func WithBodyPatch(patch func(map[string]json.RawMessage) error) Option
WithBodyPatch applies a provider-local patch after common fields are merged.
func WithHeader ¶
WithHeader adds one documented static request header.
type ProviderOptions ¶
type ProviderOptions struct {
Headers http.Header
Path string
BodyFields map[string]json.RawMessage
PatchRequest func(map[string]json.RawMessage) error
// contains filtered or unexported fields
}
ProviderOptions is the common option state accepted by simple provider packages. Provider-specific packages expose only the option functions that their official documentation supports.
type UnsupportedAuthenticationError ¶
UnsupportedAuthenticationError is returned when a simple provider wrapper is accidentally used for an OAuth, GCP, service-key, or account-token flow.
func (*UnsupportedAuthenticationError) Error ¶
func (e *UnsupportedAuthenticationError) Error() string