From e8001f73a38c4922f97d512bcd806e80d804fdce Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 13 Nov 2026 21:44:17 +0800 Subject: [PATCH] providers: a model named at an effort is priced as its model, for every provider (stockAAAAA on X) Antigravity's gemini-4-argon-high, gemini-4-carbon-high and claude-opus-5-5-high showed "price unknown". pricedNamesTo, the list of ids ListPrice, MakerPrice and PricedName (Usage, the Requests ledger, Sessions) look a model up by, read an effort off an id only when it named grok- (#224): for any other id it returned before the effort pattern, so the base model (gemini-4-argon, $2/$10 on models.dev) was never tried. The reporter's claim is right. effortBase now reads the effort off any id, with no regexp (every model of every provider's list is priced on each Providers poll): -minimal, -low, -medium, -high, -xhigh, and Antigravity's -extra-high and -extra-low. The id's own name is still tried first, so a catalog id that names an effort keeps its own price (o3-mini-high, nano-gpt's gemini-3.1-pro-preview-high). Not read: -max and -none (gpt-5.1-codex-max, qwen3.8-max are models at prices of their own), a fast id (grok-4.7-low-fast), and a base with no digit in its last part (mistral-medium, vision-medium, claw-high), so a size word is not taken for an effort. Checked against every model id in the bundled models.dev catalog: the ids that end in an effort word with a digit in the base are the same model at an effort (o3-mini-high/low, gemini-3.1-pro-preview-high/low, gpt-5.3-codex-xhigh). The Grok window pattern still runs only on ids naming grok-. Tests: TestEffortIDPricedAsItsModel (new) prices the reporter's three ids, each other effort word, upper case and a google/ prefix through MakerPrice, an Antigravity ListPrice and another provider's ListPrice, keeps o3-mini-high's own price, and leaves gpt-5.1-codex-max, -none, vision-medium, mistral/vision-high, -high-fast and -ultra unpriced. TestGrokEffortListPrice: gpt-6-astra-high, unpriced before because only Grok's ids were read, is now priced as gpt-6-astra, and cursor-grok-4.7-high as grok-4.7 (the catalog already prices cursor-grok-4.7 as grok-4.7, renamed). Run (on mote, mote-run): - old models.go with the new tests: TestEffortIDPricedAsItsModel FAIL, e.g. MakerPrice("gemini-4-carbon-high") = {Input:0 ...}, false; want gemini-4-carbon's {Input:2 Output:10 CacheRead:0.1}; same for claude-opus-5-5-high and the Antigravity ListPrice. - new code: go test -tags nogui ./internal/provider/ ./internal/sessions/ ./internal/catalog/ ok. - with this Mac's real models.dev cache (~/.cache/magpie/models.json copied into a scratch test, not committed): Antigravity's ListPrice/EffectivePrice of gemini-4-argon-high and gemini-4-carbon-high $2/$10/$0.1, claude-opus-5-5-high $4/$20/$0.2/$5; gpt-5.1-codex-max and mistral-medium unpriced; PricedName(o3-mini-high) o3-mini. - gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./..., go build, GOOS=linux go build -tags nogui, GOOS=windows go build: ok. - the full go test -tags nogui ./... was not run before this push (shipped at once); it is run on mote after it. Not tried: the reporter's own usage log, or the GUI's Usage page. --- internal/provider/effort_price_test.go | 85 ++++++++++++++++++++++++++ internal/provider/grok_price_test.go | 12 +++- internal/provider/models.go | 63 +++++++++++++------ 3 files changed, 139 insertions(+), 21 deletions(-) create mode 100644 internal/provider/effort_price_test.go diff --git a/internal/provider/effort_price_test.go b/internal/provider/effort_price_test.go new file mode 100644 index 000000000..3dae11082 --- /dev/null +++ b/internal/provider/effort_price_test.go @@ -0,0 +1,85 @@ +package provider + +import ( + "os" + "path/filepath" + "testing" + + "github.com/yetone/magpie/internal/catalog" +) + +// An id named at a reasoning effort is priced as its model, whichever +// provider serves it: Antigravity's gemini-4-argon-high, +// gemini-4-carbon-high and claude-opus-5-5-high showed "price unknown" +// (stockAAAAA on X), as only Grok's ids were read this way. An id a +// catalog prices by its own name keeps that price, and a suffix that is +// part of a model's own name (-max, mistral-medium) is not taken for an +// effort of another model. +func TestEffortIDPricedAsItsModel(t *testing.T) { + 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) + // models.dev's prices on 2026-11-13 + os.WriteFile(catalog.CachePath(), []byte(`{ + "google":{"id":"google","models":{ + "gemini-4-argon":{"id":"gemini-4-argon","cost":{"input":2,"output":10,"cache_read":0.1}}, + "gemini-4-carbon":{"id":"gemini-4-carbon","cost":{"input":2,"output":10,"cache_read":0.1}}}}, + "anthropic":{"id":"anthropic","models":{ + "claude-opus-5-5":{"id":"claude-opus-5-5","cost":{"input":4,"output":20,"cache_read":0.2,"cache_write":5}}}}, + "openai":{"id":"openai","models":{ + "gpt-5.1-codex":{"id":"gpt-5.1-codex","cost":{"input":1.25,"output":10}}, + "o3-mini":{"id":"o3-mini","cost":{"input":1.1,"output":4.4}}, + "o3-mini-high":{"id":"o3-mini-high","cost":{"input":3,"output":12}}}}, + "mistral":{"id":"mistral","models":{ + "vision":{"id":"vision","cost":{"input":9,"output":9}}}}}`), 0o644) + catalog.Reset() + t.Cleanup(catalog.Reset) + + ag := Provider{ID: "antigravity", Name: "Antigravity"} + other := Provider{ID: "some-relay", Name: "Relay"} + want := map[string]catalog.Price{ + "gemini-4-argon": {Input: 2, Output: 10, CacheRead: 0.1}, + "gemini-4-carbon": {Input: 2, Output: 10, CacheRead: 0.1}, + "claude-opus-5-5": {Input: 4, Output: 20, CacheRead: 0.2, CacheWrite: 5}, + } + for id, base := range map[string]string{ + // the reporter's three + "gemini-4-argon-high": "gemini-4-argon", + "gemini-4-carbon-high": "gemini-4-carbon", + "claude-opus-5-5-high": "claude-opus-5-5", + // the other words an effort is spelled in + "gemini-4-argon-low": "gemini-4-argon", "gemini-4-argon-medium": "gemini-4-argon", + "gemini-4-argon-minimal": "gemini-4-argon", "claude-opus-5-5-xhigh": "claude-opus-5-5", + "gemini-4-carbon-extra-high": "gemini-4-carbon", "gemini-4-carbon-extra-low": "gemini-4-carbon", + "Claude-Opus-5-5-High": "claude-opus-5-5", "google/gemini-4-argon-high": "gemini-4-argon", + } { + w := want[base] + for name, price := range map[string]func(string) (catalog.Price, bool){ + "MakerPrice": MakerPrice, "antigravity ListPrice": ag.ListPrice, "relay ListPrice": other.ListPrice} { + pr, ok := price(id) + if !ok || pr.Input != w.Input || pr.Output != w.Output || pr.CacheRead != w.CacheRead || pr.CacheWrite != w.CacheWrite { + t.Errorf("%s(%q) = %+v, %v; want %s's %+v", name, id, pr, ok, base, w) + } + } + } + if got := PricedName("gemini-4-argon-high"); got != "gemini-4-argon" { + t.Errorf("PricedName(gemini-4-argon-high) = %q", got) + } + // an id priced by its own name keeps its own price + if pr, ok := MakerPrice("o3-mini-high"); !ok || pr.Input != 3 || pr.Output != 12 { + t.Errorf("MakerPrice(o3-mini-high) = %+v, %v; want its own $3/$12", pr, ok) + } + // -max is a model of its own, and a word size names no effort + for _, id := range []string{"gpt-5.1-codex-max", "gpt-5.1-codex-none", "vision-medium", + "mistral/vision-high", "gemini-4-argon-high-fast", "gemini-4-argon-ultra"} { + if pr, ok := MakerPrice(id); ok { + t.Errorf("MakerPrice(%q) = %+v; want unpriced", id, pr) + } + if pr, ok := other.ListPrice(id); ok { + t.Errorf("ListPrice(%q) = %+v; want unpriced", id, pr) + } + } +} diff --git a/internal/provider/grok_price_test.go b/internal/provider/grok_price_test.go index 553b8aa4a..e956eff06 100644 --- a/internal/provider/grok_price_test.go +++ b/internal/provider/grok_price_test.go @@ -31,7 +31,9 @@ func TestGrokEffortListPrice(t *testing.T) { for _, id := range []string{"grok-4.7", "grok-4.7-low", "grok-4.7-medium", "grok-4.7-high", "grok-4.7-xhigh", "GROK-4.7-High", "x-ai/grok-4.7-xhigh", "grok-4.6-minimal", // a model at a window of its own (#1608) - "grok-4.7@500k", "grok-4.6@500k"} { + "grok-4.7@500k", "grok-4.6@500k", + // a relay's name of grok-4.7 (catalog's renamed), at an effort + "cursor-grok-4.7-high"} { for name, price := range map[string]func(string) (catalog.Price, bool){"MakerPrice": MakerPrice, "ListPrice": grok.ListPrice} { pr, ok := price(id) if !ok || pr.Input != 2 || pr.Output != 6 || pr.CacheRead != 0.5 { @@ -41,8 +43,7 @@ func TestGrokEffortListPrice(t *testing.T) { } for _, id := range []string{"grok-4.7-fast", "grok-4.7-low-fast", "grok-4.7-xhigh-fast", "grok-4.7-build", "grok-4.7-build-fast", "grok-4.7-mini", "grok-4.7-mini-high", "grok-4.7-max", - // only Grok's ids are read this way - "gpt-6-astra-high", "cursor-grok-4.7-high", "grok-4.7-build@500k"} { + "grok-4.7-build@500k"} { if pr, ok := grok.ListPrice(id); ok { t.Errorf("ListPrice(%q) = %+v; want unpriced", id, pr) } @@ -50,6 +51,11 @@ func TestGrokEffortListPrice(t *testing.T) { t.Errorf("MakerPrice(%q) = %+v; want unpriced", id, pr) } } + // an effort is read off any id, not only Grok's + // (TestEffortIDPricedAsItsModel) + if pr, ok := grok.ListPrice("gpt-6-astra-high"); !ok || pr.Input != 10 || pr.Output != 50 { + t.Errorf("ListPrice(gpt-6-astra-high) = %+v, %v; want gpt-6-astra's $10/$50", pr, ok) + } // a window is read off any id, not only Grok's: the Cursor plugin's // sized ids (TestCursorWindowIDsPricedAsTheirModel) if pr, ok := grok.ListPrice("gpt-6-astra@500k"); !ok || pr.Input != 10 || pr.Output != 50 { diff --git a/internal/provider/models.go b/internal/provider/models.go index b24328191..02b1c7b98 100644 --- a/internal/provider/models.go +++ b/internal/provider/models.go @@ -3159,12 +3159,39 @@ func byIDOrWasIn(all []Provider, id string) (Provider, bool) { return Provider{}, false } -// grokEffort is a reasoning effort a Grok id is named at ("grok-4.7-low", -// "grok-4.7-xhigh"): the levels Grok's own model list gives grok-4.7, the -// words Cursor spells its ids in. A fast one ("grok-4.7-low-fast") doesn't -// match: fast is a model of its own (cursor_models.go), and no catalog -// prices it. -var grokEffort = lazyre.New(`^((?:.*/)?grok-[0-9][^/]*?)-(?:minimal|low|medium|high|xhigh|extra-high)$`) +// effortBase is the model an id is named at a reasoning effort of +// ("grok-4.7-low", Antigravity's gemini-4-argon-high and +// claude-opus-5-5-high, Cursor's gpt-5.3-codex-xhigh): the id without +// its effort, and whether it named one. Only the words an effort is +// spelled in: -max and -none are not read, as -max names models of their +// own at prices of their own (gpt-5.1-codex-max, qwen3.8-max). The model +// left must name a version (a digit in its last part), so a name whose +// size is a word (mistral-medium, vision-medium) is not taken for an +// effort of another. A fast one ("grok-4.7-low-fast") doesn't match: fast +// is a model of its own (cursor_models.go). No regexp, for the same +// reason as below: every model of every provider's list is priced on +// each Providers poll. +func effortBase(l string) (string, bool) { + i := strings.LastIndexByte(l, '-') + if i <= 0 { + return "", false + } + base, effort := l[:i], l[i+1:] + if (effort == "high" || effort == "low") && strings.HasSuffix(base, "-extra") { + base = base[:len(base)-len("-extra")] // Antigravity's extra-high, extra-low + } else { + switch effort { + case "minimal", "low", "medium", "high", "xhigh": + default: + return "", false + } + } + last := base[strings.LastIndexByte(base, '/')+1:] + if !strings.ContainsAny(last, "0123456789") { + return "", false + } + return base, true +} // grokWindow is a Grok id offered at a context window of its own // ("grok-4.7@500k", the grok plugin's windowsOf): the same model, asked for @@ -3184,9 +3211,10 @@ var modelWindow = lazyre.New(`^([^@]+)@[0-9]+[km]$`) // pricedNames are the ids a model is priced by, in order: its own, then, // for an id at a window (claude-opus-5-5@300k, grok-4.7@500k), the model // it is that window of (modelWindow), so a Cursor account's sized ids are -// priced as their model and not left without a cost (RyuJeXu on X); for a -// Grok id named at an effort, the model it is that effort of — the same -// model, at the same price (#224). Codex Auto Review uses GPT-5.6 Luna +// priced as their model and not left without a cost (RyuJeXu on X); for an +// id named at an effort, the model it is that effort of (effortBase) — the +// same model, at the same price (#224 for Grok's; Antigravity's +// gemini-4-argon-high, stockAAAAA on X). Codex Auto Review uses GPT-5.6 Luna // according to OpenAI's rate card (2026-09-30): // https://help.openai.com/en/articles/11481834-chatgpt-rate-card-business-enterpriseedu-credit-based-pricing // This is a list-price estimate, not evidence of a response's served model. @@ -3210,16 +3238,15 @@ func pricedNamesTo(dst []string, model string) []string { out = append(out, m[1]) } } - // both patterns name grok-, for the same reason - if !strings.Contains(l, "grok-") { - return out + // a Grok window the id names without a k (grok-4.7@131072): the + // pattern names grok-, for the same reason + if strings.Contains(l, "grok-") { + if m := grokWindow.FindStringSubmatch(l); m != nil && !slices.Contains(out, m[1]) { + out = append(out, m[1]) + } } - // a Grok window the id names without a k (grok-4.7@131072) - if m := grokWindow.FindStringSubmatch(l); m != nil && !slices.Contains(out, m[1]) { - out = append(out, m[1]) - } - if m := grokEffort.FindStringSubmatch(l); m != nil { - out = append(out, m[1]) + if base, ok := effortBase(l); ok { + out = append(out, base) } return out }