2026-02-25 22:51:45 +03:00
|
|
|
package models
|
|
|
|
|
|
|
|
|
|
// ModelsDBProviders is the top-level type for models.dev/api.json data:
|
|
|
|
|
// a map of provider ID → provider object.
|
|
|
|
|
type ModelsDBProviders = map[string]modelsDBProvider
|
|
|
|
|
|
|
|
|
|
// modelsDBProvider represents a provider entry from models.dev/api.json.
|
|
|
|
|
type modelsDBProvider struct {
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
|
Env []string `json:"env"`
|
|
|
|
|
NPM string `json:"npm"`
|
|
|
|
|
API string `json:"api,omitempty"`
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
Doc string `json:"doc,omitempty"`
|
|
|
|
|
Models map[string]modelsDBModel `json:"models"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// modelsDBModel represents a model entry from models.dev/api.json.
|
|
|
|
|
type modelsDBModel struct {
|
2026-03-26 12:44:19 +03:00
|
|
|
ID string `json:"id"`
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
Family string `json:"family,omitempty"`
|
|
|
|
|
Attachment bool `json:"attachment"`
|
|
|
|
|
Reasoning bool `json:"reasoning"`
|
|
|
|
|
ToolCall bool `json:"tool_call"`
|
|
|
|
|
Temperature bool `json:"temperature"`
|
|
|
|
|
Cost modelsDBCost `json:"cost"`
|
|
|
|
|
Limit modelsDBLimit `json:"limit"`
|
|
|
|
|
Provider *modelsDBModelProvider `json:"provider,omitempty"` // Model-specific provider override
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// modelsDBModelProvider represents a provider reference within a model.
|
|
|
|
|
type modelsDBModelProvider struct {
|
|
|
|
|
NPM string `json:"npm"`
|
2026-02-25 22:51:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// modelsDBCost represents model pricing from models.dev.
|
|
|
|
|
type modelsDBCost struct {
|
|
|
|
|
Input float64 `json:"input"`
|
|
|
|
|
Output float64 `json:"output"`
|
|
|
|
|
CacheRead *float64 `json:"cache_read,omitempty"`
|
|
|
|
|
CacheWrite *float64 `json:"cache_write,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// modelsDBLimit represents model context/output limits from models.dev.
|
|
|
|
|
type modelsDBLimit struct {
|
|
|
|
|
Context int `json:"context"`
|
|
|
|
|
Output int `json:"output"`
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-02 15:07:07 +03:00
|
|
|
// wireProtocol identifies which LLM API protocol an npm package speaks.
|
|
|
|
|
// Fantasy implements three native protocols (openai, anthropic, google);
|
|
|
|
|
// everything else in its providers/ tree is a thin wrapper around one of
|
|
|
|
|
// them with a pre-baked default URL or auth scheme.
|
|
|
|
|
type wireProtocol int
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
wireUnknown wireProtocol = iota
|
|
|
|
|
wireOpenAI
|
|
|
|
|
wireAnthropic
|
|
|
|
|
wireGoogle
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// npmToWireProtocol maps npm package names from models.dev to the wire
|
|
|
|
|
// protocol they speak. Provider-specific bundles (azure, bedrock, vercel,
|
|
|
|
|
// openrouter, google-vertex, google-vertex-anthropic) are intentionally
|
|
|
|
|
// absent — they have native top-level cases in CreateProvider and never
|
|
|
|
|
// reach the auto-router. Providers not in this map but with an api URL
|
|
|
|
|
// are auto-routed through the OpenAI-compatible wire.
|
|
|
|
|
var npmToWireProtocol = map[string]wireProtocol{
|
|
|
|
|
"@ai-sdk/openai": wireOpenAI,
|
|
|
|
|
"@ai-sdk/openai-compatible": wireOpenAI,
|
|
|
|
|
"@ai-sdk/anthropic": wireAnthropic,
|
|
|
|
|
"@ai-sdk/google": wireGoogle,
|
2026-02-25 22:51:45 +03:00
|
|
|
}
|