provider: Cursor's grok-4.7 fast ids are priced at Cursor's fast rate, so a routing group of them counts its cost (TradingLife on Discord)

A group of Cursor's and Grok's Grok 4.7 fast recorded calls with no cost.
Cursor's ids grok-4.7-fast, grok-4.7-<effort>-fast (and at a window,
@500k) had no price anywhere: no models.dev catalog lists them, and
30431e04 left fast ids unpriced on purpose rather than make one up. So
every usage record on them (provider cursor, model grok-4.7-fast) was
unpriced, and the group, whose price needs every member's, had none.

Cursor publishes the price (https://cursor.com/docs/models, read
2026-10-12): Grok 4.7 (Fast) $4 input / $1 cache read / $12 output per
million, "Fast mode for long context (>256k) is billed at 3x standard
rates". Provider.ListPrice now gives a Cursor account (the built-in's or
the Cursor plugin's) that price for its fast Grok 4.7 ids, with a tier
above 256k at $6 / $1.5 / $18. Scoped to Cursor: elsewhere a "-fast" Grok
id is a model of its own (xAI's grok-4-fast is $0.2 / $0.5), and Grok
Build's grok-4.7-build-fast (Grok's own list) has no published price, so
it stays unpriced, as does a fast id of a model Cursor gives no fast
price for.

