Documentation
¶
Index ¶
Constants ¶
const ( ModelsDevAPIURL = "https://models.dev/api.json" CacheFileName = "models_dev.json" )
Variables ¶
var NewStore = sync.OnceValues(func() (*Store, error) { homeDir, err := os.UserHomeDir() if err != nil { return nil, fmt.Errorf("failed to get user home directory: %w", err) } cacheDir := filepath.Join(homeDir, ".cagent") if err := os.MkdirAll(cacheDir, 0o755); err != nil { return nil, fmt.Errorf("failed to create cache directory: %w", err) } return &Store{ cacheFile: filepath.Join(cacheDir, CacheFileName), }, nil })
NewStore returns the process-wide singleton Store.
The database is loaded lazily on the first call to GetDatabase and then cached in memory so that every caller shares one copy. The first call creates the cache directory if it does not exist.
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 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"`
}
Model represents an AI model with its specifications and capabilities
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.
Use NewStore to obtain the process-wide singleton instance. The database is loaded on first access via GetDatabase and shared across all callers, avoiding redundant disk/network I/O.
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 (*Store) GetDatabase ¶
GetDatabase returns the models.dev database, fetching from cache or API as needed.
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.