From ba0bd421eaee34fb24486bc83454124c97a6d86d Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 15 Oct 2026 13:52:10 +0800 Subject: [PATCH] provider, sessions: Grok's grok-4.7-build-fast is priced at twice grok-4.7, so a group of Cursor's and Grok's Grok 4.7 fast counts Grok's calls too (TradingLife on Discord) cbc96b599 priced Cursor's grok-4.7-fast ids, but the group's other half, Grok's own fast variant, stayed unpriced: Grok Build lists it as grok-4.7-build-fast, which no models.dev catalog has, and TestCursorGrokFastPrice asserted it unpriced. Every call the group sent to Grok (built-in or moved to the Grok plugin, both provider "grok") was recorded with no cost, so on v0.1.1247 the group still showed none for those calls. xAI says what it costs (https://x.ai/news/grok-4-7, read 2026-10-15): "We also serve a fast variant with twice the output speed at twice the price". Provider.ListPrice now prices a Grok account's (Account.Agent "grok" or the grok plugin's) grok--build-fast, at a window too (@500k), at twice its model's list price, every tier with it ($4 / $1 / $12, $8 / $2 / $24 past 200k for grok-4.7). A Grok CLI session's bare grok-4.7-build-fast on the Sessions page is priced the same way. Other providers and a build-fast of a model with no price stay unpriced. Not changed: a member sent fast through Group.Fast (Cursor plugin grok-4.7 with service_tier priority, or Codex priority) is still priced at the standard rate; no record's price reads TierSent yet. Run: go test -tags nogui ./internal/provider ./internal/sessions ./internal/usage (ok); go vet -tags nogui for darwin, linux, windows on provider and sessions; gofmt -l clean. Broken by hand: with the grokFastPrice lookup off, TestGrokBuildFastPrice fails for the built-in and the plugin; with the sessions branch off, TestPriceOfGrokEffort fails. Not checked against the reporter's own usage log or a live Grok account. --- internal/provider/grok_price_test.go | 58 +++++++++++++++++++++++++++- internal/provider/models.go | 50 +++++++++++++++++++++++- internal/sessions/price_test.go | 12 ++++-- internal/sessions/sessions.go | 8 ++++ 4 files changed, 122 insertions(+), 6 deletions(-) diff --git a/internal/provider/grok_price_test.go b/internal/provider/grok_price_test.go index d1bfac049..7e6dd6be8 100644 --- a/internal/provider/grok_price_test.go +++ b/internal/provider/grok_price_test.go @@ -104,12 +104,15 @@ func TestCursorGrokFastPrice(t *testing.T) { t.Errorf("ListPrice(grok-4.6-fast) = %+v; want unpriced", pr) } } - // elsewhere a fast id is not Cursor's fast mode + // elsewhere a fast id is not Cursor's fast mode (Grok's own + // grok-4.7-build-fast is priced as Grok's, TestGrokBuildFastPrice) 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"} { + for _, id := range []string{"grok-4.7-fast", "grok-4.7-low-fast"} { if pr, ok := grok.ListPrice(id); ok { t.Errorf("grok ListPrice(%q) = %+v; want unpriced", id, pr) } + } + for _, id := range []string{"grok-4.7-fast", "grok-4.7-build-fast"} { if pr, ok := MakerPrice(id); ok { t.Errorf("MakerPrice(%q) = %+v; want unpriced", id, pr) } @@ -202,3 +205,54 @@ func TestFactoryFastPrice(t *testing.T) { t.Errorf("claude ListPrice(claude-opus-5-5-fast) = %+v; want unpriced", pr) } } + +// A Grok account's fast variant, grok-4.7-build-fast, is priced at twice +// grok-4.7, every tier with it, as xAI sells it (https://x.ai/news/grok-4-7: +// "a fast variant with twice the output speed at twice the price"), +// whether the built-in or the Grok plugin serves it: a routing group of +// Cursor's and Grok's Grok 4.7 fast counted no cost for Grok's calls +// (TradingLife on Discord). Elsewhere the id stays unpriced. +func TestGrokBuildFastPrice(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) + // as models.dev's xai lists it (2026-10-15) + 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, + "tiers":[{"input":4,"output":12,"cache_read":1,"tier":{"type":"context","size":200000}}]}}}}}`), 0o644) + catalog.Reset() + t.Cleanup(catalog.Reset) + + builtin := Provider{ID: "grok", Name: "Grok (SuperGrok)", Account: &Account{Agent: "grok"}} + moved := Provider{ID: "grok", Name: "Grok (SuperGrok)", Account: &Account{plugin: &plugin.Provider{ID: "grok"}}} + for _, p := range []Provider{builtin, moved} { + for _, id := range []string{"grok-4.7-build-fast", "GROK-4.7-Build-Fast", "grok-4.7-build-fast@500k"} { + pr, ok := p.ListPrice(id) + if !ok || pr.Input != 4 || pr.Output != 12 || pr.CacheRead != 1 { + t.Errorf("%q ListPrice(%q) = %+v, %v; want twice grok-4.7's, $4/$12/$1", p.PluginProvider(), id, pr, ok) + continue + } + if long := pr.At(300000); long.Input != 8 || long.Output != 24 || long.CacheRead != 2 { + t.Errorf("%q ListPrice(%q) past 200k = %+v; want $8/$24/$2", p.PluginProvider(), id, long) + } + } + // the model itself keeps its own price + if pr, ok := p.ListPrice("grok-4.7"); !ok || pr.Input != 2 { + t.Errorf("ListPrice(grok-4.7) = %+v, %v; want $2", pr, ok) + } + // a fast variant of a model no catalog prices stays unpriced + if pr, ok := p.ListPrice("grok-4.6-build-fast"); ok { + t.Errorf("ListPrice(grok-4.6-build-fast) = %+v; want unpriced", pr) + } + } + // not a Grok account: not Grok Build's fast variant + for _, p := range []Provider{{ID: "grok"}, {ID: "cursor", Account: &Account{Agent: "cursor"}}} { + if pr, ok := p.ListPrice("grok-4.7-build-fast"); ok { + t.Errorf("%s ListPrice(grok-4.7-build-fast) = %+v; want unpriced", p.ID, pr) + } + } +} diff --git a/internal/provider/models.go b/internal/provider/models.go index 30620d332..f3a323bcb 100644 --- a/internal/provider/models.go +++ b/internal/provider/models.go @@ -1654,6 +1654,9 @@ func (p Provider) ListPrice(model string) (catalog.Price, bool) { if pr, ok := p.factoryFastPrice(model); ok { return pr, true } + if pr, ok := p.grokFastPrice(model); ok { + return pr, true + } names := pricedNames(model) if p.kimiCodeMember() { if id, ok := kimiCodeAPI[strings.ToLower(strings.TrimSpace(model))]; ok { @@ -1759,6 +1762,50 @@ func (p Provider) cursorFastPrice(model string) (catalog.Price, bool) { return pr, ok } +// grokBuildFast is Grok Build's id of a Grok model's fast variant, as its +// own model list offers it (grok-4.7-build-fast, and at a window of its +// own, grok-4.7-build-fast@500k). m[1] is the model it is fast of. +var grokBuildFast = regexp.MustCompile(`^(grok-[0-9][0-9.]*)-build-fast(?:@[0-9]+k?)?$`) + +// grokFastPrice is a Grok account's (the built-in's or the Grok plugin's) +// price for its fast variant of a Grok model: twice the model's own, every +// tier with it, as xAI says it sells it ("We also serve a fast variant +// with twice the output speed at twice the price", +// https://x.ai/news/grok-4-7, read 2026-10-15). No catalog lists +// grok-4.7-build-fast, so every call a routing group of Cursor's and +// Grok's Grok 4.7 fast sent to Grok was unpriced, and the group's cost +// left out half its calls (TradingLife on Discord, after cbc96b599 priced +// Cursor's half). Only on a Grok account: no other vendor serves the id. +func (p Provider) grokFastPrice(model string) (catalog.Price, bool) { + if p.Account == nil || p.Account.Agent != "grok" && p.PluginProvider() != "grok" { + return catalog.Price{}, false + } + base, ok := GrokBuildFast(model) + if !ok { + return catalog.Price{}, false + } + pr, ok := p.ListPrice(base) + if !ok { + return catalog.Price{}, false + } + return pr.Times(GrokFastTimes), true +} + +// GrokFastTimes is how many times its model's price xAI sells a Grok +// model's fast variant at (grokFastPrice). +const GrokFastTimes = 2 + +// GrokBuildFast is the Grok model id is Grok Build's fast variant of +// (grok-4.7-build-fast is grok-4.7's), and whether it is one: for a Grok +// CLI session, which names it bare, priced as grokFastPrice prices it. +func GrokBuildFast(id string) (string, bool) { + m := grokBuildFast.FindStringSubmatch(strings.ToLower(strings.TrimSpace(id))) + if m == nil { + return "", false + } + return m[1], true +} + // factoryFastTimes is how many times its base model's list price each // Fast Mode model Factory offers is billed at by the model's maker // (droid's ids, the factory plugin's MODELS): Anthropic's fast mode is 2x @@ -1992,7 +2039,8 @@ var grokWindow = regexp.MustCompile(`^((?:.*/)?grok-[0-9][^/@]*)@[0-9]+k?$`) // This is a list-price estimate, not evidence of a response's served model. // 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). +// Cursor's own fast rate (Provider.cursorFastPrice), and a Grok account's +// grok-4.7-build-fast at twice grok-4.7's (Provider.grokFastPrice). func pricedNames(model string) []string { out := []string{model} if model == "codex-auto-review" { diff --git a/internal/sessions/price_test.go b/internal/sessions/price_test.go index 7c050f543..2a438da64 100644 --- a/internal/sessions/price_test.go +++ b/internal/sessions/price_test.go @@ -11,8 +11,9 @@ import ( ) // A session's Grok model named at an effort is priced as its model; one no -// catalog lists (Grok Build's grok-4.7-build, grok-4.7-mini, a fast one) -// stays unpriced (#224). +// catalog lists (Grok Build's grok-4.7-build, grok-4.7-mini, Cursor's fast +// one) stays unpriced (#224). Grok Build's own fast variant, +// grok-4.7-build-fast, is twice grok-4.7, as xAI sells it. func TestPriceOfGrokEffort(t *testing.T) { home := t.TempDir() t.Setenv("HOME", home) @@ -29,7 +30,12 @@ func TestPriceOfGrokEffort(t *testing.T) { t.Errorf("priceOf(%q) = %+v, %v; want $2/$6/$0.5", m, pr, ok) } } - for _, m := range []string{"grok-4.7-build", "grok-4.7-mini", "grok-4.7-low-fast", "grok-4.7-build-fast"} { + for _, m := range []string{"grok-4.7-build-fast", "Grok-4.7-Build-Fast", "grok-4.7-build-fast@500k"} { + if pr, ok := priceOf(settings.Load(), m); !ok || pr.Input != 4 || pr.Output != 12 || pr.CacheRead != 1 { + t.Errorf("priceOf(%q) = %+v, %v; want twice grok-4.7's, $4/$12/$1", m, pr, ok) + } + } + for _, m := range []string{"grok-4.7-build", "grok-4.7-mini", "grok-4.7-low-fast", "grok-4.6-build-fast"} { if pr, ok := priceOf(settings.Load(), m); ok { t.Errorf("priceOf(%q) = %+v; want unpriced", m, pr) } diff --git a/internal/sessions/sessions.go b/internal/sessions/sessions.go index 569a4f5ce..122fe5892 100644 --- a/internal/sessions/sessions.go +++ b/internal/sessions/sessions.go @@ -1418,6 +1418,14 @@ func priceOf(s settings.Settings, model string) (catalog.Price, bool) { return pr, true } } + // Grok Build's fast variant (grok-4.7-build-fast), which only the Grok + // CLI names, at twice its model's price, as a Grok account's call on it + // is (TradingLife on Discord) + if base, ok := provider.GrokBuildFast(bare); ok { + if pr, ok := catalog.PricedBy(makers(base), base); ok { + return pr.Times(provider.GrokFastTimes), true + } + } return catalog.Price{}, false }