catalog

package
v0.1.4849 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 31 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 catalog knows which models exist. It reads the models.dev catalog (from magpie's own cache or OpenCode's), Codex's model cache, and falls back to a small built-in list so the picker is never empty.

Index

Constants

View Source
const (
	AuthXAPIKey = "x-api-key"
	AuthBearer  = "bearer"
)

Which header a key goes in, for a vendor that takes one of the two alone (provider.Provider.AuthHeader): "" sends both.

View Source
const (
	ServesEmbedding     = "embedding"
	ServesRerank        = "rerank"
	ServesSpeech        = "speech"
	ServesTranscription = "transcription"
)

The APIs a model Serves is made for.

View Source
const LeastWindow = 2048

LeastWindow is the smallest context window a list is taken at its word for. Less can't hold an agent's system prompt, let alone a turn, and an agent told it compacts at once or won't send at all (H20 on Discord: hy3 and Cline's free models listed at 512, which Claude Code and Codex took as the model's window). The smallest real chat models' windows are about 4096 (gpt-3.5-turbo-instruct's 4095, mythomax's 4096): those stand.

View Source
const MaxVia = 8

MaxVia is the most magpies a model's way may pass through before a list is taken to loop through a magpie from before magpie_via, which stamps none of its own.

View Source
const PageLimit = 1000

PageLimit is the page size asked of a list that pages, which Anthropic accepts: a real catalog of its own fits in one or two pages of it.

View Source
const PeakFactor = 2

PeakFactor is what a call in the peak hours costs, times the off-peak list price: DeepSeek's off-peak rates are half its peak rates, and so are Ollama Cloud's.

Variables

View Source
var Changed func()

Changed, when set, is told that the models magpie offers may be others now: a provider added, edited or removed, a vendor's list fetched anew. The agent package sets it, to bring the model lists agents keep in files of their own up to date.

View Source
var EffortAliases = map[string]string{"light": "low", "extra_high": "xhigh"}

EffortAliases are levels some vendors name in words of their own, each with the level of EffortRank's it is: Trae's light and extra_high (its 轻 and 极高), which a plugin serving Trae's models (Our Free Model's) lists as they are (nianshou5 on Discord).

View Source
var EffortRank = []string{"none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"}

EffortRank orders the reasoning levels agents and vendors name, weakest first.

View Source
var ErrAsked = errors.New("every list of this base was already asked for this key")

ErrAsked is what FetchAtListed says when every list URL of the base was already asked for this key and none of them answered: there is nothing left to ask there, which is not a refusal of the base and is not reported as one to the user. A caller asking several bases of one provider reads it as "this base said nothing new" and moves on.

View Source
var Forget func()

Forget, when set, is told so first: the provider package drops the catalog a request holds (provider.Hold).

View Source
var OneAuthOrder = []string{AuthXAPIKey, AuthBearer}

OneAuthOrder is the order the two headers are tried in alone when a vendor refuses both together: Anthropic's own x-api-key first.

View Source
var PublicCatalogs = map[string]string{
	"aihubmix.com":  "https://aihubmix.com/api/v1/models",
	"openrouter.ai": "https://openrouter.ai/api/v1/models?output_modalities=image",
}

PublicCatalogs are vendors whose /models, asked with a key, leaves out the image models the key can use: AIHubMix lists only its Gemini image models there, while gpt-image-2 and the rest draw with the same key. Its public catalog, by the host of the vendor's base URL, has them. OpenRouter's /models lists only the models that answer in text, so of its image models only those that chat (Nano Banana, GPT-5 Image) were there; FLUX, Seedream, Riverflow, Recraft, GPT Image and the rest, which answer with an image alone, are listed by its Image API's own /images/models (iwinux on Discord). They draw at its /images, as the gateway asks it. That list leaves out a model's variants, though: recraft/recraft-v4.1-flash-v2:free is listed by /models asked for image output alone (AllenH__ on X), which lists every model /images/models does as well, each row with the endpoints it is asked at.

View Source
var UserSame func(bare string) (string, bool)

UserSame, when set, is the model the user said a model of this bare id (lowercase, without a vendor's prefix) is the same as, by the id any vendor spells it with (settings' ModelSameAs; the settings package sets it). A model models.dev lists by its very id is that model; one it doesn't is looked up as the model the user named, before any guess of magpie's (renamed, normalFor): a relay's rename no rule can read, "ds.4.1(WB)" for deepseek-v4.1-flash (pinmmis on X), has that model's window, reply limit, levels and images.

Functions

func APIHost

func APIHost(id string) string

APIHost is the host models.dev says a provider serves its models at (api.deepseek.com), lower case; "" when it isn't in the catalog.

func APIOf added in v0.1.166

func APIOf(providerID, modelID string) string

APIOf is the API a models.dev provider's model is served on, when the catalog says it's one of its own: "responses", "anthropic" or "gemini" for a model OpenCode serves through OpenAI's, Anthropic's or Google's SDK (Gemini's generateContent: Zen's Gemini models, Go's Gemini 4 Argon Contributor, #2168), not the OpenAI-compatible one the rest of its models go through.

func APIRefused

func APIRefused(status int, body []byte) bool

APIRefused is a refusal of the API itself, whatever the model: sub2api answers a key whose group isn't let dispatch Anthropic's Messages with 403 {"type":"error","error":{"type":"permission_error","message":"This group does not allow /v1/messages dispatch"}} (Sidrune AI, 11-20: every Claude Code request of a China-region key). The key serves its models on its other APIs; on this one it serves none of them.

func Asked

func Asked(ctx context.Context)

Asked says a model list made of the catalog alone is being fetched: a Claude subscription's, which is models.dev's anthropic list, as magpie asks Anthropic nothing in Claude Code's name. The catalog is fetched now, as long as ctx allows, when it is older than askedAfter and wasn't tried in that time, so a model launched since the day's fetch is on the list the user asked for (hhdaxia on X: Fable 5.2, on models.dev and in Claude Code's /model, not after Fetch models again). Only in a process that keeps the catalog fresh (KeepFresh), one fetch at a time, and a failed one leaves the catalog as it was.

func AtEndpoint added in v0.1.1231

func AtEndpoint(base string) []string

AtEndpoint are the models.dev providers whose models are served at base (their "api"), in order: the catalog of a provider the user added by its endpoint alone. A trailing slash and the case of the address don't count.

func BothAuthRefused added in v0.1.1211

func BothAuthRefused(status int, body []byte) bool

BothAuthRefused is a 401 whose body says x-api-key and Authorization can't both be sent (Aloha on Discord: "鉴权 header, x-api-key 和 Authorization 不可以同时存在"), in Chinese or English.

func CacheKey

func CacheKey() string

CacheKey names the catalog kept on disk, models.dev's provider catalog and the lab catalog and v2 embedding models beside it (a price one of them gives re-prices the ledger's calls), by what the files hold, not by when they were written. A Claude account's model list fetches the catalog again every 45 minutes (Asked), and usage keyed its whole index on the file's mtime: each fetch, the same bytes, had the next usage query read every session file again, ~15 s of CPU over a long history.

func CachePath

func CachePath() string

CachePath is where `magpie sync` stores the models.dev catalog.

func CodexEntry added in v0.1.1691

func CodexEntry(raw json.RawMessage) bool

CodexEntry reports whether raw, one row of a model list, is a model as Codex's own catalog lists it (/backend-api/codex/models, codex-rs's ModelInfo): a slug, its reasoning levels, its shell and its instructions. A plain OpenAI list's row has none of them.

func CodexHome added in v0.1.763

func CodexHome() string

CodexHome is where Codex CLI keeps its state: $CODEX_HOME, else ~/.codex.

func CodexLevels added in v0.1.1691

func CodexLevels(raw json.RawMessage) ([]string, bool)

CodexLevels are the efforts of a Codex catalog entry's supported_reasoning_levels; false when raw is no such entry.

