modelsdev

package
v1.23.1 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModelsDevAPIURL = "https://models.dev/api.json"
	CacheFileName   = "models_dev.json"
)

Variables

This section is empty.

Functions

func ModelSupportsReasoning added in v1.19.3

func ModelSupportsReasoning(modelID string) bool

ModelSupportsReasoning checks if the given model ID supports reasoning/thinking.

This function implements fail-open semantics:

  • If modelID is empty or not in "provider/model" format, returns true (fail-open)
  • If models.dev lookup fails for any reason, returns true (fail-open)
  • If lookup succeeds, returns the model's Reasoning field value

Types

type CachedData

type CachedData struct {
	Database    Database  `json:"database"`
	CachedAt    time.Time `json:"cached_at"`
	LastRefresh time.Time `json:"last_refresh"`
}

CachedData represents the cached models.dev data with metadata

type Cost

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 represents the pricing information for a model

type Database

type Database struct {
	Providers map[string]Provider `json:"providers"`
	UpdatedAt time.Time           `json:"updated_at"`
}

Database represents the complete models.dev database

type Limit

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

Limit represents the context and output limitations of a model

type Modalities

type Modalities struct {
	Input  []string `json:"input"`
	Output []string `json:"output"`
}

Modalities represents the supported input and output types

type Model

type Model struct {
	ID          string     `json:"id"`
	Name        string     `json:"name"`
	Family      string     `json:"family,omitempty"`
	Attachment  bool       `json:"attachment"`
	Reasoning   bool       `json:"reasoning"`
	Temperature bool       `json:"temperature"`
	ToolCall    bool       `json:"tool_call"`
	Knowledge   string     `json:"knowledge,omitempty"`
	ReleaseDate string     `json:"release_date"`
	LastUpdated string     `json:"last_updated"`
	OpenWeights bool       `json:"open_weights"`
	Cost        *Cost      `json:"cost,omitempty"`
	Limit       Limit      `json:"limit"`
	Modalities  Modalities `json:"modalities"`
}

Model represents an AI model with its specifications and capabilities

type Provider

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

Provider represents an AI model provider

type Store

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

Store manages access to the models.dev data. The database is loaded lazily on first access and cached for the lifetime of the Store. All methods are safe for concurrent use.

func NewDatabaseStore added in v1.23.1

func NewDatabaseStore(db *Database) *Store

NewDatabaseStore creates a Store pre-populated with the given database. The returned store serves data entirely from memory and never fetches from the network or touches the filesystem, making it suitable for tests and any scenario where the provider data is already known.

func NewStore

func NewStore() (*Store, error)

NewStore returns the cached default store instance. The underlying database is fetched lazily on first access from a local cache file or the models.dev API.

func (*Store) GetDatabase

func (s *Store) GetDatabase() (*Database, error)

GetDatabase returns the models.dev database, fetching from cache or API as needed.

func (*Store) GetModel

func (s *Store) GetModel(id string) (*Model, error)

GetModel returns a specific model by provider ID and model ID.

func (*Store) GetProvider

func (s *Store) GetProvider(providerID string) (*Provider, error)

GetProvider returns a specific provider by ID.

func (*Store) ResolveModelAlias added in v1.18.8

func (s *Store) ResolveModelAlias(providerID, modelName string) string

ResolveModelAlias resolves a model alias to its pinned version. For example, ("anthropic", "claude-sonnet-4-5") might resolve to "claude-sonnet-4-5-20250929". If the model is not an alias (already pinned or unknown), the original model name is returned. This method uses the models.dev database to find the corresponding pinned version.

Jump to

Keyboard shortcuts

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