Run: go test -tags nogui ./internal/provider ./internal/sessions
./internal/usage (ok); new TestCursorGrokFastPrice fails with the lookup
switched off; gofmt -l clean. Not done: a group member sent fast through
Group.Fast (the plugin's grok-4.7@256k with service_tier priority) is
still recorded at the standard price, since a usage record doesn't say
it went fast; not checked against the reporter's own usage log.
This commit is contained in:
yetone
2026-10-12 22:08:57 +08:00
parent f96b7e842c
commit cbc96b5995
2 changed files with 115 additions and 2 deletions
+59
View File
@@ -6,6 +6,7 @@ import (
"testing"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/plugin"
)
// A Grok id named at an effort is priced as its model; a fast, mini or
@@ -56,3 +57,61 @@ func TestGrokEffortListPrice(t *testing.T) {
t.Errorf("PricedName(grok-4.7-low-fast) = %q", got)
}
}
// A Cursor account's fast Grok ids are priced at what Cursor bills fast
// mode (https://cursor.com/docs/models: Grok 4.7 (Fast) $4 / $1 cache
// read / $12, 3x standard past 256k), whether the built-in or the plugin
// serves them, so a routing group of grok-4.7-fast counts its cost
// (TradingLife on Discord). A "-fast" Grok id elsewhere is a model of its
// own, and stays as the catalogs price it.
func TestCursorGrokFastPrice(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)
os.WriteFile(catalog.CachePath(), []byte(`{
"xai":{"id":"xai","models":{
"grok-4.7":{"id":"grok-4.7","cost":{"input":2,"output":6,"cache_read":0.5}}}}}`), 0o644)
catalog.Reset()
t.Cleanup(catalog.Reset)
builtin := Provider{ID: "cursor", Name: "Cursor", Account: &Account{Agent: "cursor"}}
moved := Provider{ID: "cursor", Name: "Cursor", Account: &Account{plugin: &plugin.Provider{ID: "cursor"}}}
for _, p := range []Provider{builtin, moved} {
for _, id := range []string{"grok-4.7-fast", "grok-4.7-low-fast", "grok-4.7-high-fast", "grok-4.7-xhigh-fast",
"GROK-4.7-Fast", "grok-4.7-fast@500k", "grok-4.7-medium-fast@256k"} {
pr, ok := p.ListPrice(id)
if !ok || pr.Input != 4 || pr.Output != 12 || pr.CacheRead != 1 {
t.Errorf("%s ListPrice(%q) = %+v, %v; want Cursor's fast $4/$12/$1", p.PluginProvider(), id, pr, ok)
continue
}
// past 256k, 3x standard
if long := pr.At(300000); long.Input != 6 || long.Output != 18 || long.CacheRead != 1.5 {
t.Errorf("%s ListPrice(%q) past 256k = %+v; want $6/$18/$1.5", p.PluginProvider(), id, long)
}
if short := pr.At(200000); short.Input != 4 {
t.Errorf("%s ListPrice(%q) at 200k = %+v; want $4", p.PluginProvider(), id, short)
}
}
// not fast: grok's own price
if pr, ok := p.ListPrice("grok-4.7-high"); !ok || pr.Input != 2 {
t.Errorf("ListPrice(grok-4.7-high) = %+v, %v; want $2", pr, ok)
}
// a fast id of a model Cursor gives no fast price for
if pr, ok := p.ListPrice("grok-4.6-fast"); ok {
t.Errorf("ListPrice(grok-4.6-fast) = %+v; want unpriced", pr)
}
}
// elsewhere a fast id is not Cursor's fast mode
grok := Provider{ID: "grok", Name: "Grok", Account: &Account{plugin: &plugin.Provider{ID: "grok"}}}
for _, id := range []string{"grok-4.7-fast", "grok-4.7-build-fast"} {
if pr, ok := grok.ListPrice(id); ok {
t.Errorf("grok ListPrice(%q) = %+v; want unpriced", id, pr)
}
if pr, ok := MakerPrice(id); ok {
t.Errorf("MakerPrice(%q) = %+v; want unpriced", id, pr)
}
}
}
+56 -2
View File
@@ -1062,6 +1062,9 @@ func (p Provider) ListPrice(model string) (catalog.Price, bool) {
// served at no cost: not at the price of the model it is free of
return catalog.Price{}, true
}
if pr, ok := p.cursorFastPrice(model); ok {
return pr, true
}
names := pricedNames(model)
if p.kimiCodeMember() {
if id, ok := kimiCodeAPI[strings.ToLower(strings.TrimSpace(model))]; ok {
@@ -1079,6 +1082,56 @@ func (p Provider) ListPrice(model string) (catalog.Price, bool) {
return catalog.Price{}, false
}
// cursorFast is a Cursor id of a Grok model in its fast mode, at an effort
// or not, at a window or not: grok-4.7-fast, grok-4.7-low-fast,
// grok-4.7-xhigh-fast@500k. m[1] is the model it is fast of.
var cursorFast = regexp.MustCompile(`^((?:.*/)?grok-[0-9][^/@]*?)(?:-(?:minimal|low|medium|high|xhigh|extra-high))?-fast(?:@[0-9]+k)?$`)
// cursorFastPrices are what Cursor bills a Grok model in its fast mode
// per million tokens, as its own model list says
// (https://cursor.com/docs/models, read 2026-10-12): Grok 4.7 (Fast) $4
// input, $1 cache read, $12 output ("Fast mode is available at 2x
// pricing"), and "Fast mode for long context (>256k) is billed at 3x
// standard rates" ($6, $1.5, $18). No catalog lists these ids, so a call
// on Cursor's grok-4.7-fast, or on a routing group of it, had no cost at
// all (TradingLife on Discord).
var cursorFastPrices = map[string]catalog.Price{
"grok-4.7": {Input: 4, CacheRead: 1, Output: 12,
Tiers: []catalog.Tier{{Above: 256000, Input: 6, CacheRead: 1.5, Output: 18}}},
}
// servedByCursor is whether p is a Cursor account: the built-in's or the
// Cursor plugin's.
func (p Provider) servedByCursor() bool {
if p.Account == nil {
return false
}
return p.Account.Agent == "cursor" || p.PluginProvider() == "cursor"
}
// cursorFastPrice is Cursor's price for its fast id of a Grok model
// (cursorFastPrices), on a Cursor account only: elsewhere a "-fast" Grok
// id is a model of its own (xAI's grok-4-fast is $0.2 / $0.5), not this
// mode, and Grok Build's grok-4.7-build-fast has no published price.
func (p Provider) cursorFastPrice(model string) (catalog.Price, bool) {
if !p.servedByCursor() {
return catalog.Price{}, false
}
m := cursorFast.FindStringSubmatch(strings.ToLower(strings.TrimSpace(model)))
if m == nil {
return catalog.Price{}, false
}
base := m[1]
if i := strings.LastIndex(base, "/"); i >= 0 {
base = base[i+1:]
}
pr, ok := cursorFastPrices[base]
if ok {
pr.Tiers = slices.Clone(pr.Tiers)
}
return pr, ok
}
// membershipCatalogs are models.dev catalogs of a membership's own
// endpoints that list every model at $0: what the membership charges per
// token, not what the model costs (#1370, maicent: the Usage page counted
@@ -1259,8 +1312,9 @@ var grokWindow = regexp.MustCompile(`^((?:.*/)?grok-[0-9][^/@]*)@[0-9]+k$`)
// 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.
// Other names without catalog prices stay unpriced (grok-4.7-build, grok-4.7-mini,
// grok-4.7-fast).
// Other names without catalog prices stay unpriced here (grok-4.7-build,
// grok-4.7-mini, grok-4.7-fast); a Cursor account's fast ids are priced at
// Cursor's own fast rate (Provider.cursorFastPrice).
func pricedNames(model string) []string {
out := []string{model}
if model == "codex-auto-review" {