func CodexModelsCache added in v0.1.763

func CodexModelsCache() string

CodexModelsCache is the model list Codex CLI keeps, under CodexHome.

func ContextOf added in v0.1.54

func ContextOf(id string) int

ContextOf is the context window models.dev gives a model of this id, as most of the providers it lists serving it do, or 0 when it doesn't know the model. Like SeesImages it reaches a vendor models.dev doesn't list: a proxy serving "openai/gpt-5.4", or "gpt-5.4(high)" with the reasoning level CLIProxyAPI takes in the id, which a static model list would otherwise leave at the agent's default.

A relay's rename of a model it knows (renamed) that names its window ("[1M]", "[200K]", Claude Code's "[1m]") has the window it names: what the relay serves it at, as Claude Code takes claude-opus-5[1m] for 1M.

Last, a model it lists under another spelling (normalFor): Volcengine Ark's kimi-k3-1-pro-261024 has kimi-k3.1-pro's window. A window the vendor's own list gives is read before this, by the caller, and stays.

func DrawsID added in v0.1.338

func DrawsID(id string) bool

DrawsID is whether a model's id names one that makes images, for a model the catalog doesn't know (one typed in, or a vendor's own list's). Banana is the Nano Banana the Gemini image models are called on a relay, whatever its spelling there (#2071). SenseNova's U1 models (sensenova-u1.5-lite, -fast) draw only, on its images API (lileo0668 on Discord).

func EffortLevel added in v0.1.1778

func EffortLevel(e string) string

EffortLevel is the level of EffortRank's that e names: e itself, or the one a vendor's word for it is (EffortAliases).

func Efforts

func Efforts(models []Model, id string) []string

Efforts returns the reasoning levels a model supports, if known.

func EffortsOf added in v0.1.59

func EffortsOf(id string) []string

EffortsOf is the reasoning levels models.dev gives a model of this id, as most of the providers giving any for it do, or nil when none does. Like ContextOf it reaches a vendor models.dev doesn't list: a custom provider serving "glm-5.3-flash" takes the levels Z.ai and the others serving it say it does, where it would otherwise be taken for a model that doesn't reason, and an agent offer no levels for it.

func EmbeddingsPath

func EmbeddingsPath() string

EmbeddingsPath is where Sync keeps models.dev's v2 embedding models, beside its provider catalog.

func EndpointAPIs added in v0.1.141

func EndpointAPIs(endpoints []string) []string

EndpointAPIs names the APIs of a model list's supported_endpoints — "chat", "responses", "anthropic" — leaving out any magpie doesn't speak (Copilot's websocket one); nil when it names none of them.

func FilmsID added in v0.1.2926

func FilmsID(id string) bool

FilmsID is whether a model's id names one that makes videos, for a model whose list says nothing of a kind: OpenAI's sora-2 and sora-2-pro are made at its OpenAI-shaped videos API, which the gateway speaks, but textModel counts their ids out of the chat models, and a list that marks no kind left them unlisted at all — never offered to talk to, and never marked a video model in the provider's editor (#4954). The other video families keep the faces their own APIs are asked on: Ark's Seedance at its tasks (gateway arkVideoModel), a MiniMax key's H3 (video_minimax.go), and a model the user says makes videos (#1399).

func ImagesAPI added in v0.1.384

func ImagesAPI(id string) bool

ImagesAPI is whether a model draws on an images API rather than answering in chat with pictures: gpt-image, dall-e, imagen, flux, seedream… — not gemini-*-image or gpt-5-image, which chat. iFlytek Loomy's Hy-Image generators (Hy-Image-3.5-preview) draw on its images API too (#4913).

func InputsOf

func InputsOf(id string) []string

InputsOf is what models.dev says a model of this id takes (text, image, audio, video, pdf), as most of the providers it lists serving it do, found as SeesImages finds it; nil when it doesn't know the model. The list is shared: the caller only reads it.

func IsOneLike

func IsOneLike(id string, like func(bare string) bool) bool

IsOneLike is IsOneOf for models a rule names by their id rather than a list: whether like takes the model of this id, by the id or any spelling IsOneOf hears (a relay's rename, a tag in brackets, ":official", the model the user said it is). like gets bare ids, lowercase. A rule kept so reaches a model newer than any list: provider.OffersUltra's every GPT Sol, Astra and Terra.

func IsOneOf added in v0.1.3277

func IsOneOf(id string, ids map[string]bool) bool

IsOneOf reports whether the model of this id is one of ids (bare, lowercase), matched as ContextOf and EffortsOf match it: by the id, a relay's rename (codex-gpt-6.1-sol, a tag in brackets), another spelling, or the model the user said it is the same as (UserSame). It is how a rule kept for some models by name reaches them on a relay that renames them.

func KeepFresh added in v0.1.426

func KeepFresh()

KeepFresh fetches the catalog whenever it is stale, now and every hour after, for as long as the process runs (the app's backend, `magpie serve`). It never returns.

A fetch that fails (models.dev unreachable, or hanging past fetch's bound) is tried again sooner than the hour, after retryFirst and then twice as long each time up to the hour, so a magpie started before the network or its proxy was up has the catalog fetched soon after (creeksuen on X). Until then the catalog read before answers, or the one magpie ships with (bundled.go).

func KeepFreshForTest

func KeepFreshForTest(url string) (restore func())

KeepFreshForTest has the catalog kept fresh from url, as the app's backend keeps it from models.dev, for a test of what asks for it.

func KinEfforts added in v0.1.1209

func KinEfforts(providers []string, id string) ([]string, bool)

KinEfforts are the reasoning levels of a model none of the providers named lists, taken from the newest of their thinking models of the same name but for its version (gpt-6.1-sol's from gpt-6-sol, mimo-v2.7-flash's from mimo-v2.6-flash): a model newer than the catalog on this machine offers its line's levels, not none. False when none of them has one.

func Kinds added in v0.1.2343

func Kinds(modalities []string) []string

Kinds is a list's modalities as models.dev words them (text, image, audio, video, pdf), each once and in the order first met. A vendor may list the media types it takes instead: OpenCode Go's /models gives deepseek-v4.1-flash ["text","image/jpeg","image/png","image/gif", "image/webp"] and Gemini's application/pdf, which read word for word were no "image", so every model there that sees was taken for text-only (zeo9901 on Discord). An unknown word is kept as it is; nil stays nil, a list that said nothing.

func Knows added in v0.1.680

func Knows(id string) bool

Knows reports whether models.dev lists a model of this id at all, under any provider, as ContextOf and EffortsOf match it.

A model it lists under another spelling alone (normalFor) counts.

func KnowsAsWritten added in v0.1.2015

func KnowsAsWritten(id string) bool

KnowsAsWritten is Knows without another spelling (normalFor): the usage report sends a model's id only when models.dev knows it as written, so an id a user typed that only folds into a known one ("Kimi K3.1 Pro 261024") is not sent.

func LabsPath added in v0.1.1681

func LabsPath() string

LabsPath is where Sync keeps models.dev's lab catalog (models.json), beside its provider catalog.

func ListedBy added in v0.1.404

func ListedBy(providers []string, id string) ([]string, bool)

ListedBy is the reasoning levels the first of providers (models.dev ids) listing a model of this id gives it — none, for one listed with a thinking switch alone or nothing at all — and whether any of them says. One listed with a thinking budget and no levels says nothing of them (Anthropic's claude-sonnet-4-5, whose budget an effort is sent as). The id is matched as EffortsOf matches it: without a vendor's prefix, in any case. It is how a model's maker is heard before its resellers: Xiaomi lists mimo-v2.6-flash with a switch alone, where gateways reselling it give levels up to max, which Xiaomi turns away (#214).

func ListedByBorrowed added in v0.1.1233

func ListedByBorrowed(providers []string, id string) ([]string, bool)

ListedByBorrowed is ListedBy for levels borrowed from another provider: it uses the levels the catalog lists, without adding a verified provider's toggle-only off level. A provider's API accepting "none" does not verify that a relay, reseller, or another provider does too.

func Lists added in v0.1.1294

func Lists(id string) bool

Lists reports whether models.dev lists a model by this very id (its last part, any case), not one found by another spelling: claude-opus-5.5 only when that is how one of its providers spells it.

func LiveAsked added in v0.1.3389

func LiveAsked(provider string) string

LiveAsked is what the provider's fetched list was asked as (SaveLiveAsked): "" when it wasn't said, or there is no list.

func LiveKey

func LiveKey(provider string) (key string, ok bool)

LiveKey names the list saved for provider by what it holds, not by when it was fetched: each account's list is fetched again every 45 minutes and on every start, and saved again with only its fetch time moved (saveLive). Usage keyed its whole index on the file's mtime, so each of those saves dropped it, and every start and every refresh read the whole session history again (~1.5 GB allocated, seconds of CPU). "missing" when there is no list; ok is false when it can't be read.

func LiveKinded added in v0.1.3040

func LiveKinded(provider string) bool

LiveKinded is whether the provider's fetched list was saved since lists keep the models made for other APIs (Model.Serves): one saved before left them out, and is fetched again once to have them (#5339).

func LiveListed added in v0.1.2434

func LiveListed(provider string) bool

LiveListed is whether Live lists any model, without the list copied.

func LiveNewest added in v0.1.3389

func LiveNewest(provider string) time.Time

LiveNewest is when the newest model in provider's list was first in it (LiveSince); zero when there is no list.

func LivePath

func LivePath(provider string) string

LivePath is where the fetched model list of one provider is kept.

func LiveSince added in v0.1.3389

func LiveSince(provider, model string) (since time.Time, ok bool)

LiveSince is when the provider's fetched list first had model, as far as magpie kept it: since the first save that listed it, or, for a list saved before that was kept, since that list's own fetch (no earlier one is known). ok is false when the list doesn't have it, or there is none.

func Loops added in v0.1.3367

func Loops(via []string) bool

Loops reports whether what another magpie passes on by way of via (a model's magpie_via, a quota card's Via) leaves this magpie and comes back to it, or has passed through more magpies than MaxVia.

func MagpieAdded added in v0.1.486

func MagpieAdded(etag, slug, description string) bool

MagpieAdded reports whether an entry of Codex's models_cache.json is one of magpie's, not Codex's own: the list Codex keeps is the one it was last handed, and handed through the gateway it has magpie's models in it too ("group/semantic", "deepseek/deepseek-v4", "codex/gpt-5.5" — magpie's ids, which Codex's slugs never look like). Read back as Codex's own, they were listed under OpenAI, and kept there after Codex was routed elsewhere.

func Missing added in v0.1.426

func Missing()

Missing says a call's model has no price: the catalog is fetched again, in the background, when it is older than six hours and wasn't tried in that time. Only in a process that keeps it fresh (KeepFresh), so a CLI command or a test never fetches on its own.

func NameOf added in v0.1.1079

func NameOf(id string) string

NameOf is the name models.dev gives a model of this id, as most of the providers it lists serving it do, matched as SeesImages matches it: without a vendor's prefix, in any case. "" when no provider names it other than by its id.

func NameWindow

func NameWindow(id string) int

NameWindow is the context window a model's name says it has, for a local or custom model nothing else says a window of (maohy915 on X: a "Qwen-3.8-27b-128k" he made himself): a last part of the id that is a number and a unit alone, set apart by "-", "_" or " " from what comes before it (or the last of an Ollama tag, "qwen:27b-128k"). k is 4 to 2048 thousand, m is 1, 2, 4, 5, 8 or 10 million, read as the same 1,000 and 1,000,000 a "[200k]" mark is (a name that rounds up never promises more than the model takes). Anything else is no window: a model's size (27b, pythia-14m, smollm-135m), its version, a date (gpt-4o-2024), a quant (q4_k_m), a lone "128k" with nothing before it. It is the last resort: the user's own, the server's and models.dev's windows are read before it.

func NearestEffort added in v0.1.1214

func NearestEffort(want string, levels []string) string

NearestEffort is the level of levels nearest want in EffortRank's order, a tie going up, never "none" unless it is want; want itself when levels are none, hold it, or want is no level EffortRank knows. The gateway fits an effort to a model's levels by it on the way out (fitEffort), and Codex's catalog gives a model the effort set for new sessions by it (codexcat.ModelDefault), so the level a model starts at is the one it would be sent at. A level is placed by the one it names (EffortLevel), so low is a model's light, and a model's levels go in its own words.

func NoChannel

func NoChannel(status int, body []byte) bool

NoChannel recognizes a relay (New API and its forks) answering 503 that no channel serves the model in the caller's group: the relay holds the model on some of its APIs and has no channel for it on the one asked, so another API of the same relay may serve it (equinox0253 on X: gpt-6.1-sol asked on a relay's Anthropic URL, where only its Claude models have a channel).

func OneAuth added in v0.1.1211

func OneAuth(h http.Header, only string)

OneAuth leaves h with the key in the one header only names: x-api-key alone, or Authorization alone.

func OneHourFor added in v0.1.1043

func OneHourFor(id string, p *Price)

OneHourFor gives a Claude model's price its 1-hour cache write where none is given — models.dev lists none, and a price the user gives may leave it out: 2× input, as Anthropic bills it for every model, wherever the model has a (5-minute) cache write price at all. Any other model's stays unset, its writes all at the 5-minute price: only Anthropic has a 1-hour one (PAMI on Discord: gpt-6-astra was shown a $20 one that isn't).

func OpenRouterPricing added in v0.1.1440

func OpenRouterPricing(pr Price) map[string]string

OpenRouterPricing is a price as OpenRouter's model list writes it (gateway /v1/models' and an agent plugin's connect's "pricing"), the shape agents and SDKs built on that list read: USD a token, as decimal strings. prompt and completion are always there, a price set at 0 included, since the price is known; a cache read or write only when it has a price, as a part a list leaves at 0 is one it doesn't give. The base price only: a model billed more above a prompt size (Tiers) tells what it costs below it, and the 1-hour cache write has no field there.

func OutputOf added in v0.1.100

func OutputOf(id string) int

OutputOf is the most tokens a reply from a model of this id may hold, as most of the providers serving it give it, or 0 when not known.

func Paged added in v0.1.1224

func Paged(list string, page func(at string) (more bool, last string, err error)) error

Paged asks a model list that pages for every page of itself: page asks for one page, at the URL given, and says whether another page follows and the id it starts after. The first page is asked at list as it stands, so a list that does not page is asked exactly as it always was, and each page after it at the same list with limit=PageLimit and after_id set to the id the page before ended at. It stops when a page says none follows.

What does not stop it leaves the list unread, and an unread list is no answer at all, as a page of it was (#904): a page that fails, a list that pages without naming the id to carry on from, one that answers the page just asked again under that same id, and one still paging after modelPages pages. Half a list is not a list — it is missing every model of the pages after, which the caller would take for models the vendor dropped, and would then drop from the user's picks.

A caller that has to ask the list itself, for the headers it takes or the shape it reads, pages it here rather than with a rule of its own (provider.kiloModels).

func PerToken added in v0.1.1440

func PerToken(perMillion float64) string

PerToken is a price of USD a million tokens as USD a token, written as a decimal: the decimal point moved, not the float divided, so $0.3 is "0.0000003" and not 2.9999999999999997e-07.

func PlanTierTimes

func PlanTierTimes(model, tier string) (float64, bool)

PlanTierTimes is the multiple of model's Standard rate a ChatGPT plan's included usage is drawn down at in tier ("priority" for Fast, "ultrafast"), and whether OpenAI says one (planTierTimes).

func PointsToChat added in v0.1.1214

func PointsToChat(text string) bool

PointsToChat is PointsToImagesAPI the other way round: a refusal on the images API that names chat completions as where the model draws.

func PointsToImagesAPI added in v0.1.1214

func PointsToImagesAPI(text string) bool

PointsToImagesAPI is whether a vendor's refusal of a chat request names its images API as the one the model is asked on: Agnes answers agnes-image-2.5-flash on chat completions with 400 "Model agnes-image-2.5-flash is an image model. Use /v1/images/generations" (#1837), a model ImagesAPI can't tell by its name from gemini's -flash image ones, which chat. The vendor's own words decide it then.

func PricedInYuan

func PricedInYuan(id string) bool

PricedInYuan is whether a models.dev provider sells in China's yuan rather than in dollars: one of yuanSellers, or one whose id ends in -cn, whose name says "(China)" or whose API is on a .cn host. Its models.dev prices are still in dollars, converted from the yuan; only how a cost of it is shown (Settings' currency "provider") asks this.

func ProviderName added in v0.1.39

func ProviderName(id string) string

ProviderName is a models.dev provider's display name ("GitHub Copilot" for "github-copilot"), or "" when the catalog doesn't know it.

func Providers

func Providers() []string

Providers returns models.dev provider ids known to the catalog.

func PutUserHeader added in v0.1.1160

func PutUserHeader(h http.Header, name, value string)

PutUserHeader writes a request header the user typed (a provider's own headers) onto h. Every header already there under the same name in any case is taken off first: Header.Set keys a name by its canonical form, while the user's goes in as typed (some gateways match names case-sensitively), so a "user-agent" or "authorization" typed in lower case used to ride beside magpie's own — two of the header, magpie's first (#1487, a relay that checks the client turned the request away).

User-Agent itself is kept under its canonical name: Go's HTTP/1 writer looks only there, and adds its own Go-http-client/1.1 when it finds none, ahead of a "user-agent" written in any other case.

func RelayOpenAIList

func RelayOpenAIList(base string) string

RelayOpenAIList is the model list of a relay that serves OpenAI's API under …/openai with no /v1 in the base, and its list at the root's /api/v1/models alone: claude-relay-service mounts its unified routes (/v1/chat/completions) and Codex's (/responses, /v1/responses) under /openai, and the models list on /api and /claude only (src/app.js, src/routes/api.js). "" for any other base. A list found there means chat is at the base's /v1 (Cyrus_4433 on X: …/openai was asked …/openai/chat/completions and answered 404 Not Found).

func Reset

func Reset()

Reset forgets the loaded catalog so the next call re-reads the cache, and tells Forget: what the provider package built of the old one (the windows and output limits of its entries) is kept between requests for a moment, and would answer for the old catalog meanwhile.

func Resets

func Resets() int64

Resets is how many times the catalog was forgotten for one that may differ (Reset). What was asked of the catalog before may be answered otherwise after, though the file's key (CacheKey) is the same: Sync writes the file first and resets after.

func SameModel added in v0.1.2015

func SameModel(id string) string

SameModel is a model's name as vendors agree on it: lowercase, without the vendor's own prefix ("anthropic/claude-sonnet-5" is claude-sonnet-5, "accounts/fireworks/models/…" too), with a version's dot as Anthropic writes it ("claude-opus-5.5" is claude-opus-5-5, and so is Fireworks' "p" for the dot, "deepseek-v4p1"), a run of spaces, "_" and "-" as one "-" (a relay that lists its display name as the id, "GPT-6 Sol", is gpt-6-sol: Chill on Discord), and without the snapshot date some add: "claude-opus-5-5-20260801", Vertex's "…@20260801", and Volcengine Ark's six digits ("deepseek-v4-1-flash-260910" is deepseek-v4-1-flash, #583). Anything else stays: a variant after ":" (":batch"), -flash, -thinking, and a four-digit release (qwen's -2507, kimi-k2-0905) that is a model of its own. So does OpenAI's dashed date ("gpt-4o-2024-08-06"): a pinned snapshot apart from the alias that moves, and an id that has had a group of its own (auto-gpt-4o-2024-08-06) agents and saved groups name. An id spelt with spaces merges with its dashed spelling, whose group id (Slug's) it had already.

The provider package groups models by it, and the catalog finds a model models.dev lists under another spelling by it (normalFor).

func SaveLive

func SaveLive(provider, base string, models []Model) error

SaveLive stores a fetched list; an empty list forgets it.

func SaveLiveAsked added in v0.1.3389

func SaveLiveAsked(provider, base, asked string, models []Model) error

SaveLiveAsked is SaveLive for a list whose answer depends on what it was asked as (liveFile.Asked), kept beside it for LiveAsked.

func SaveLiveSides added in v0.1.1224

func SaveLiveSides(provider, base string, models []Model, sides map[string][]Model) error

SaveLiveSides is SaveLive, keeping what each endpoint answered with beside the merged list (LiveSplit): a provider whose protocols sit at bases of their own asks every base, and a base that can't be asked next time has to know which of the models were its own to keep (#904).

func Seed

func Seed()

Seed writes the shipped copy where Sync keeps the catalog when no catalog file is there, or the one there is older than the copy, dated when the copy was taken: Stale says so once it is a day old, and the fetch that follows replaces it. A sync in progress is left to finish, and a copy that can't be written is still read from the binary (load). It is cheap when there is nothing to do, a stat or two.

func SeesImages added in v0.1.44

func SeesImages(id string) bool

SeesImages reports whether models.dev says a model of this id takes images, as most of the providers it lists serving it do; for a vendor it doesn't list, serving a model it knows from others ("z-ai/glm-5.3" is glm-5.3).

func Self added in v0.1.3007

func Self() string

Self is this run of magpie's name in magpie_via: random, made up once a run, and told only to a magpie that asks for its list.

func ServesOf added in v0.1.3040

func ServesOf(id string) string

ServesOf is the API a model's id says it is made for, other than chat, images or video: "" for any other model. Read from the id alone, as vendors' OpenAI-style lists say no more (text-embedding-3-small, bge-reranker-v2-m3, tts-1, gpt-4o-mini-tts, whisper-1, gpt-4o-transcribe). Voyage AI makes embedding models alone, and names them voyage-* (voyage-4, voyage-code-3), with no "embed" in the id.

func SetSelfForTest added in v0.1.3367

func SetSelfForTest(s string) (restore func())

SetSelfForTest has Self be s, for a test that plays several magpies in one process one after another, until the returned func puts it back.

func Source

func Source() string

Source reports which catalog file is in use ("" when only built-ins are).

func Spelling added in v0.1.2104

func Spelling(id string) string

Spelling is the spelling models.dev gives a model most, of every bare id it knows that is the same model (SameModel): glm-5.3-flash for glm-5-3-flash, GLM-5.3-Flash or Ark's glm-5-3-flash-260828, as most of its providers spell it (the normal index normalFor reads). Lowercase, without a vendor's prefix; "" when it knows the model by no spelling.

func Stale

func Stale() bool

Stale reports whether no catalog exists or the cache is older than a day (fresh.go), or magpie's has no lab catalog or v2 embedding models beside it yet (labs.go, embeddings.go).

func Sync

func Sync(ctx context.Context) error

Sync downloads the models.dev catalog into CachePath. It serializes with itself so a background refresh and a manual one cannot interleave writes.

func SyncIfMissing added in v0.1.1240

func SyncIfMissing(ctx context.Context) error

SyncIfMissing is Sync, but returns nil if a catalog already exists once the lock is acquired.

func Thinks added in v0.1.572

func Thinks(id string) bool

Thinks reports whether models.dev says a model of this id reasons, as most of the providers it lists serving it do, whether or not they give it levels; for a vendor it doesn't list, serving a model it knows from others.

func TierTimes

func TierTimes(model, tier string, at time.Time) (float64, int)

TierTimes is the multiple of model's standard rate OpenAI bills tier at a call made at at (tierTimes), and which of its rates that is, for a cache to tell calls on either side of a change apart; 0 when the tier isn't priced that way. A zero at is now.

func TogetherAPI

func TogetherAPI(u string) bool

TogetherAPI says u is Together AI's API, whose model list says what each model is for (its "type").

func Touched added in v0.1.54

func Touched()

Touched tells Forget and Changed, if set.

func Unprefixed

func Unprefixed(catalogs []string, id string) string

Unprefixed is the model a provider's id is when the provider lists it without its maker's name in front, by what the provider's own catalogs (models.dev ids, first match wins) say of that very id: the spelling models.dev gives the model (Spelling), "" when nothing says so.

Kimi Code lists Kimi K3.1 Pro as k3.1-pro and K3 as k3, whose entries models.dev gives the canonical_model_id moonshotai/kimi-k3.1-pro and moonshotai/kimi-k3; OpenCode Go and Devin serve them as kimi-k3.1-pro, so the group magpie found for the model left Kimi Code out (tmr11235 on X). A relay's minimax/m3.1-flash is MiniMax-M3.1-Flash the same way.

Only a dropped prefix counts, never the canonical id alone: models.dev gives Kimi Code's k3.1-pro-highspeed the canonical kimi-k3.1-pro and k3-256k kimi-k3, which are other models (another speed, another window). So the id is the canonical's with a maker's name taken off the front — words of letters, "kimi-", "minimax-" — and nothing else: k3.1-pro is kimi-k3.1-pro, never kimi-k3.1 nor kimi-k3. An id that goes on past the canonical (k3.1-pro-highspeed past kimi-k3.1-pro) is that maker's name in front of the whole id, kimi-k3.1-pro-highspeed, only where models.dev knows a model by it; k3-256k, whose kimi-k3-256k it doesn't, stays its own.

func Unsuffixed added in v0.1.1441

func Unsuffixed(id string) (string, bool)

Unsuffixed is id with a proxy's level or speed word taken off (variantSuffix), and whether it had one. It is for borrowing levels a model has no word on alone: the vendor's own list, which may name a model so, goes first.

func VercelGateway

func VercelGateway(u string) bool

VercelGateway reports whether u is at Vercel's AI Gateway (ai-gateway.vercel.sh), whose model list marks each row's type.

func Versioned added in v0.1.332

func Versioned(base string) bool

Versioned reports whether an API base URL has a version in its path — a segment like v1, v3, v4 or v1beta — and so names the vendor's API as it is, with no /v1 left out of it.

func ViaHere added in v0.1.3007

func ViaHere(came []string) []string

ViaHere is the magpie_via a model goes out with in this magpie's list to another: the way it came here by, when it came from another magpie, then this one.

func WholeOf

func WholeOf(id string, window int) int

WholeOf is the context window, prompt and reply together, that models.dev gives model id beside an input limit of window: 1050000 for gpt-6.2-sol told 922000, the input limit Context holds (window). 0 when none of its entries pairs that input limit with a larger context: a window the user typed, or one a vendor's own list gives, is a window of its own, and an agent that takes both (OpenCode's limit.context and limit.input) is told it alone, as before. The id is looked up as ContextOf looks it up: a relay's spelling or a snapshot of it.

func Window added in v0.1.1214

func Window(n int) int

Window is n as a model's context window: n, or 0 — not known, for models.dev, a family's window or the agent's default to answer — when n is under LeastWindow.

func WithListAuth added in v0.1.1211

func WithListAuth(ctx context.Context, only string, learned func(string)) context.Context

WithListAuth has a model list asked under ctx send its key in the one header only names ("" both), and, sending both, ask again with each alone when the vendor refuses the two together, telling learned the one it took.

func WithListSigner

func WithListSigner(ctx context.Context, sign func(*http.Request) error) context.Context

WithListSigner is ctx with sign called on each request for a model list made under it, last, once its headers are set: a list asked with a signature in place of a key (Amazon Bedrock with an AWS access key, #7687). An error from sign is the list's.

func Words added in v0.1.1710

func Words(body []byte) []byte

Words is an error body as its words are matched: a JSON body that escapes what isn't ASCII as \uXXXX (Python's json.dumps does by default) has its strings decoded and put after it, one to a line, so "用量", "频率" or "将在 … 重置" are read whether the vendor escaped them or not (#1669). Any other body is matched as it is.

func WrongEndpoint added in v0.1.1710

func WrongEndpoint(status int, body []byte) bool

WrongEndpoint recognizes the errors OpenAI-compatible servers give when a model exists but isn't served on the endpoint asked: the gateway asks the model on another API the provider has then, and so does a model's test.

func YuanHost

func YuanHost(base string) bool

YuanHost is whether a base URL is on a .cn host, a mainland Chinese vendor's, which sells in yuan.

Types

type Family added in v0.1.2110

type Family struct {
	Name     string // the id without its version, snapshot or preview
	Version  []int  // every version number, in the order the id has them
	Snapshot string // its dates or revision, "" for an alias
	Preview  bool
}

Family is what an id's name says about it: the family it belongs to and where it stands in it.

func FamilyOf added in v0.1.2110

func FamilyOf(id string) Family

FamilyOf reads id's family off its name.

type ListError

type ListError struct {
	URL, StatusText, Msg string
	Status               int
}

ListError is a model list the vendor answered with an error status: Status is it, for a caller to tell a refused key (401) from the rest.

func (*ListError) Error

func (e *ListError) Error() string

type Listed added in v0.1.1224

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

Listed is what one fetch of a provider has asked for one key: every list URL it asked at, under the authentication it asked it with, and the models of the ones that answered. A caller asking several bases of one provider passes the same Listed to each of them (FetchAtListed), so no list is fetched twice and no request is made twice.

func NewListed added in v0.1.1224

func NewListed() *Listed

NewListed is an empty record of one fetch's model list requests.

type ListsFailed

type ListsFailed struct {
	Msg    string
	Status *ListError
}

ListsFailed is a model list asked at none of its URLs, in the words each was refused with, carrying the first error status a vendor answered (ListError) for errors.As to find.

func (ListsFailed) Error

func (e ListsFailed) Error() string

func (ListsFailed) Unwrap

func (e ListsFailed) Unwrap() error

type Model

type Model struct {
	ID          string // e.g. "claude-sonnet-5"
	Name        string // display name
	Provider    string // models.dev provider id
	Released    string // YYYY-MM-DD, used for ordering
	Efforts     []string
	Temperature *bool  // false when the model refuses temperature/top_p
	Price       *Price // USD per million tokens, when models.dev lists it
	// Keys, for a vendor whose keys each see models of their own, are the
	// keys (by fingerprint) whose list has this one; empty is every key.
	Keys []string `json:",omitempty"`
	// EffortsBorrowed is set when Efforts are not the source's word but
	// borrowed for its id (a plugin's model that thinks with no variants):
	// a model listed by another id (provider's localIDs) borrows them for
	// that id again.
	EffortsBorrowed bool `json:"-"`
	// APIs, when the vendor says, are the APIs the model is served on
	// ("chat", "responses", "anthropic"); empty is not known.
	APIs []string `json:",omitempty"`
	// Prefers, on a model of another magpie's list, is the API that magpie
	// asks it on best (magpie_prefers): "responses" for a GPT its OpenAI
	// key or ChatGPT sign-in is best asked on there, or a routing group
	// whose members are; "" when it didn't say.
	Prefers string `json:",omitempty"`
	// Endpoints, in magpie's own models for an agent, are the gateway
	// paths a request for it is relayed on as it is
	// (provider.NativeEndpoints, /v1/models' native_endpoints); a group's
	// are those every member relays (provider.GroupEndpoints), which
	// /v1/models leaves out; none for a model translated anyway.
	Endpoints []string `json:"-"`
	// Images is set on a model that takes images as input.
	Images bool `json:",omitempty"`
	// ImageInput is the source's explicit answer; nil means it did not say.
	ImageInput *bool `json:",omitempty"`
	// InputModalities and OutputModalities are what the model takes and
	// gives (text, image, audio, video, pdf) as its source listed them;
	// nil is not said. Images (and the user's override of it) still
	// decides "image" (provider.Entry.Modalities).
	InputModalities  []string `json:",omitempty"`
	OutputModalities []string `json:",omitempty"`
	// Context is how many tokens a prompt may hold, when known: models.dev's
	// input limit, else its context window.
	Context int `json:",omitempty"`
	// MaxContext is the most a prompt may hold when asked for, above
	// Context: Codex's max_context_window (872k on GPT-6, 272k by default).
	MaxContext int `json:",omitempty"`
	// Output is the most tokens a reply may hold, when known.
	Output int `json:",omitempty"`
	// OutputSet is set when Output is a Max output the user typed for the
	// model or its provider (provider.Entry.OutputSet): an agent that trims
	// a vendor's figure for its own reasons hands this one on as it is.
	OutputSet bool `json:"-"`
	// Compact is where the user has Codex compact a conversation on this
	// model (#876), its own or its provider's (settings.ModelCompacts), or
	// Context itself when that is a window the user typed (#1809,
	// provider.CompactFor): the window it is told when Context is longer.
	// 0 is none set, for the one for every model (settings.Compact).
	Compact int `json:",omitempty"`
	// Plain, on a model of another magpie's list, is its name there alone
	// (display_name), when Name is its label there, with that magpie's
	// provider after it (magpie_label): the name Provider in model names
	// Off has here (ARNO on Discord).
	Plain string `json:",omitempty"`
	// By, on a model of another magpie's list, is the provider that
	// magpie names as serving it (magpie_by): its own provider's name, or,
	// for a model it has from a magpie further on, the one there, the
	// first in the chain. Its Remote magpie's upstream names (Provider's
	// UpstreamProviders) say it after the model (lcc580 on X).
	By string `json:",omitempty"`
	// Via, on a model of another magpie's list, is the magpies it passes
	// through to its vendor, that one last (magpie_via.go)
	Via []string `json:",omitempty"`
	// Apart, in a list magpie hands Codex, is what tells the model from
	// another entry Codex's picker would call the same (two providers
	// named Codex each serving GPT-6.1-Sol, nb5p on Discord): its
	// provider's id. Said in the entry's display_name alone
	// (codexcat.Entries), which stays in Codex's picker; never in its
	// description or Name, which go upstream in spawn_agent's list of
	// models. Kept in the list's tag, so a change has Codex ask again.
	Apart string `json:",omitempty"`
	// Fast is set on a model Codex may ask for priority processing (its
	// Fast mode): one a ChatGPT account serves.
	Fast bool `json:",omitempty"`
	// Seals is set on a model whose provider seals a multi-agent V2
	// lead's subagent tasks as the ChatGPT backend does: one of no sign-in
	// on the Responses API (a relay of that backend, Sub2API or CPA,
	// #1109; OpenAI's own API), or a group with such a member. With
	// "subagents on any model" (settings.CodexAgentsV1) its Codex entry
	// says V1 as the ChatGPT account's do (codexcat.Entries; brethhbbm on
	// X: relay/gpt-6-astra kept its subagents).
	Seals bool `json:",omitempty"`
	// Tiers, in one ChatGPT account's own model list, are the service
	// tiers its plan offers on the model ("priority", "ultrafast"); in
	// another magpie's, the tiers it offers its Codex on the model
	// (#1234); in a provider plugin's, the tiers it says its vendor serves
	// the model at (#2514).
	Tiers []string `json:",omitempty"`
	// OwnTier is set on a model of a provider the user added by its
	// address, which the gateway sends the tier Codex asks for as it is
	// (gateway Request.Tier): Codex offers it the tiers of its own entry
	// for the same model, Fast on another GPT model.
	OwnTier bool `json:",omitempty"`
	// CodexFast is set on a GPT model a ChatGPT account serves itself, not
	// through a routing group: one Codex's /fast (service_tier "priority")
	// is asked of, which OpenCode is offered as fast variants (#2379).
	// Not kept with a list: it is the provider's, worked out each time.
	CodexFast bool `json:"-"`
	// AgentsV2 is set on a model Codex is told multi-agent V2 for, so its
	// Ultra hands work to Codex's agents: one offering Ultra that no
	// ChatGPT account answers for (provider.Entry's).
	AgentsV2 bool `json:",omitempty"`
	// Draws is set on a vendor-listed model that makes images (gpt-image-1,
	// a relay's flux): kept with the list for Settings → Models → Images, never
	// offered to agents as a model to talk to.
	Draws bool `json:",omitempty"`
	// Films is set on a model another magpie lists as one it makes videos
	// with (a Remote magpie's Grok Imagine Video): kept with the list for
	// its videos API, never offered as a model to talk to or draw with.
	Films bool `json:",omitempty"`
	// Serves is set on a vendor-listed model made for an API other than
	// chat, images or video (ServesEmbedding, ServesRerank, ServesSpeech,
	// ServesTranscription): kept with the list for that API's routes and
	// their groups of one kind (provider.KindGroup), never offered to
	// agents as a model to talk to (#5339, XYenon on Discord).
	Serves string `json:",omitempty"`
	// Decides marks a decision model another magpie explicitly lists,
	// including models whose ids don't name Jev.
	Decides bool `json:",omitempty"`
	// Free is set on a model a subscription serves at no cost to its
	// allowance: WorkBuddy's "credits": "x0.00", OpenCode Go's
	// "monthly_usage": null.
	Free bool `json:",omitempty"`
	// Rate is what a request costs of a subscription's credits, as a
	// multiple, when its vendor lists it: Qoder's price_factor (0.5),
	// WorkBuddy's "credits": "x0.03". 0 is not listed, or Free.
	Rate float64 `json:",omitempty"`
	// RateWas is the rate before a discount running now, when the vendor
	// says it: Qoder's Qwen3.8-Flash at 0× with 0.1× struck through.
	RateWas float64 `json:",omitempty"`
	// Reasoning is set on a model that thinks, whether or not it takes
	// levels: mimo-v2.6-flash thinks with a switch alone (#402).
	Reasoning bool `json:",omitempty"`
	// AlwaysThinks is set on a model its vendor's list says always thinks,
	// with no way to turn it off: Kimi Code's supports_thinking_type
	// "only" (reasoning.type). Kimi Code is told always_thinking for it.
	AlwaysThinks bool `json:",omitempty"`
	// AsksAdaptively is set on a routing group dsh asks on Messages whose
	// every member is asked adaptively there (gateway.AsksAdaptively,
	// which a group's own id doesn't answer): dsh gives it pi-ai's
	// forceAdaptiveThinking, as it does such a member alone, so its xhigh
	// and max aren't clamped to a high budget (#6778).
	AsksAdaptively bool `json:",omitempty"`
	// DynamicTools is set on a model its vendor's list says loads tools
	// mid-conversation: Kimi Code's supports_dynamic_tools
	// (tools.dynamic_load). Kimi Code is told dynamically_loaded_tools.
	DynamicTools bool `json:",omitempty"`
	// DefaultEffort is the effort the vendor's list says the model thinks
	// at when none is asked: Kimi Code's think_efforts.default_effort
	// (reasoning.effort.default). "" is not said.
	DefaultEffort string `json:",omitempty"`
	// WebSearch is how another magpie (a Remote magpie) searches the web
	// for the model when a web search tool is offered: "native", its own
	// provider by itself, or "magpie", with that magpie's searcher; "" it
	// doesn't, or didn't say. A plugin's model it says searches by itself
	// (m.searches) is "native" too.
	WebSearch string `json:",omitempty"`
	// Codex, on a model a vendor lists the way Codex's own catalog does
	// (a sub2api asked with Codex's client_version), is that entry as the
	// vendor gave it (CodexEntry): Codex is handed it as it is, its
	// instructions and window and all, rather than an entry magpie made up
	// from models.dev (ctopsc on Discord). Its context_window,
	// max_context_window, input_modalities and reasoning levels are read
	// into the fields above too, so the rest of magpie says what it says.
	Codex json.RawMessage `json:",omitempty"`
}

Model is one entry the picker can offer.

func BestInFamily added in v0.1.2110

func BestInFamily(ms []Model) []Model

BestInFamily is ms with only the newest model of each family left (FamilyOf, newerInFamily), in the order ms has them. A family's first listed wins a tie.

func Chat added in v0.1.340

func Chat(ms []Model) []Model

Chat is ms without the models that draw, make videos or are made for another API (Model.Serves).

func Codex

func Codex() []Model

Codex returns the models Codex itself lists, straight from the cache the Codex CLI writes; there is no compiled-in list to fall back to.

func CodexShared

func CodexShared() []Model

CodexShared is Codex's list without a copy, for a caller that only reads it: the effort field asks for it on every poll.

func Decorate

func Decorate(live []Model, known []Model) []Model

Decorate fills in names and reasoning levels for live models from the catalog's entry for the same id, keeping the live order.

func Describe added in v0.1.1681

func Describe(id, name string) Model

Describe is a model a vendor or an account lists by id, described as models.dev knows it on any host — most providers' word, else its lab's — for a list that has it where the provider's own catalog doesn't: its window, reply limit, thinking, levels, images and release. name is the list's own, kept when it gives one. It has no price: a lab gives none, and another host's isn't this one's.

func Drawers added in v0.1.338

func Drawers(id string) []Model

Drawers are the models of one models.dev provider that make images, newest first.

func Fetch

func Fetch(ctx context.Context, base, key string, anthropic bool, headers map[string]string) ([]Model, error)

Fetch asks an endpoint for its models. base is an API base URL of any flavour (…/v1, …/anthropic, …/api); the usual list paths are tried around it. The result keeps the server's order. anthropic sends the Anthropic version header, which the official API requires but which a dual-protocol relay like OpenRouter reads as a request for its Anthropic-flavoured catalog — namespaced, differently named ids.

func FetchAt added in v0.1.65

func FetchAt(ctx context.Context, base, key string, anthropic bool, headers map[string]string) ([]Model, string, error)

FetchAt is Fetch, and says which URL answered. An OpenAI-style base with a version in its path (…/v1, …/api/plan/v3, …/api/paas/v4, …/v1beta/openai) names the vendor's API as it is and is asked only as written, at base/models: a /v1 is looked for only around a base without one (a bare host, a relay's …/api), where it may have been left out. An Anthropic base is the root /v1/messages is asked at, so /v1/models under it is its own list. When no URL answers, the error names each one asked and what it said.

func FetchAtListed added in v0.1.1224

func FetchAtListed(ctx context.Context, base, key string, anthropic bool, headers map[string]string, listed *Listed) ([]Model, string, error)

FetchAtListed is FetchAt over a provider's several bases, and over what one of them has already asked. listed is the record of this key's requests so far (NewListed), and the key of a request is the list URL it is made at and the authentication it is made with — Bearer, or the Anthropic version header with it.

Two rules follow, and both are what make a multi-protocol vendor's models findable without asking its list twice (#1006). A list URL this key has already listed is not asked again, by any protocol: the answer is the answer, so a …/v1 base and the bare host beside it that speaks Anthropic are one /v1/models, fetched once. And a request already made is not made again — but a URL refused under one authentication is not refused under the next, so the Gemini list of a base whose Chat request was answered 401 is asked, with x-goog-api-key, instead of being taken for a list already had.

func FetchGemini added in v0.1.1125

func FetchGemini(ctx context.Context, base, key string, headers map[string]string) ([]Model, string, error)

FetchGemini lists the models at a Gemini API's base (…/v1beta), as Google's Gemini API lists them: GET models, the key in x-goog-api-key, a page at a time (nextPageToken), each named models/{id} with the methods it serves. Only those that serve generateContent are kept: the list also has embedding models (embedContent), Imagen's (predict) and Veo's (predictLongRunning), which no agent can talk to (#1346). It answers the URL it asked first.

func FetchURL added in v0.1.85

func FetchURL(ctx context.Context, url, key string, anthropic bool, headers map[string]string) ([]Model, error)

FetchURL asks for the model list at exactly url.

func Live

func Live(provider string) (models []Model, fetched time.Time, ok bool)

Live returns the model list last fetched from the provider, if any: the models to talk to, without the ones that draw (LiveDrawers).

func LiveAll added in v0.1.1218

func LiveAll(provider string) (models []Model, ok bool)

LiveAll is the whole model list last fetched from the provider, the models that draw or make videos among them, with each one's keys: what tells which of the provider's keys serves an image model (#1657), which Live, the models to talk to, leaves out.

func LiveByID added in v0.1.1269

func LiveByID(provider, model string) []Model

LiveByID are the models of Live with this id, in the list's order (one since Unique; a slice for the callers that read it so): what a look through Live finds, without the list copied for each model asked about.

func LiveByIDShared added in v0.1.2449

func LiveByIDShared(provider, model string) []Model

LiveByIDShared is LiveByID without the copy, for a caller that only reads it: asked for a model's APIs, price or tiers for every model a page lists, the copies were 32 MB of a live magpie's 2.6 GB in a minute and a half.

func LiveDrawers added in v0.1.340

func LiveDrawers(provider string) []Model

LiveDrawers are the models in the provider's fetched list that make images, in the list's order.

func LiveServing added in v0.1.3040

func LiveServing(provider, serves string) []Model

LiveServing are the models in the provider's fetched list made for the API serves names (Model.Serves), in the list's order; "" is every such model, whatever its API.

func LiveSplit added in v0.1.1224

func LiveSplit(provider string) (sides map[string][]Model, all []Model, ok bool)

LiveSplit returns the provider's fetched list as every endpoint's own part of it: sides[base] is what that endpoint listed, and all is the whole list those parts were merged into. ok is false where there is no list at all; sides is nil for a list saved without its parts, where every endpoint answered alike.

func LiveVideomakers added in v0.1.651

func LiveVideomakers(provider string) []Model

LiveVideomakers are the models in the provider's fetched list that make videos, in the list's order.

func Named added in v0.1.1079

func Named(ms []Model, reserved ...Model) []Model

Named gives a model the list names by its id alone the name models.dev knows it by (NameOf), so one model reads the same under every provider: a GLM Coding Plan's glm-5-turbo, which Zhipu's catalog doesn't list, is GLM-5-Turbo as ZCode's is. Its id, and where requests go, stay as they are. A supplemented name shared by different ids falls back to the id. Already named models in reserved count toward collisions but stay as given.

func Provider

func Provider(id string) []Model

Provider returns the text models of one models.dev provider, newest first. The list comes from the synced models.dev catalog; nothing is compiled in. A vendor's own /models answer, once fetched, is layered over it by the provider package (see provider.Provider.Available).

func ProviderShared

func ProviderShared(id string) []Model

ProviderShared is Provider without the copy, for a caller that only reads it: every provider's model list is built from it on each look at the catalog, and the copies were a third of what building them took.

func PublicDrawers added in v0.1.345

func PublicDrawers(ctx context.Context, base string) []Model

PublicDrawers are the image models the public catalog for base's host lists, marked as drawing; nil when there is none or it can't be read.

func Unique

func Unique(ms []Model) []Model

Unique is ms with each model id once (#6582: some APIs list a model more than once, and every copy was a row of its own in the pickers, the gateway's /v1/models and the agents' lists). The first keeps its place, and what it leaves unsaid is taken from the copies after it, as the lookups by id (LiveByID's callers) already took the first copy that said it: a name other than the id, a window, an output cap, levels, a price, the APIs, tiers, the magpies on its way and the keys that list it. ms comes back as it is when no id is in it twice.

func WithDrawers added in v0.1.345

func WithDrawers(ms, drawers []Model) []Model

WithDrawers adds the drawers not already in ms.

type Peak added in v0.1.2173

type Peak string

Peak names the hours a list price is the off-peak price of: a call made in them is billed at PeakFactor times it. DeepSeek bills its models at half price off-peak, and models.dev lists that half as the price, with a multiplier for the peak hours its api.json leaves out (providers/deepseek/models/deepseek-flash.toml: "Base prices below are off-peak; the multiplier doubles them at peak"). Empty: the price holds at every hour.

const (
	// PeakDeepSeek is DeepSeek's own: 01:00 to 04:00 and 06:00 to 10:00
	// UTC, Monday to Friday, never on a Chinese public holiday
	// (https://api-docs.deepseek.com/quick_start/pricing)
	PeakDeepSeek Peak = "deepseek"
	// PeakWeekdays is the same hours on every weekday, holidays too: what
	// Command Code (https://commandcode.ai/docs/resources/pricing-limits)
	// and OpenCode Go (https://opencode.ai/docs/go) bill DeepSeek's models
	// at, neither of which names a holiday
	PeakWeekdays Peak = "weekdays"
	// PeakOllama is Ollama Cloud's: 12:00 to 18:00 UTC, Monday to Friday
	// (https://ollama.com/pricing: off-peak outside 12:00 and 18:00 UTC on
	// weekdays, and all of Saturday and Sunday), where its
	// off-peak rows are half its peak ones and models.dev lists the
	// off-peak row as the price. It names no holiday.
	PeakOllama Peak = "ollama"
)

func (Peak) At added in v0.1.2173

func (k Peak) At(t time.Time) bool

At is whether a call made at t is in the peak hours. A zero time, a call whose time isn't known, is not.

type Price

type Price struct {
	Input      float64 `json:"input"`
	Output     float64 `json:"output"`
	CacheRead  float64 `json:"cache_read"`
	CacheWrite float64 `json:"cache_write"`
	// CacheWrite1h is what a cache write kept for an hour costs, Anthropic's
	// 1-hour TTL, which it bills at 2× input where a 5-minute write (the
	// CacheWrite above) is 1.25×. 0 is not given: such a write is then
	// counted at the 5-minute price, as no other vendor has an hour's
	// writes to bill apart; a Claude model's is 2× input (OneHourFor).
	CacheWrite1h float64 `json:"cache_write_1h,omitempty"`
	// Tiers are the prices a request is billed at, whole, once its input
	// goes over a size (OpenAI's gpt-6-astra: 2× input and cache, 1.5×
	// output above 272K), lowest first. models.dev lists them as "tiers" of
	// type "context".
	Tiers []Tier `json:"tiers,omitempty"`
	// Peak, when set, says this is an off-peak price, billed at PeakFactor
	// times it in Peak's hours (Price.In): a DeepSeek model's list price at
	// a provider that bills by DeepSeek's hours. A price the user set has
	// none.
	Peak Peak `json:"peak,omitempty"`
}

Price is what a model costs, in USD per million tokens.

func MakerPriced added in v0.1.2049

func MakerPriced(prefer []string, id string) (Price, bool)

MakerPriced is the list price the model's own maker gives it: priced by PricedBy at one provider alone, the first of prefer that is an API of the model's maker (ownAPI), else the first by id of the providers that list it as their own (madeByOf). A model a lab sells itself is costed at the lab's price rather than a reseller's that a maker catalog asked before it lists: Mistral sells DeepSeek's deepseek-v4.1-flash-1017 at $0.30/$1.20, DeepSeek's own price is $0.15/$0.60 (bestony on Discord: a Command Code call costed at the model's official price), and Meta's muse-spark-1.2 and Sakana's fugu-ultra, which no maker preset lists, are priced too. False when no provider lists it as its own, or none of those prices it.

func PriceOf

func PriceOf(providerID, modelID string) (Price, bool)

PriceOf is the list price of a models.dev provider's model, if known.

func PricedBy added in v0.1.411

func PricedBy(providers []string, id string) (Price, bool)

PricedBy is the list price the first of providers (models.dev ids) pricing a model of this id gives it: by its own key first, then by its id without a path or case ("openai/GPT-6-Sol" is gpt-6-sol), a Bedrock profile's geography, a "(variant)" or a ":tag"; then with a dot taken for a dash, then as the model an entry names as its canonical_model_id (DeepSeek's deepseek-flash is deepseek-v4.1-flash).

func TierPrice

func TierPrice(std Price, model, tier string, at time.Time) (Price, bool)

TierPrice is what a model's maker bills it at a service tier, as models.dev lists it under the model's modes, when std is the model's standard price there: a price a user, a relay or another vendor set is theirs, and isn't moved. The tier is OpenAI's service_tier word ("priority", Fast's; "ultrafast"; "flex") or "fast", Claude's speed (bodyTier). OpenAI's pricing page has gpt-6.1-sol's Fast (Priority processing until 2026-07-30) at $4/$20/$0.20 cached, twice its standard, and Ultrafast at six times; Anthropic's has Claude Opus 5.5's fast mode at $8/$40, twice too, "across the full context window". A mode lists no long-context price or 1-hour cache write, so std's are scaled by the mode's own ratio to std, part by part.

A tier OpenAI prices as a multiple of the standard rate that changes on a date (tierTimes: GPT-6.2's Ultrafast, which models.dev lists with no cost) is std times the multiple in force at at, the call's own time.

func (Price) At added in v0.1.1032

func (p Price) At(prompt int) Price

At is the flat price a request whose input, cached and cache-written tokens included, comes to prompt tokens is billed at: that of the highest tier it is over, else the base price. OpenAI counts a request's input with its cached tokens in it, and bills the whole request at the tier.

func (Price) Cost

func (p Price) Cost(input, output, cacheRead, cacheWrite int) float64

Cost of a call at this price, every cache write a 5-minute one. Reasoning tokens are billed as output by every vendor, and are already inside the output count.

func (Price) CostSplit added in v0.1.1032

func (p Price) CostSplit(input, output, cacheRead, cacheWrite, cacheWrite1h int) float64

CostSplit is Cost where cacheWrite1h of the cacheWrite tokens were written for an hour, billed at that price, and the rest for 5 minutes. The whole call is billed at the tier its input reaches.

func (Price) In added in v0.1.2173

func (p Price) In(t time.Time) Price

In is the price a call made at t is billed at: PeakFactor times this one in its peak hours, else this one. The price it gives holds at every hour.

func (Price) OneHour added in v0.1.1032

func (p Price) OneHour() float64

OneHour is what a 1-hour cache write costs at this flat price: the price given, else the 5-minute one (a Claude model's is given, OneHourFor).

func (Price) Same added in v0.1.1032

func (p Price) Same(q Price) bool

Same is whether two prices are the same in every part and tier.

func (Price) Times added in v0.1.901

func (p Price) Times(r float64) Price

Times is the price at r times each of its parts.

func (*Price) UnmarshalJSON added in v0.1.1032

func (p *Price) UnmarshalJSON(b []byte) error

UnmarshalJSON reads a price as magpie writes it, and as models.dev does, whose tiers name their size as {"tier": {"type": "context", "size": N}} and may leave a part out, which is then the base price's. A tier of another type, or of no size, is left out.

type Tier added in v0.1.1032

type Tier struct {
	Above        int     `json:"above"`
	Input        float64 `json:"input"`
	Output       float64 `json:"output"`
	CacheRead    float64 `json:"cache_read"`
	CacheWrite   float64 `json:"cache_write"`
	CacheWrite1h float64 `json:"cache_write_1h,omitempty"`
}

Tier is a price from a request's input size on: what the whole request costs once its input, cached and cache-written tokens included, is over Above tokens.

Jump to

Keyboard shortcuts

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