catalog

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package catalog is Seshat's view of the public models.dev catalog of providers and models: which providers exist, the base URL and API key variable of each, and what each model can do (context window, output limit, image input, reasoning, cost, status). It is the data opencode builds its provider list from.

Two rules govern how the data is used:

  • The catalog is data about models, not an authority over where a key is sent. The base URL, the API key variable and the protocol of a provider come from the snapshot embedded in this binary (reviewed when it was built). A catalog fetched later can update models and add providers, but a provider it adds is Unverified: its URL must be shown to the user and confirmed before a key is sent to it. See Merge.
  • Our own catalog of models (internal/providers) wins over this one. The catalog's limits are community data: some are placeholders (an output limit equal to the context window usually means "unknown").

Index

Constants

View Source
const DefaultURL = "https://models.dev/api.json"

DefaultURL is where the public models.dev catalog is served.

View Source
const RefreshInterval = 24 * time.Hour

RefreshInterval is how old the cache may be before a background refresh fetches the catalog again.

Variables

View Source
var ErrCatalogTooSmall = errors.New("the catalog has too few providers to be genuine")

ErrCatalogTooSmall is returned when a catalog has too few providers to be believed.

Functions

func CacheAge

func CacheAge(cacheDir string) (time.Duration, bool)

CacheAge returns how long ago the cache was written, and false when there is none.

func Encode added in v1.11.0

func Encode(c *Catalog) ([]byte, error)

Encode writes a catalog in the compact gzip form Load reads (and the embedded snapshot is kept in).

func Refresh

func Refresh(ctx context.Context, client *http.Client, url, cacheDir string) error

Refresh fetches the catalog from url (DefaultURL when empty) and keeps it in cacheDir for Load. It is the only function of the package that uses the network, and the only one a host has to call for the catalog to follow the public one.

func RefreshIfStale

func RefreshIfStale(ctx context.Context, client *http.Client, url, cacheDir string) (bool, error)

RefreshIfStale refreshes the catalog when the cache is missing or older than RefreshInterval. It reports whether it fetched.

Types

type Catalog

type Catalog struct {
	Providers map[string]Provider
	// Source says where the data came from: "embedded", "cache" or the URL it was fetched from.
	Source string
}

Catalog is a set of providers.

func Embedded

func Embedded() (*Catalog, error)

Embedded returns the catalog built into the binary. It is read once. Every provider in it is verified.

func Fetch

func Fetch(ctx context.Context, client *http.Client, url string) (*Catalog, []byte, error)

Fetch downloads the catalog from url (DefaultURL when empty). It sends nothing about the user: a plain GET.

func Load

func Load(cacheDir string) (*Catalog, error)

Load returns the catalog to use: the embedded one, with the cached fetch merged over it when there is one. It never touches the network. cacheDir may be empty to ignore the cache. A damaged cache is ignored, not an error: the embedded catalog stands.

func Merge

func Merge(trusted, fetched *Catalog) *Catalog

Merge puts a catalog fetched at run time over the trusted one (the embedded snapshot) and returns the result. The rule is the security rule of the package:

  • A provider that is in trusted keeps its BaseURL, Env and Protocol from trusted. The fetched catalog may only update its name and its models. A fetched catalog that moves a provider to another URL changes nothing here.
  • A provider that is only in fetched is added with Unverified set: a host must show its URL and have the user confirm it before an API key is sent there.
  • A model that is only in trusted is kept (a provider that drops a model from its list does not make a conversation that uses it fail); a model in both takes the fetched data.

func Parse

func Parse(raw []byte, source string) (*Catalog, error)

Parse reads a catalog in the models.dev format. Every provider of the result is Unverified: it came from outside this binary. Models that do not produce text or cannot call tools are left out, as an agent cannot use them.

func (*Catalog) Model

func (c *Catalog) Model(providerID, modelID string) (Model, bool)

Model returns a model of a provider.

func (*Catalog) OpenAICompatibleProviders

func (c *Catalog) OpenAICompatibleProviders() []Provider

