Documentation
¶
Overview ¶
Package auto is the composition root that selects and wires a concrete inference.Client for a validated Model. It imports every provider it can fully construct from (model, key) alone, so business logic depends only on the inference.Client interface — never on a concrete provider — and every credential/attestation decision is made here, once. Two providers it deliberately does NOT import take an input auto.New does not carry: Bedrock needs AWS SigV4 credentials, and Phala needs an attestation acceptance Policy. For each, New dispatches to a typed construct-directly error (SigV4NotConstructibleError, PolicyNotConstructibleError) that directs the caller to the named constructor rather than building a fail-open client with defaulted credentials. It maps a Provider to its client and enforces the provider's fail-closed auth contract before any network object is constructed.
Index ¶
- func New(selected model.Model, key auth.APIKey, opts ...Option) (inference.Client, error)
- func NewCounter(model model.Model, key auth.APIKey) (contextcount.ContextCounter, error)
- func NewWithAuth(selected model.Model, source credentials.Source, opts ...Option) (inference.Client, error)
- type CredentialNotConstructibleError
- type Option
- type PolicyNotConstructibleError
- type SigV4NotConstructibleError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New validates model, creates the compatibility source for its explicit API key, and delegates to NewWithAuth. Ordered:
- llm.ValidateModel — a self-contradictory or unknown-provider model yields a *model.ValidationError before anything else.
- Provider.RequiredAuth — an unknown provider fails closed with a *model.ValidationError (never a permissive default).
- A provider that requires an API key but is given none yields a *llm.AuthRequiredError. A provider requiring a special credential kind yields a *CredentialNotConstructibleError when the explicit credential is absent; auto.New never discovers special credentials from the environment.
- Dispatch on Provider to the concrete client.
No live I/O happens here; the returned inference.Client performs its own per-request guards (binding, validation, auth) when Invoke/Stream is called.
func NewCounter ¶
func NewCounter(model model.Model, key auth.APIKey) (contextcount.ContextCounter, error)
NewCounter validates model and resolves its exact provider context counter from the same (Model, APIKey) inputs accepted by New. It never performs provider I/O and never silently substitutes an estimator.
Error ordering is intentional: model validation runs first so unknown or contradictory models remain validation failures. Exact-counter support is then classified before API-key presence, so a known unsupported provider cannot be mistaken for a supported counter with a missing key. Providers with an exact counter perform the final fail-closed API-key validation in their constructors.
func NewWithAuth ¶
func NewWithAuth(selected model.Model, source credentials.Source, opts ...Option) (inference.Client, error)
NewWithAuth is the canonical credential-backed construction path. It binds a source to the exact provider/transport policy before returning a client; each request then acquires and verifies a fresh lease through credentialclient.
Types ¶
type CredentialNotConstructibleError ¶
CredentialNotConstructibleError is returned when auto.New would have to read or exchange a provider-specific credential from process state. The auto API accepts only an explicit auth.APIKey value, so callers must obtain the provider's OAuth/GCP/service-key/account token and pass it explicitly.
func (*CredentialNotConstructibleError) Error ¶
func (e *CredentialNotConstructibleError) Error() string
type Option ¶
type Option func(*options)
Option customizes construction for a provider-specific branch.
func WithOpenRouterOptions ¶
func WithOpenRouterOptions(opts ...openrouter.Option) Option
WithOpenRouterOptions applies OpenRouter-specific headers and request-body options. It is used only when selected.Provider is OpenRouter; supplying it for another provider is rejected by New.
func WithTLSRootCAs ¶
WithTLSRootCAs supplies a caller-owned verified certificate pool to supported generic clients; nil is rejected immediately.
type PolicyNotConstructibleError ¶
PolicyNotConstructibleError is returned by New for a provider that needs an attestation acceptance Policy auto.New cannot supply (currently Phala). auto.New's inputs are (model, key) only — it carries no Policy — so the caller must construct the client directly via the named constructor with their own verified policy. Fail-closed and directive, never a silent client with a defaulted policy.
func (*PolicyNotConstructibleError) Error ¶
func (e *PolicyNotConstructibleError) Error() string
type SigV4NotConstructibleError ¶
SigV4NotConstructibleError is returned by New for a provider whose required credential kind is AuthSigV4 (currently Bedrock). auto.New's only credential input is an auth.APIKey, which cannot carry AWS SigV4 credentials, so such a provider must be constructed directly via its own constructor (named by Use, e.g. "bedrock.New"). Fail-closed and directive — never a silent nil client. This is why auto does NOT import the bedrock package: it dispatches to an error, not to a constructor it cannot feed.
func (*SigV4NotConstructibleError) Error ¶
func (e *SigV4NotConstructibleError) Error() string