modelsdev

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 15 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 loads the models.dev provider/model catalog used to price and describe models. The catalog is runtime data: this package does not carry a baked model or pricing table.

Index

Constants

View Source
const (
	DefaultSource = "https://models.dev"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Catalog

type Catalog map[string]Provider

func (Catalog) Resolve

func (catalog Catalog) Resolve(providerID, modelID string) (calc.Model, error)

Resolve addresses the provider and model maps by their catalog keys. Model.id is API metadata, not a lookup alias.

type Client

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

func New

func New(options Options) (*Client, error)

New constructs a catalog client. Empty options select models.dev and the user cache directory.

func NewFromEnv

func NewFromEnv(version string) (*Client, error)

NewFromEnv reads the catalog settings from the environment. Only "true" and "1" (case-insensitive) enable SENIOR_DEV_DISABLE_MODELS_FETCH.

func (*Client) CachePath

func (client *Client) CachePath() string

CachePath is exposed for diagnostics and tests.

func (*Client) Get

func (client *Client) Get(ctx context.Context) (Catalog, error)

Get is memoized for the process lifetime. Population is disk -> (no bundled snapshot) -> disabled-fetch empty catalog -> network.

func (*Client) Refresh

func (client *Client) Refresh(ctx context.Context, force bool) error

Refresh refetches a stale catalog: freshness is checked on the generated cache path (not SENIOR_DEV_MODELS_PATH), checked again under the cross-process lock, and fetch errors leave the memoized catalog untouched.

func (*Client) StartRefresh

func (client *Client) StartRefresh(ctx context.Context, report func(error))

StartRefresh performs the startup refresh and repeats one hour after each completion.

type Cost

type Cost struct {
	Input           float64  `json:"input"`
	Output          float64  `json:"output"`
	CacheRead       *float64 `json:"cache_read,omitempty"`
	CacheWrite      *float64 `json:"cache_write,omitempty"`
	ContextOver200K *Cost    `json:"context_over_200k,omitempty"`
}

Cost is the models.dev cost block. Pointer fields preserve the distinction between an omitted optional rate and an explicit zero.

type Limit

type Limit struct {
	Context float64  `json:"context"`
	Input   *float64 `json:"input,omitempty"`
	Output  float64  `json:"output"`
}

type Modalities

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

type Model

type Model struct {
	ID          string      `json:"id"`
	Name        string      `json:"name"`
	Attachment  *bool       `json:"attachment,omitempty"`
	Reasoning   *bool       `json:"reasoning,omitempty"`
	Temperature *bool       `json:"temperature,omitempty"`
	ToolCall    *bool       `json:"tool_call,omitempty"`
	Modalities  *Modalities `json:"modalities,omitempty"`
	Cost        *Cost       `json:"cost,omitempty"`
	Limit       Limit       `json:"limit"`
}

type Options

type Options struct {
	Source       string
	CatalogPath  string
	CacheDir     string
	DisableFetch bool
	HTTPClient   *http.Client
	Version      string
	Now          func() time.Time
	Sleep        func(context.Context, time.Duration) error
	LockTimeout  time.Duration
	LockPoll     time.Duration
}

type Provider

type Provider struct {
	ID     string           `json:"id"`
	Name   string           `json:"name"`
	Models map[string]Model `json:"models"`
}

Jump to

Keyboard shortcuts

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