Documentation
¶
Index ¶
Constants ¶
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 ID ¶ added in v1.59.0
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
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
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
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
IsValid reports whether both components of the ID are populated.
type Modalities ¶
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.
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 ¶
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 ¶
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 ¶
GetDatabase returns the models.dev database, fetching from cache or API as needed.
func (*Store) GetModel ¶
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 ¶
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.