OpenAICompatibleProviders returns the providers the generic OpenAI-compatible client can call, sorted by name.

func (*Catalog) Provider

func (c *Catalog) Provider(id string) (Provider, bool)

Provider returns the provider with that id.

type Cost

type Cost struct {
	Input      float64
	Output     float64
	CacheRead  float64
	CacheWrite float64
	// Reasoning is the price of reasoning tokens when they are billed apart from the output.
	Reasoning float64
	// InputAudio and OutputAudio are the prices of audio tokens when they are billed apart.
	InputAudio  float64
	OutputAudio float64
}

Cost is the price of a model in US dollars per million tokens. A zero value means the price is unknown (or not billed apart).

type Model

type Model struct {
	ID            string
	Name          string
	ContextWindow int
	// MaxInput is the limit on the prompt alone, 0 when the catalog gives none. When it is below the context window the prompt
	// cannot use the whole window (the rest is kept for the output).
	MaxInput int
	// MaxOutput is the output limit, 0 when unknown. See OutputIsKnown.
	MaxOutput int
	// InputModalities lists what the model accepts besides text: "image", "audio", "video", "pdf".
	InputModalities []string
	Reasoning       bool
	// Attachment is true when the model accepts file attachments.
	Attachment bool
	// StructuredOutput is true when the model supports JSON-schema constrained output.
	StructuredOutput bool
	// NoTemperature is true when the catalog says the model does not support the temperature parameter (many reasoning models reject it).
	// A model the catalog says nothing about is assumed to support it.
	NoTemperature bool
	// Interleaved says the model interleaves reasoning with its answer and how: the name of the response field that carries the reasoning
	// ("reasoning_content" or "reasoning_details"), "true" when the catalog gives no field, "" when it does not interleave.
	Interleaved string
	// OpenWeights is true when the trained weights are publicly available.
	OpenWeights bool
	// Family groups the models of a line ("claude-sonnet", "gpt"), "" when the catalog gives none.
	Family string
	// Knowledge is the knowledge cutoff, "YYYY-MM" or "YYYY-MM-DD", "" when unknown.
	Knowledge string
	Cost      Cost
	// Status is "", "alpha", "beta" or "deprecated".
	Status      string
	ReleaseDate string
	// LastUpdated is the date of the last update of the model's entry.
	LastUpdated string
}

Model describes one model of a provider.

func (Model) Audio

func (m Model) Audio() bool

Audio reports whether the model accepts audio.

func (Model) Deprecated

func (m Model) Deprecated() bool

Deprecated reports whether the provider has retired or is retiring the model.

func (Model) OutputIsKnown

func (m Model) OutputIsKnown() bool

OutputIsKnown reports whether the output limit is a real one. The catalog often repeats the context window when the limit is not known, so a limit equal to the window, or a missing one, is not trusted.

func (Model) Vision

func (m Model) Vision() bool

Vision reports whether the model accepts images.

type Provider

type Provider struct {
	ID   string
	Name string
	// BaseURL is the API base URL, empty for providers that have no fixed one (Anthropic, OpenAI, Gemini, AWS...).
	BaseURL string
	// Env lists the environment variables that can hold the API key, the first one first.
	Env []string
	// Protocol is the SDK package the catalog names for the provider: "@ai-sdk/openai-compatible" for most.
	Protocol string
	Models   map[string]Model
	// Unverified is true for a provider that is not in the embedded snapshot: its BaseURL comes from a catalog fetched at run
	// time and must be confirmed by the user before an API key is sent to it.
	Unverified bool
}

Provider describes one provider of the catalog.

func (Provider) OpenAICompatible

func (p Provider) OpenAICompatible() bool

OpenAICompatible reports whether the provider can be called with the generic OpenAI-compatible client: it speaks that protocol and the catalog gives its base URL.

func (Provider) SortedModels

func (p Provider) SortedModels() []Model

SortedModels returns the models, newest first, then by id. Deprecated models come last.

Jump to

Keyboard shortcuts

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