From 65bd4e4f724121bc66800d5cb431dc9ce7c046f2 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 29 Oct 2026 18:59:08 +0800 Subject: [PATCH] provider: a model is priced at its maker's own API before a reseller's (bestony on Discord) bestony on Discord (#feedback) asked that a subscription with no price of its own, such as Command Code, be costed at the model's official list price. magpie already estimates every subscription at the maker's list price, but the maker step (PricedBy over the maker presets) took the first preset that listed the id, and Mistral resells other labs' models: deepseek-v4.1-flash-1017 was costed at Mistral's $0.30/$1.20 instead of DeepSeek's $0.15/$0.60, glm-5-2 at Mistral's instead of Zhipu's, and a lab that isn't a preset (Meta's muse-spark, Sakana, Tencent hy4-preview) had no price at all. catalog.MakerPriced prices a model at a models.dev provider that lists it as its own: the entry's canonical_model_id names that provider as maker, or the provider id is the maker's with a region (alibaba-cn), never a plan's ("-plan") and never an entry at $0. A maker preset that is such an API is asked first, in preset order, then the other owners by id; the old PricedBy over the presets stays the fallback. makerListPrice uses it in ListPrice's maker step, MakerPrice and PricedName. No new setting: a model no maker lists still takes the user's price or a same-as model. Over every id in the real models.dev cache (2026-10-29, ~4086 ids) the only prices that changed are the deepseek-v4.1-flash-1017 family (0.30 -> 0.15), glm-5-2 (Mistral 1.40 -> Zhipu 1.19516), and newly priced Meta, Sakana, Thinking Machines and Tencent hy4-preview models. Run (mote-run, rebased on 1a8539432; catalog, provider, usage run again at this head): - TestMakerPriceIsTheMakersOwn (fixture: literal entries of the real models.dev cache) red on the old code, 10 errors (Mistral's resale price, Meta unpriced), green on the new. - gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows for internal/catalog, internal/provider, internal/usage. - go test -timeout 45m ./internal/catalog ./internal/provider ./internal/usage: ok. - go test -run 'Pric|Cost|Usage' ./internal/gateway ./internal/gui ./internal/cli: ok. Not tried: a real Command Code request and its Usage row in the GUI; the full gateway suite; Windows/Linux runs of the tests. --- docs/subsystems/providers-accounts.md | 1 + internal/catalog/catalog.go | 107 ++++++++++++++++++++++ internal/provider/maker_own_price_test.go | 105 +++++++++++++++++++++ internal/provider/models.go | 20 +++- 4 files changed, 230 insertions(+), 3 deletions(-) create mode 100644 internal/provider/maker_own_price_test.go diff --git a/docs/subsystems/providers-accounts.md b/docs/subsystems/providers-accounts.md index d3beec4c8..78bc1b3c5 100644 --- a/docs/subsystems/providers-accounts.md +++ b/docs/subsystems/providers-accounts.md @@ -53,6 +53,7 @@ keys and accounts per request is in [Gateway routing and fallback](gateway-routi | A remote magpie's service tiers | A remote magpie's `/v1/models` gives each model the `service_tiers` its own Codex is offered on it (`codexTiers` → `codexcat.ServiceTiers`, from the same `CodexCatalog` and `codexcat.Entries` as its `/v1/codex/models`: Fast on a ChatGPT account's GPT model, the tiers of Codex's own entry on a relay's, none on a model it offers none). The local keeps the ids (`catalog.Model.Tiers` → `Entry.Tiers`), `codexListed` hands them on for the remote's models, and `codexcat.Entries` offers them to the local Codex with Codex's own names (`namedTiers`). The gateway sends the tier Codex asks for to a remote magpie as it was asked (`Request.OwnTier`, as for a provider added by its address; dropped and not sent again if refused), and the remote serves it as its own Codex's turn (#1234). An agent's picker offers the bolt on a remote's model whose tiers hold `priority` (`provider.CanFast` reads them with `RemoteTiers`; Ultrafast too where they hold `ultrafast`, `UltraOn`), and a fast pick of one goes on with `service_tier` `priority` on the remote's Chat or Responses: an agent on Messages, whose fast is Claude's `speed`, has it turned into the tier the remote offers (`forwardTranslated`), so Claude Code's pick reaches the remote's vendor too (littlekk88 on Discord; `TestRemoteMagpieFastPick`, red without either half). A remote from before this sends no tiers, and its models are offered none, as before. The list gives every client the tiers, not only a magpie asking with `X-Magpie-Drawers`: Cindy shows its Fast switch on a model whose `service_tiers` hold `priority` (#1914, `TestModelsListTiersForEveryClient`). | [`codexcat.go`](../../internal/codexcat/codexcat.go), [`codex_models.go`](../../internal/provider/codex_models.go), [`codex_catalog.go`](../../internal/gateway/codex_catalog.go), [`gateway.go`](../../internal/gateway/gateway.go), [`live.go`](../../internal/catalog/live.go) | | A relay's Codex entries | A provider the user added by its address with a Responses URL may list its models in Codex's own shape (`slug`, `supported_reasoning_levels`, `shell_type`, `base_instructions`: `catalog.CodexEntry`), plainly or when asked with Codex's `client_version`, as sub2api does (ctopsc on Discord: GPT-6.1 Terra was handed models.dev's 922000 window where the relay said 272000). `fetchOne` keeps such a row whole (`catalog.Model.Codex`, with its window, max window and inputs read off it), and when the plain list has none it asks the same URL once more with `client_version` (`codexEntries`): only where the list is fetched (add, key change, Refresh), never per Codex poll. The answer only adds entries to models the plain list has; one that fails or can't be read keeps the last list's entries (failed read = unknown), one that answers plainly says there are none. `codexcat.listedEntry` hands Codex the relay's entry as given, `base_instructions` included, with magpie's slug, name, priority and " via magpie" description; the user's window, compaction, levels and image setting still win (levels keep the relay's descriptions). A saved list from before is enriched at its next Refresh. `TestCodexListedEntry`, `TestCodexListedEntryInPlainList`. | [`codex_entries.go`](../../internal/provider/codex_entries.go), [`live.go`](../../internal/catalog/live.go), [`codexcat.go`](../../internal/codexcat/codexcat.go) | | An endpoint's catalog | A key's provider with no catalog of its own (none named, none from a preset) is priced from the models.dev catalog whose `api` is one of its endpoints (`EndpointCatalog`, `catalog.AtEndpoint`; a trailing slash and case don't count, and an Anthropic base, kept as its root, is also matched with its `/v1`). Only when exactly one catalog is at that address, and it isn't a plan's (an id with `-plan`, or a `membershipCatalogs` one): a plan lists its membership's $0, and two catalogs at one address can't be told apart. A subscription's account never gets one. A provider at AMD's own endpoint is priced from `amd`, which lists Qwen3.8-27B at $0, a price, where its maker sells no such model and it had none (#2052); a relay's endpoint matches nothing and its model stays unpriced, never priced at a reseller's guess. `magpie model price` names the catalog, and says how to give a price when none is known. | [`models.go`](../../internal/provider/models.go), [`catalog.go`](../../internal/catalog/catalog.go) | +| The maker's own price | A model priced at its maker (`MakerPrice`, a provider's `ListPrice` after its own catalog, `PricedName`; through `makerListPrice`) is priced at a models.dev provider that lists it as its own (`catalog.MakerPriced`): one whose entry's `canonical_model_id` names it as the maker, or whose id is the maker's with a region (`alibaba-cn`), never a plan's (`-plan`) and never at $0. A maker preset that is such an API is asked first, in preset order, then the other owners by id; only then the maker presets as before (`PricedBy`). A maker preset that resells another lab's model no longer prices it: Mistral's `deepseek-v4-1-flash-1017` at $0.30/$1.20 gave way to DeepSeek's $0.15/$0.60, and a lab that isn't a preset (Meta's `muse-spark`) is priced at all. So a subscription's model (Command Code's, bestony on Discord) is estimated at what its maker charges (`TestMakerPriceIsTheMakersOwn`). A model no maker lists (Kimi K2.5, GLM-5.2 Fast) stays unpriced; the user gives it a price or a same-as model. | [`models.go`](../../internal/provider/models.go), [`catalog.go`](../../internal/catalog/catalog.go) | | A membership's $0 catalog | models.dev lists every model of Kimi Code's plans (`kimi-code-plan-global`, `kimi-code-plan-cn`) and of Xiaomi MiMo's Token Plans (`xiaomi-token-plan-cn`, `-sgp`, `-ams`) at $0: what the membership charges per token, not what the model costs. `membershipCatalogs` are never read for a price (`priceCatalogs`, `makerPriceCatalogs`), so a Xiaomi MiMo model is priced at `xiaomi`'s list price at every region, and each region of the preset names its own catalog, pay as you go `xiaomi` alone (#1873). A Kimi Code provider's model is priced at the Kimi API model it is (`kimiCodeAPI`, from Kimi Code's docs: k3 and k3-256k are kimi-k3, kimi-for-coding-highspeed is kimi-k2.7-code-highspeed), and kimi-for-coding (K2.8 Preview, not on the API) is unpriced rather than free (#1370). The alias is Kimi Code's alone (`kimiCodePlans`): a relay's own `k3` keeps its own price. A catalog other than these that lists a model at $0 still prices it at $0: models.dev has truly free models (nvidia, modelscope). The Requests list names the API model it was priced as (`PricedNameFor`). | [`models.go`](../../internal/provider/models.go) | | A plugin's own price | A model no catalog prices (models.dev has no vendor's own model: Devin's SWE-2 and SWE-1.7 Lightning, Cursor's auto, Qoder's efficient) is priced at what its plugin lists it at (`ListPrice` → `pluginListPrice`, `plugin.Model.Cost`, read by `pluginPrice`: an input or output above 0, OpenCode's 0 being none), else at $0 when the plugin says the plan serves it free (`pluginFree`, `plugin.Model.Free`: Devin's Free cost tier, Qoder's and WorkBuddy's x0). Both come after every catalog, so a price a catalog gives is kept over the plugin's. Devin's plugin (0.1.18) lists each paid model at the price Devin's GetCliModelConfigs gives it (input, cached input and output per 1M tokens); a moved Devin user's calls on Devin's own models had no cost on Usage before (太陽と向日葵 on Discord, `TestPluginFreeModelCostsNothing`). A plugin that gives no price and doesn't say free leaves the model unpriced. | [`models.go`](../../internal/provider/models.go), [`plugins.go`](../../internal/provider/plugins.go), [`providers.go`](../../internal/plugin/providers.go) | | Codex's free auto-review | OpenAI made Codex's Auto-review free for users signed in through a ChatGPT account (silverzhou on Discord), so a `codex-auto-review` call through the Codex subscription is priced at nothing (`ListPrice` → `codexReviewFree`, `provider.ChatGPTReviewFree`), not at GPT-5.6 Luna's price (`pricedNames`), and the Requests list names no model it is priced as (`PricedNameFor`). Not on a Free plan, where it spends the allowance (cybercaius), read from the plan Codex is signed in to now; a Codex signed out since counts as a paid plan, as the gateway's caps take it (`freeOnChatGPT`). The same model through an API key, the ChatGPT API subscription or a relay, and a review that followed the session to another model, keep their price; a price the user set wins. Every call is priced as it is read, so rows logged before are free too; the price views' cache keys on each account's plan (`usagePriceCacheKey`). Guarded by `TestAutoReviewFreeOnChatGPTSignIn` and `usage.TestAutoReviewFreeOnChatGPT`. | diff --git a/internal/catalog/catalog.go b/internal/catalog/catalog.go index 9f9883460..6404ecb5b 100644 --- a/internal/catalog/catalog.go +++ b/internal/catalog/catalog.go @@ -966,6 +966,113 @@ func canonicallyPriced(all map[string]mdProvider, at int, providers []string, b return Price{}, false } +// madeBy is who a model is, by models.dev's canonical_model_id: the labs +// that make it, and the providers that list it as their own (ownAPI). +type madeBy struct{ makers, owners []string } + +// makerOwners are, by bare id and by that id with its dots as dashes, the +// makers of the models models.dev's providers list and those of the +// providers that are a maker's own API, for the Reset count gen: an entry +// whose canonical_model_id names the provider listing it, or one it is an +// API of, as its maker (deepseek's deepseek-flash, deepseek/deepseek-v4.1-flash-1017; +// meta's muse-spark-1.2; stepfun-ai's step-5-preview), under the entry's +// id and its canonical's. An entry at $0 counts for neither: a maker's +// free tier (nvidia's) is not what the model costs. +var makerOwners struct { + sync.Mutex + gen int + by map[string]*madeBy +} + +// ownAPI is whether the models.dev provider pid is maker's own API: its +// id, or its id and a region or edition (stepfun-ai is StepFun's global +// API, alibaba-cn Alibaba's in China). A plan's catalog ("-plan") is not: +// it lists what a membership charges, not the model's price. +func ownAPI(pid, maker string) bool { + pid, maker = strings.ToLower(pid), strings.ToLower(maker) + return (pid == maker || strings.HasPrefix(pid, maker+"-")) && !strings.Contains(pid, "-plan") +} + +// madeByOf is who the bare id b is made and listed as their own by, nil +// when no provider lists it as its own. +func madeByOf(all map[string]mdProvider, at int, b string) *madeBy { + makerOwners.Lock() + defer makerOwners.Unlock() + if makerOwners.by == nil || makerOwners.gen != at { + by := map[string]*madeBy{} + add := func(k, maker, pid string) { + for _, k := range []string{k, dashed(k)} { + x := by[k] + if x == nil { + x = &madeBy{} + by[k] = x + } + if !slices.Contains(x.makers, maker) { + x.makers = append(x.makers, maker) + } + if !slices.Contains(x.owners, pid) { + x.owners = append(x.owners, pid) + } + } + } + for pid, p := range all { + for key, m := range p.Models { + maker, _, ok := strings.Cut(m.Canonical, "/") + if !ok || !ownAPI(pid, maker) || m.Cost == nil || m.Cost.Same(Price{}) { + continue + } + maker = strings.ToLower(maker) + add(bareID(key), maker, pid) + add(bareID(m.Canonical), maker, pid) + } + } + for _, x := range by { + slices.Sort(x.makers) + slices.Sort(x.owners) + } + makerOwners.gen, makerOwners.by = at, by + } + if x := makerOwners.by[b]; x != nil { + return x + } + return makerOwners.by[dashed(b)] +} + +// 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 MakerPriced(prefer []string, id string) (Price, bool) { + all, at := loadGen() + b := bareID(id) + if r, ok := unprofiled(b); ok { + b = r + } + x := madeByOf(all, at, b) + if x == nil { + return Price{}, false + } + var asked []string + for _, pid := range prefer { + if slices.ContainsFunc(x.makers, func(mk string) bool { return ownAPI(pid, mk) }) { + asked = append(asked, pid) + } + } + for _, pid := range append(asked, x.owners...) { + if pr, ok := PricedBy([]string{pid}, id); ok { + return pr, true + } + } + return Price{}, false +} + // dashed is an id with its dots as dashes: the spelling two ids are compared // in when one vendor writes a model's version 4.6 and another 4-6. func dashed(id string) string { return strings.ReplaceAll(id, ".", "-") } diff --git a/internal/provider/maker_own_price_test.go b/internal/provider/maker_own_price_test.go new file mode 100644 index 000000000..571a4dcef --- /dev/null +++ b/internal/provider/maker_own_price_test.go @@ -0,0 +1,105 @@ +package provider + +import ( + "os" + "path/filepath" + "testing" + + "github.com/yetone/magpie/internal/catalog" +) + +// makerOwnCatalog is models.dev's api.json as magpie had it on 2026-10-29, +// these entries byte for byte. DeepSeek sells V4.1 Flash 1017 as +// deepseek-flash at $0.15/$0.60 and Mistral resells it, by a dashed id, at +// $0.30/$1.20; Mistral resells Zhipu's GLM-5.2 too. Alibaba lists Qwen3.7 +// Max with no canonical and Alibaba (China) with one, at a price of its +// own. StepFun's global API and its China one each list Step 5 Preview, +// and its Step Plan lists it with no price. Meta, which no maker preset +// is, lists Muse Spark 1.2 and a contributor edition; NVIDIA lists its own +// Nemotron at $0. +const makerOwnCatalog = ` +{"deepseek":{"id":"deepseek","models":{ +"deepseek-flash":{"id":"deepseek-flash","name":"DeepSeek V4.1 Flash 1017","description":"October 17 update of DeepSeek V4.1 Flash with improved reasoning, coding, agentic tasks, and visual understanding","family":"deepseek-flash","attachment":true,"reasoning":true,"reasoning_options":[{"type":"toggle"},{"type":"effort","values":["low","high","max"]}],"tool_call":true,"interleaved":{"field":"reasoning_content"},"structured_output":true,"temperature":true,"knowledge":"2025-05","release_date":"2026-10-17","last_updated":"2026-10-17","modalities":{"input":["text","image"],"output":["text"]},"open_weights":true,"limit":{"context":1048576,"output":393216},"cost":{"input":0.15,"output":0.6,"reasoning":0.6,"cache_read":0.003},"canonical_model_id":"deepseek/deepseek-v4.1-flash-1017"}, +"deepseek-v4-pro":{"id":"deepseek-v4-pro","name":"DeepSeek V4 Pro","description":"DeepSeek V4 Pro snapshot with million-token context and support for thinking and non-thinking modes","family":"deepseek-thinking","attachment":false,"reasoning":true,"reasoning_options":[{"type":"toggle"},{"type":"effort","values":["low","high","max"]}],"tool_call":true,"interleaved":{"field":"reasoning_content"},"structured_output":true,"temperature":true,"release_date":"2026-08-13","last_updated":"2026-08-22","modalities":{"input":["text"],"output":["text"]},"open_weights":true,"limit":{"context":1048576,"output":393216},"cost":{"input":0.66,"output":1.98,"reasoning":1.98,"cache_read":0.022},"canonical_model_id":"deepseek/deepseek-v4-pro-0813"}}}, +"mistral":{"id":"mistral","models":{ +"deepseek-v4-1-flash-1017":{"id":"deepseek-v4-1-flash-1017","name":"DeepSeek V4.1 Flash 1017","description":"October 17 update of DeepSeek V4.1 Flash with improved reasoning, coding, agentic tasks, and visual understanding","family":"deepseek-flash","attachment":false,"reasoning":true,"reasoning_options":[{"type":"effort","values":["none","low","high","max"]}],"tool_call":true,"structured_output":true,"temperature":true,"knowledge":"2025-05","release_date":"2026-10-17","last_updated":"2026-10-17","modalities":{"input":["text"],"output":["text"]},"open_weights":true,"limit":{"context":1048576,"output":128000},"cost":{"input":0.3,"output":1.2,"cache_read":0.007},"canonical_model_id":"deepseek/deepseek-v4.1-flash-1017"}, +"glm-5-2":{"id":"glm-5-2","name":"GLM-5.2","description":"Open flagship GLM for long-horizon coding agents and million-token context work","family":"glm","attachment":false,"reasoning":true,"reasoning_options":[{"type":"effort","values":["none","high","max"]}],"tool_call":true,"structured_output":true,"temperature":true,"release_date":"2026-06-13","last_updated":"2026-06-13","modalities":{"input":["text"],"output":["text"]},"open_weights":true,"limit":{"context":1048576,"output":131072},"status":"deprecated","cost":{"input":1.4,"output":4.4,"cache_read":0.14},"canonical_model_id":"zhipuai/glm-5.2"}}}, +"zhipuai":{"id":"zhipuai","models":{ +"glm-5.2":{"id":"glm-5.2","name":"GLM-5.2","description":"Open flagship GLM for long-horizon coding agents and million-token context work","family":"glm","attachment":false,"reasoning":true,"reasoning_options":[{"type":"toggle"},{"type":"effort","values":["high","max"]}],"tool_call":true,"interleaved":{"field":"reasoning_content"},"structured_output":true,"temperature":true,"release_date":"2026-06-13","last_updated":"2026-06-13","modalities":{"input":["text"],"output":["text"]},"open_weights":true,"limit":{"context":1000000,"output":131072},"cost":{"input":1.19516,"output":4.18306,"cache_read":0.29879,"cache_write":0},"canonical_model_id":"zhipuai/glm-5.2"}}}, +"alibaba":{"id":"alibaba","models":{ +"qwen3.7-max":{"id":"qwen3.7-max","name":"Qwen3.7 Max","description":"Qwen frontier model tuned for agent frameworks, coding assistants, and long tasks","family":"qwen","attachment":false,"reasoning":true,"reasoning_options":[{"type":"toggle"},{"type":"budget_tokens"}],"tool_call":true,"structured_output":true,"temperature":true,"release_date":"2026-05-21","last_updated":"2026-05-21","modalities":{"input":["text"],"output":["text"]},"open_weights":false,"limit":{"context":1000000,"output":131072},"cost":{"input":2.5,"output":7.5,"cache_read":0.5,"cache_write":3.125}}}}, +"alibaba-cn":{"id":"alibaba-cn","models":{ +"qwen3.7-max":{"id":"qwen3.7-max","name":"Qwen3.7 Max","description":"Qwen frontier model tuned for agent frameworks, coding assistants, and long tasks","family":"qwen","attachment":false,"reasoning":true,"reasoning_options":[{"type":"toggle"},{"type":"budget_tokens","max":262144}],"tool_call":true,"structured_output":true,"temperature":true,"release_date":"2026-05-21","last_updated":"2026-05-21","modalities":{"input":["text"],"output":["text"]},"open_weights":false,"limit":{"context":1000000,"output":131072},"cost":{"input":1.65,"output":4.951,"cache_read":0.33,"cache_write":2.0625},"canonical_model_id":"alibaba/qwen3.7-max"}}}, +"stepfun-ai":{"id":"stepfun-ai","models":{ +"step-5-preview":{"id":"step-5-preview","name":"Step 5 Preview","description":"StepFun's next-generation flagship base model for coding and professional knowledge work, with native text, image, and video input and a 1M-token context window","attachment":true,"reasoning":true,"reasoning_options":[{"type":"effort","values":["low","medium","high"]}],"tool_call":true,"interleaved":{"field":"reasoning_content"},"structured_output":true,"temperature":true,"release_date":"2026-09-16","last_updated":"2026-09-20","modalities":{"input":["text","image","video"],"output":["text"]},"open_weights":true,"limit":{"context":1024000,"input":1024000,"output":65536},"cost":{"input":1,"output":2.7,"cache_read":0.1},"canonical_model_id":"stepfun/step-5-preview"}}}, +"stepfun":{"id":"stepfun","models":{ +"step-5-preview":{"id":"step-5-preview","name":"Step 5 Preview","description":"StepFun's next-generation flagship base model for coding and professional knowledge work, with native text, image, and video input and a 1M-token context window","attachment":true,"reasoning":true,"reasoning_options":[{"type":"effort","values":["low","medium","high"]}],"tool_call":true,"interleaved":{"field":"reasoning_content"},"structured_output":true,"temperature":true,"release_date":"2026-09-16","last_updated":"2026-09-20","modalities":{"input":["text","image","video"],"output":["text"]},"open_weights":true,"limit":{"context":1000000,"input":1000000,"output":65536},"cost":{"input":1.04613,"output":2.98895,"cache_read":0.10461},"canonical_model_id":"stepfun/step-5-preview"}}}, +"stepfun-ai-step-plan":{"id":"stepfun-ai-step-plan","models":{ +"step-5-preview":{"id":"step-5-preview","name":"Step 5 Preview","description":"StepFun's next-generation flagship base model for coding and professional knowledge work, with native text, image, and video input and a 1M-token context window","attachment":true,"reasoning":true,"reasoning_options":[{"type":"effort","values":["low","medium","high"]}],"tool_call":true,"interleaved":{"field":"reasoning_content"},"structured_output":true,"temperature":true,"release_date":"2026-09-16","last_updated":"2026-09-20","modalities":{"input":["text","image","video"],"output":["text"]},"open_weights":true,"limit":{"context":1000000,"input":1000000,"output":65536},"canonical_model_id":"stepfun/step-5-preview"}}}, +"meta":{"id":"meta","models":{ +"muse-spark-1.2":{"id":"muse-spark-1.2","name":"Muse Spark 1.2","description":"Muse Spark 1.2 is a coding-focused update to Muse Spark 1.1 with improvements in code generation, complex debugging, codebase understanding, and end-to-end developer workflows.","family":"muse","attachment":true,"reasoning":true,"reasoning_options":[{"type":"effort","values":["minimal","low","medium","high","xhigh"]}],"tool_call":true,"structured_output":true,"temperature":true,"release_date":"2026-08-05","last_updated":"2026-08-05","modalities":{"input":["text","image","video","pdf","audio"],"output":["text"]},"open_weights":false,"limit":{"context":1048576,"output":131072},"cost":{"input":1.25,"output":4.25,"cache_read":0.15},"canonical_model_id":"meta/muse-spark-1.2"}, +"muse-spark-1.2-contributor":{"id":"muse-spark-1.2-contributor","name":"Muse Spark 1.2 Contributor","description":"Muse Spark 1.2 is a coding-focused update to Muse Spark 1.1 with improvements in code generation, complex debugging, codebase understanding, and end-to-end developer workflows.","family":"muse","attachment":true,"reasoning":true,"reasoning_options":[{"type":"effort","values":["minimal","low","medium","high","xhigh"]}],"tool_call":true,"structured_output":true,"temperature":true,"release_date":"2026-08-05","last_updated":"2026-08-05","modalities":{"input":["text","image","video","pdf","audio"],"output":["text"]},"open_weights":false,"limit":{"context":1048576,"output":131072},"cost":{"input":0.1,"output":0.2,"cache_read":0.002},"canonical_model_id":"meta/muse-spark-1.2"}}}, +"nvidia":{"id":"nvidia","models":{ +"nvidia/nemotron-3-ultra-550b-a55b":{"id":"nvidia/nemotron-3-ultra-550b-a55b","name":"Nemotron 3 Ultra 550B A55B","description":"Largest Nemotron 3 model for maximum open-weight reasoning and agent accuracy","family":"nemotron","attachment":false,"reasoning":true,"reasoning_options":[{"type":"effort","values":["none","medium","high"]},{"type":"budget_tokens","min":-1,"max":32768}],"tool_call":true,"structured_output":true,"temperature":true,"knowledge":"2025-09","release_date":"2026-06-04","last_updated":"2026-06-04","modalities":{"input":["text"],"output":["text"]},"open_weights":true,"limit":{"context":1000000,"output":65536},"cost":{"input":0,"output":0},"canonical_model_id":"nvidia/nemotron-3-ultra-550b-a55b"}}}}` + +func useMakerOwnCatalog(t *testing.T) { + t.Helper() + home := t.TempDir() + t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) + t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) + t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache")) + os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755) + if err := os.WriteFile(catalog.CachePath(), []byte(makerOwnCatalog), 0o644); err != nil { + t.Fatal(err) + } + catalog.Reset() + t.Cleanup(catalog.Reset) +} + +// A subscription's call is estimated at the price the model's own maker +// lists it at, not at a reseller's that a maker preset lists before it +// (bestony on Discord: Command Code's calls costed at the official price). +// Command Code serves deepseek/deepseek-v4.1-flash-1017, which Mistral +// resells at twice DeepSeek's price, and Meta's muse-spark-1.2, which only +// Meta prices. +func TestMakerPriceIsTheMakersOwn(t *testing.T) { + useMakerOwnCatalog(t) + + cc := Provider{ID: "commandcode-plan", Name: "Command Code"} + for _, c := range []struct { + id string + input, output, cr float64 + }{ + // DeepSeek's deepseek-flash, by its canonical, not Mistral's resale + {"deepseek/deepseek-v4.1-flash-1017", 0.15, 0.6, 0.003}, + {"deepseek-v4-1-flash-1017", 0.15, 0.6, 0.003}, + // Zhipu's own, not Mistral's glm-5-2 + {"glm-5-2", 1.19516, 4.18306, 0.29879}, + {"zai-org/GLM-5.2", 1.19516, 4.18306, 0.29879}, + // the maker preset's own entry, as before, though only + // alibaba-cn names the model's maker + {"Qwen/Qwen3.7-Max", 2.5, 7.5, 0.5}, + // StepFun's global API, the preset asked first, not its plan's + {"stepfun/Step-5-Preview", 1, 2.7, 0.1}, + // a lab no maker preset is + {"meta/muse-spark-1.2", 1.25, 4.25, 0.15}, + {"meta/muse-spark-1.2-contributor", 0.1, 0.2, 0.002}, + // ids the maker lists as given keep their own prices + {"deepseek/deepseek-v4-pro", 0.66, 1.98, 0.022}, + } { + for name, price := range map[string]func(string) (catalog.Price, bool){"MakerPrice": MakerPrice, "ListPrice": cc.ListPrice} { + pr, ok := price(c.id) + if !ok || pr.Input != c.input || pr.Output != c.output || pr.CacheRead != c.cr { + t.Errorf("%s(%q) = %+v, %v; want $%v/$%v/$%v", name, c.id, pr, ok, c.input, c.output, c.cr) + } + } + } + // a maker's own $0 entry is no price for the model + if pr, ok := MakerPrice("nvidia/nemotron-3-ultra-550b-a55b"); ok { + t.Errorf("MakerPrice(nemotron) = %+v; want unpriced", pr) + } + if pr, ok := MakerPrice("thinkingmachines/inkling"); ok { + t.Errorf("MakerPrice(inkling) = %+v; want unpriced, no catalog lists it", pr) + } +} diff --git a/internal/provider/models.go b/internal/provider/models.go index e23386006..e8d8fd468 100644 --- a/internal/provider/models.go +++ b/internal/provider/models.go @@ -1875,7 +1875,7 @@ func (p Provider) ListPrice(model string) (catalog.Price, bool) { if pr, ok := catalog.PricedBy(priceCatalogs(cats), m); ok { return pr, true } - if pr, ok := catalog.PricedBy(makerPriceCatalogs(), m); ok { + if pr, ok := makerListPrice(m); ok { return pr, true } } @@ -2146,13 +2146,27 @@ var kimiCodeAPI = map[string]string{ // gone since. func MakerPrice(model string) (catalog.Price, bool) { for _, m := range pricedNames(model) { - if pr, ok := catalog.PricedBy(makerPriceCatalogs(), m); ok { + if pr, ok := makerListPrice(m); ok { return pr, true } } return catalog.Price{}, false } +// makerListPrice is a model id's list price at its maker: the price of +// the models.dev provider that lists it as its own model +// (catalog.MakerPriced), else the first maker preset's that lists it. The +// lab's own comes first, so a model a maker preset resells (Mistral's +// DeepSeek V4.1 Flash) is costed at what its lab charges, the official +// price a subscription's call is estimated at (bestony on Discord, on +// Command Code). +func makerListPrice(m string) (catalog.Price, bool) { + if pr, ok := catalog.MakerPriced(makerPriceCatalogs(), m); ok { + return pr, true + } + return catalog.PricedBy(makerPriceCatalogs(), m) +} + // SamePriceIn is the maker's list price of the model the user said // providerID's model is the same as (settings' ModelSameAs, #2344): for an // id of the provider's own that no list prices, as WorkBuddy's kimi-k3-1 @@ -2357,7 +2371,7 @@ func pricedNames(model string) []string { func PricedName(model string) string { n := pricedNames(model) for _, name := range n { - if _, ok := catalog.PricedBy(makerPriceCatalogs(), name); ok { + if _, ok := makerListPrice(name); ok { return name } }