modelsdev

package
v1.7.20 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 14 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 modelsdev fetches and parses the models.dev public model database (https://models.dev/api.json). It owns the catalog wire format and an optional offline metadata cache. It resolves model capabilities and AI SDK providers without knowing CCL's provider configuration, credentials or protocol dispatch.

models.dev is the metadata source OpenCode itself uses to decide which AI SDK provider (and therefore which wire protocol) each model speaks. A provider carries a default npm package (e.g. "@ai-sdk/openai-compatible") and individual models may override it via their own provider.npm field.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CachePath added in v1.7.17

func CachePath() (string, error)

CachePath is separate from provider configuration and OAuth credentials.

func CacheStamp added in v1.7.17

func CacheStamp() string

CacheStamp lets an explicitly requested proxy start notice a metadata refresh without reading/decoding the catalog or changing provider config.

func Fetch

func Fetch(ctx context.Context) (map[string]Provider, error)

Fetch downloads and decodes the models.dev catalog. The top level is a map of provider id → provider with no envelope key, so it is decoded with a raw map and tolerant of entries that do not parse into a full provider (they are skipped rather than failing the whole fetch).

func ResolvedNPM

func ResolvedNPM(p Provider, m Model) string

ResolvedNPM returns the AI SDK package that describes a model's protocol: the model-level provider.npm when present, otherwise the provider default.

Types

type Cache added in v1.7.17

type Cache struct {
	Path   string
	URL    string
	Client *http.Client
}

Cache downloads public metadata only; it never receives provider credentials. URL and Client can point to local services in isolated tests.

func (*Cache) Index added in v1.7.17

func (c *Cache) Index() (*Index, error)

func (*Cache) Refresh added in v1.7.17

func (c *Cache) Refresh(ctx context.Context) (*Snapshot, error)

type Index added in v1.7.17

type Index struct {
	// contains filtered or unexported fields
}

Index retains only reasoning metadata and exact aliases from a catalog. It is immutable after construction and safe for concurrent lookups.

func CachedIndex added in v1.7.17

func CachedIndex() (*Index, error)

CachedIndex is read-only and performs no network access. A cached immutable index is reused until the snapshot file changes (for example via ccl set).

func (*Index) Efforts added in v1.7.17

func (index *Index) Efforts(providerID, modelID, displayName string) ([]string, bool)

Efforts resolves an exact provider entry first, then a canonical/reference entry. Conflicting equal-priority aliases are not merged or guessed. Found with an empty slice means the model has no selectable reasoning tiers. The returned slice is a copy so callers cannot mutate the shared index.

type Model

type Model struct {
	ID               string            `json:"id"`
	Name             string            `json:"name"`
	Status           string            `json:"status"`
	Provider         *ModelProvider    `json:"provider"`
	Limit            ModelLimit        `json:"limit"`
	CanonicalID      string            `json:"canonical_model_id"`
	Reasoning        bool              `json:"reasoning"`
	ReasoningOptions []ReasoningOption `json:"reasoning_options"`
}

Model is a single model under a provider. Status is optional ("deprecated", "beta", …); most models omit it.

func (Model) Efforts added in v1.7.17

func (m Model) Efforts() []string

Efforts returns reasoning tiers in slider order. Off/none is a thinking switch, not a reasoning tier; toggle and budget options do not invent tiers.

type ModelLimit

type ModelLimit struct {
	Context int `json:"context"`
	Output  int `json:"output"`
}

ModelLimit carries the advertised context/output token limits.

type ModelProvider

type ModelProvider struct {
	NPM string `json:"npm"`
}

ModelProvider carries a model-level npm override. Absent means the model inherits its provider's default npm.

type Provider

type Provider struct {
	ID     string           `json:"id"`
	Name   string           `json:"name"`
	NPM    string           `json:"npm"`
	API    string           `json:"api"`
	Env    []string         `json:"env"`
	Doc    string           `json:"doc"`
	Models map[string]Model `json:"models"`
}

Provider is one entry in the models.dev catalog, keyed by its id at the top level. Fields we do not consume (cost, modalities, …) are intentionally omitted.

type ReasoningOption added in v1.7.17

type ReasoningOption struct {
	Type   string   `json:"type"`
	Values []string `json:"values"`
}

ReasoningOption distinguishes selectable effort tiers from thinking switches and token budgets. A reasoning model need not support selectable efforts.

type Snapshot added in v1.7.17

type Snapshot struct {
	Providers map[string]Provider
	Offline   bool
}

Snapshot is a validated catalog fetched during configuration. Offline means refresh failed but the last valid local snapshot remains usable.

func Refresh added in v1.7.17

func Refresh(ctx context.Context) (*Snapshot, error)

Refresh updates the on-disk snapshot, or returns the last valid offline copy. Call from OAuth / ccl set, never from a model request.

Jump to

Keyboard shortcuts

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