modelsdev

package
v1.59.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: Apache-2.0 Imports: 13 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

This section is empty.

Types

type CachedData

type CachedData struct {
	Database    Database  `json:"database"`
	LastRefresh time.Time `json:"last_refresh"`
	ETag        string    `json:"etag,omitempty"`
}

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"`
}

Database represents the complete models.dev database

type ID added in v1.59.0

type ID struct {
	Provider string
	Model    string
}

ID identifies a model in the models.dev catalog by provider and model name. It exists so callers can no longer accidentally pass a bare model name (e.g. "claude-sonnet-4-6") where a "provider/model" pair is required: the compiler rejects a [string] argument and forces one of the constructors below.

The zero value is the empty ID and reports IsZero() == true. Use NewID, ParseID, or ParseIDOrZero to construct values; use ID.String when a "provider/model" representation is required at a boundary (slog fields, event payloads, error messages, ...).

func NewID added in v1.59.0

func NewID(provider, model string) ID

NewID returns an ID for the given provider and model name. Either component may be empty (for example for a provider-less model spec during config parsing); call ID.IsZero to test for the empty ID and ID.IsValid to check that both components are populated.

func ParseID added in v1.59.0

func ParseID(ref string) (ID, error)

ParseID parses a "provider/model" reference. Either component must be non-empty and the separator must be present; otherwise an error is returned. The function does not validate that the provider or model exists in the models.dev catalog.

func ParseIDOrZero added in v1.59.0

func ParseIDOrZero(ref string) ID

ParseIDOrZero parses a "provider/model" reference and returns the zero ID when the input is malformed. Use this on best-effort code paths (logs, telemetry labels) where a malformed reference should not surface as an error.

func (ID) IsValid added in v1.59.0

func (id ID) IsValid() bool

IsValid reports whether both components of the ID are populated.

func (ID) IsZero added in v1.59.0

func (id ID) IsZero() bool

IsZero reports whether the ID has both components empty.

func (ID) String added in v1.59.0

func (id ID) String() string

String returns the canonical "provider/model" representation. When either component is empty the separator is still emitted so the output round-trips through ParseID only when both fields are set. For the zero ID the result is the empty string.

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 {
	Name       string     `json:"name"`
	Family     string     `json:"family,omitempty"`
	Cost       *Cost      `json:"cost,omitempty"`
	Limit      Limit      `json:"limit"`
	Modalities Modalities `json:"modalities"`

	// Reasoning is true when the model supports internal reasoning.
	Reasoning bool `json:"reasoning,omitempty"`
	// ToolCall is true when the model supports tool/function calls.
	ToolCall bool `json:"tool_call,omitempty"`
	// Temperature is true when the API accepts the temperature parameter.
	Temperature bool `json:"temperature,omitempty"`
	// Attachment is true when the model accepts file/image attachments.
	Attachment bool `json:"attachment,omitempty"`
	// OpenWeights is true when the model has openly-released weights.
	OpenWeights bool `json:"open_weights,omitempty"`
	// ReleaseDate is the model's public release date (YYYY-MM-DD).
	ReleaseDate string `json:"release_date,omitempty"`
}

Model represents an AI model with its specifications and capabilities.

Fields are sourced from https://models.dev/api.json. Boolean capability fields default to false when absent from the source data.

type Opt added in v1.59.0

type Opt func(*storeOptions)

Opt configures a Store created with NewStore.

func WithCache added in v1.59.0

func WithCache(path string) Opt

WithCache overrides the path of the on-disk cache file used by the Store. The parent directory will be created if it does not already exist.

type Provider

type Provider struct {
	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. All methods are safe for concurrent use.

The database is loaded on first access via GetDatabase and then cached in memory for the lifetime of the Store.

func NewDatabaseStore

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(opts ...Opt) (*Store, error)

NewStore creates a new Store backed by an on-disk cache. By default the cache lives at ~/.cagent/models_dev.json; use WithCache to override the location. Callers should create one Store and share it rather than calling NewStore repeatedly. RuntimeConfig.ModelsDevStore() is the standard way to obtain a shared instance.

func (*Store) GetDatabase

func (s *Store) GetDatabase(ctx context.Context) (*Database, error)

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

func (*Store) GetModel

func (s *Store) GetModel(ctx context.Context, id ID) (*Model, error)

GetModel returns a specific model by ID. The ID must carry both a provider and a model component; pass the result of NewID, ParseID, or a provider's ID method.

func (*Store) ResolveModelAlias

func (s *Store) ResolveModelAlias(ctx context.Context, 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