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 }