auto

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 67 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(selected model.Model, key auth.APIKey, opts ...Option) (inference.Client, error)

New validates model, creates the compatibility source for its explicit API key, and delegates to NewWithAuth. Ordered:

  1. llm.ValidateModel — a self-contradictory or unknown-provider model yields a *model.ValidationError before anything else.
  2. Provider.RequiredAuth — an unknown provider fails closed with a *model.ValidationError (never a permissive default).
  3. 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.
  4. 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

type CredentialNotConstructibleError struct {
	Provider llm.Provider
	Kind     auth.AuthKind
	Use      string
}

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

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

func WithTLSRootCAs(roots *x509.CertPool) Option

WithTLSRootCAs supplies a caller-owned verified certificate pool to supported generic clients; nil is rejected immediately.

type PolicyNotConstructibleError

type PolicyNotConstructibleError struct {
	Provider llm.Provider
	Use      string
}

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

type SigV4NotConstructibleError

type SigV4NotConstructibleError struct {
	Provider llm.Provider
	Use      string
}

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

Jump to

Keyboard shortcuts

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