providers

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 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 providers holds the catalogue of well-known LLM providers and the logic to connect one, shared by the TUI picker and the CLI so both stay in sync.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Activate

func Activate(cfg *config.Config, id, key string)

Activate records credentials (when a key is given), makes the provider the active one, and points the default model at it when the current one doesn't belong to it. It mutates cfg but does not persist — the caller saves.

func AllowedProviders added in v0.4.0

func AllowedProviders() map[string]bool

AllowedProviders returns a copy of the shared allowlist keyed by models.dev provider id. Callers outside this package (notably the build-time sync script) use it to guarantee the runtime and the bundled snapshot agree on which providers are supported. The copy is intentional: nothing external should mutate the runtime table.

func Connected

func Connected(cfg *config.Config, id string) bool

Connected reports whether a provider already has a usable credential (an API key in config, a set key-env, or being a local provider that needs none).

func ContextWindow added in v0.3.0

func ContextWindow(model string) int

ContextWindow returns the known context window for a model id, walking the same cascade as Meta(): hand-curated overrides → generated models.dev snapshot → 0 when nothing knows. Callers layer their own user-config overrides on top; this function stays package-local by design.

func FetchModelInfos added in v0.4.0

func FetchModelInfos(ctx context.Context, cfg *config.Config, providerID string) ([]llm.ModelInfo, error)

FetchModelInfos is FetchModels' richer cousin: same live /models probe but keeps every field the adapter fills in (context window, capability flags, pricing when the provider reports it). Callers that render a picker with window/cost badges should use this; callers that only need ids call FetchModels and stay allocation-light.

func FetchModels

func FetchModels(ctx context.Context, cfg *config.Config, providerID string) ([]string, error)

FetchModels queries a provider's /models endpoint for the model ids it offers, the same way the dashboard does. This surfaces models a custom or dynamic provider exposes even when they are not listed statically in the config.

func StartRefresh added in v0.4.0

func StartRefresh(ctx context.Context)

StartRefresh kicks off the background pull, if fetching is enabled. Safe to call from any goroutine; only the first call spawns the loop. Idempotent so unit tests and cmd/antares wiring can both invoke it without contract.

The caller passes a context that scopes the goroutine's lifetime — pass the runtime's root context so the loop exits when the process shuts down. A nil context is treated as context.Background() for one-shot uses.

Types

type Cost added in v0.4.0

type Cost struct {
	Input      float64 `json:"input,omitempty"`
	Output     float64 `json:"output,omitempty"`
	CacheRead  float64 `json:"cache_read,omitempty"`
	CacheWrite float64 `json:"cache_write,omitempty"`
}

Cost is per 1M-token pricing in USD, matching the models.dev unit.

func (Cost) HasCost added in v0.4.0

func (c Cost) HasCost() bool

HasCost reports whether the entry carries any pricing data at all — used to decide whether the dashboard should draw a "$3/M in" chip or hide the field.

type Info

type Info struct {
	ID       string
	Label    string
	Kind     string
	KeyEnv   string
	BaseURL  string
	NeedsKey bool
	Models   []string
}

Info describes a provider users can connect to in one step.

func Catalog

func Catalog() []Info

Catalog returns the well-known providers, in display order.

func Connect added in v0.4.0

func Connect(cfg *config.Config, id, key string) (Info, bool)

Connect records credentials (when a key is given) and configures a provider. It mutates cfg but does not persist — the caller saves.

func For

func For(id string) (Info, bool)

For looks up a catalogue entry by id.

type ModelMeta added in v0.4.0

type ModelMeta struct {
	Provider        string `json:"provider,omitempty"`
	ID              string `json:"id,omitempty"`
	Name            string `json:"name,omitempty"`
	Family          string `json:"family,omitempty"`
	ContextWindow   int    `json:"context_window,omitempty"`
	MaxOutput       int    `json:"max_output,omitempty"`
	Cost            Cost   `json:"cost,omitempty"`
	Reasoning       bool   `json:"reasoning,omitempty"`
	ToolCall        bool   `json:"tool_call,omitempty"`
	Attachment      bool   `json:"attachment,omitempty"`
	Vision          bool   `json:"vision,omitempty"`
	PDF             bool   `json:"pdf,omitempty"`
	OpenWeights     bool   `json:"open_weights,omitempty"`
	KnowledgeCutoff string `json:"knowledge_cutoff,omitempty"`
	ReleaseDate     string `json:"release_date,omitempty"`
	// Source records which cascade layer answered — useful in debug logs and
	// the dashboard so operators can tell whether metadata came from their
	// own config, the bundled models.dev snapshot, a hand-curated escape
	// hatch, or fell through to zero. Values: "user", "generated",
	// "curated", "" (miss). Not persisted in the bundled snapshot; the
	// caller stamps it after lookup.
	Source string `json:"-"`
}

ModelMeta describes a single model — context window, pricing, capability flags, and identity — as far as Antares needs to know. It is the shape the generated models.dev snapshot uses and the shape Meta() returns to callers.

Zero-values mean "unknown" — callers walking the cascade fall through to the next layer instead of trusting a fabricated 0-token window or a $0 price.

func Meta added in v0.4.0

func Meta(model string) (ModelMeta, bool)

Meta looks up model metadata by bare id (e.g. "claude-sonnet-4-6") without a caller-supplied provider hint. It walks the cascade in the same order as MetaByProvider and picks the first generated-table hit across every known provider — good enough for the agent's contextWindowFor() which only knows the model name, not always which provider it belongs to.

Prefer MetaByProvider when the caller already knows the provider, because the same model id can appear under multiple provider prefixes (e.g. "claude-opus" via anthropic and openrouter) with different pricing.

func MetaByAnyProvider added in v0.4.0

func MetaByAnyProvider(model string) (ModelMeta, bool)

MetaByAnyProvider looks up metadata by bare id across every provider in the generated table. Used only by callers that know their provider is a proxy re-serving official models (e.g. an OpenAI-compatible endpoint like EnxAPI that fronts Anthropic, OpenAI, Google under their real ids). Callers that know a specific provider should use MetaByProvider — it refuses to pin the wrong entry when the provider genuinely does not carry the model.

Preference order among candidates: first-party providers (anthropic > openai > google > well-known labs) win over noisy re-listings so "gpt-5" resolves to openai's numbers rather than some proxy's markup.

func MetaByProvider added in v0.4.0

func MetaByProvider(provider, model string) (ModelMeta, bool)

MetaByProvider looks up metadata for a specific provider+model pair, walking the full cascade:

  1. Hand-curated overrides (legacyContextWindow) — an escape hatch for entries where models.dev is missing or upstream is wrong. Kept small.
  2. Generated snapshot from models.dev, exact key "provider/id" first, then the same key with dots/dashes normalised (models.dev uses "4-6", Anthropic's own API uses "4.7" — same model, different spelling).
  3. Bare-id lookup across every provider — this is the escape hatch for custom proxies (e.g. enxapi) that re-serve official models under their own provider id. If exactly one entry in the table has that bare id, use it; if several do, prefer any anthropic/openai/google entry over noisy re-listings.
  4. Miss — the caller falls through to whatever default it has.

Note: layer 0 ("user override" via cfg.Providers[…].ModelMeta) is applied by higher-level callers that already hold *config.Config; the pure providers package stays free of runtime config to keep it importable from anywhere.

Jump to

Keyboard shortcuts

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