modeldb

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package modeldb provides access to the models.dev model database.

This package embeds the full models.dev database for use by external consumers (CLI tools, UIs, model selectors). It is NOT used by provider implementations for pricing calculations - providers maintain their own pricing logic.

To update the embedded model database, run:

curl -sL https://models.dev/api.json -o modeldb/api.json

Index

Constants

This section is empty.

Variables

View Source
var ProviderMapping = map[string]string{
	"bedrock":    "amazon-bedrock",
	"anthropic":  "anthropic",
	"openai":     "openai",
	"openrouter": "openrouter",
	"google":     "google",
}

ProviderMapping maps internal provider names to models.dev provider IDs.

Functions

func Providers

func Providers() []string

Providers returns a list of all provider IDs in the database.

Types

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"`
	ContextOver200k *Cost   `json:"context_over_200k,omitempty"`
}

Cost represents pricing in USD per 1M tokens.

type Database

type Database map[string]Provider

Database is the root structure mapping provider IDs to providers.

func Load

func Load() (Database, error)

Load returns the parsed database, loading lazily on first call. Thread-safe via sync.Once. Returns the same instance on subsequent calls.

func MustLoad

func MustLoad() Database

MustLoad returns the database or panics if loading fails. Intended for use at init time when failure is unrecoverable.

type Interleaved

type Interleaved struct {
	Enabled bool
	Field   string
}

Interleaved describes reasoning interleaving configuration. Can be unmarshaled from boolean true or object {"field": "reasoning_content"}.

func (Interleaved) MarshalJSON

func (i Interleaved) MarshalJSON() ([]byte, error)

MarshalJSON serializes Interleaved back to JSON.

func (*Interleaved) UnmarshalJSON

func (i *Interleaved) UnmarshalJSON(data []byte) error

UnmarshalJSON handles both boolean and object formats for interleaved config.

type Limit

type Limit struct {
	Context int `json:"context,omitempty"`
	Output  int `json:"output,omitempty"`
}

Limit describes context and output token limits.

type Modalities

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

Modalities describes supported input/output types.

type Model

type Model struct {
	ID               string       `json:"id"`
	Name             string       `json:"name"`
	Family           string       `json:"family,omitempty"`
	Attachment       bool         `json:"attachment,omitempty"`
	Reasoning        bool         `json:"reasoning,omitempty"`
	ToolCall         bool         `json:"tool_call,omitempty"`
	StructuredOutput bool         `json:"structured_output,omitempty"`
	Temperature      bool         `json:"temperature,omitempty"`
	Interleaved      *Interleaved `json:"interleaved,omitempty"`
	Knowledge        string       `json:"knowledge,omitempty"`
	ReleaseDate      string       `json:"release_date,omitempty"`
	LastUpdated      string       `json:"last_updated,omitempty"`
	Modalities       Modalities   `json:"modalities,omitempty"`
	OpenWeights      bool         `json:"open_weights,omitempty"`
	Cost             Cost         `json:"cost,omitempty"`
	Limit            Limit        `json:"limit,omitempty"`
}

Model represents a single LLM model with metadata and pricing.

func GetModel

func GetModel(providerName, modelID string) (Model, bool)

GetModel returns a model by provider name and model ID.

type Provider

type Provider struct {
	ID     string           `json:"id"`
	Name   string           `json:"name"`
	Env    []string         `json:"env,omitempty"`
	NPM    string           `json:"npm,omitempty"`
	API    string           `json:"api,omitempty"`
	Doc    string           `json:"doc,omitempty"`
	Models map[string]Model `json:"models"`
}

Provider represents an LLM provider with its models.

func GetProvider

func GetProvider(name string) (Provider, bool)

GetProvider returns the provider for the given internal name. Uses ProviderMapping to translate internal names to models.dev IDs.

Jump to

Keyboard shortcuts

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