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 ¶
- func Activate(cfg *config.Config, id, key string)
- func AllowedProviders() map[string]bool
- func Connected(cfg *config.Config, id string) bool
- func ContextWindow(model string) int
- func FetchModelInfos(ctx context.Context, cfg *config.Config, providerID string) ([]llm.ModelInfo, error)
- func FetchModels(ctx context.Context, cfg *config.Config, providerID string) ([]string, error)
- func StartRefresh(ctx context.Context)
- type Cost
- type Info
- type ModelMeta
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Activate ¶
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
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 ¶
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
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 ¶
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
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.
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.
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
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
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
MetaByProvider looks up metadata for a specific provider+model pair, walking the full cascade:
- Hand-curated overrides (legacyContextWindow) — an escape hatch for entries where models.dev is missing or upstream is wrong. Kept small.
- 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).
- 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.
- 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.