usage: a Grok id named at a reasoning effort is priced as its model (#224 Aimer779: calls made with Grok Build show no cost on the Usage page) — the Usage page, the Requests ledger and the Sessions page price a model by its models.dev id, and xAI lists grok-4.7 and grok-4.6 ($2 / $6 / $0.5 cache read per million in the cached catalog) but not the ids Grok's models are spelled at an effort: grok-4.7-low, -medium, -high, -xhigh (Cursor's ids, and grok-4.7 at the levels Grok's own model list gives it). Such an id is the same model at another setting, so when its own id has no price it is now looked up as the model it is an effort of (provider.pricedNames: grok-<version>[-…]-minimal|low|medium|high|xhigh|extra-high, with or without a path, any case), in Provider.ListPrice and MakerPrice (the gateway's ledger and summary) and in the Sessions page's priceOf (through provider.PricedName). An id priced by its own name keeps that price; what is recorded is unchanged. Only Grok's ids are read this way, and -max is not stripped. Left unpriced, as no catalog in use lists them and no price is made up: fast ids (grok-4.7-fast, grok-4.7-low-fast, … which cursor_models.go treats as models of their own), grok-4.7-build and grok-4.7-build-fast (Grok Build's own models, from its model list and sessions) and grok-4.7-mini; they keep the + as before. Tested with a new TestGrokEffortListPrice (MakerPrice and the Grok account's ListPrice price grok-4.7 at each effort, in upper case and with x-ai/, and grok-4.6-minimal, at grok's price; the fast, build, mini and -max ids, gpt-6-astra-high and cursor-grok-4.7-high stay unpriced) and TestPriceOfGrokEffort in internal/sessions (the same for a session's models, grok-4.7-build, grok-4.7-mini and the fast ones unpriced); TestSubscriptionListPrice unchanged. go build -tags nogui (and GOOS=linux, GOOS=windows), go test -tags nogui ./... pass (TestUserPath, TestClaudeSignedOut, TestClaudeAccountNamedAsItsLogin, TestClaudeIdentityServedWhileAsked and TestCodexVersion hit their 5s waits in the full run and pass alone). Not tried against the reporter's usage log or in the GUI.
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
)
|
||||
|
||||
// A Grok id named at an effort is priced as its model; a fast, mini or
|
||||
// build one no catalog lists stays unpriced (#224).
|
||||
func TestGrokEffortListPrice(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", 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}},
|
||||
"grok-4.6":{"id":"grok-4.6","cost":{"input":2,"output":6,"cache_read":0.5}}}},
|
||||
"openai":{"id":"openai","models":{
|
||||
"gpt-6-astra":{"id":"gpt-6-astra","cost":{"input":10,"output":50}}}}}`), 0o644)
|
||||
catalog.Reset()
|
||||
t.Cleanup(catalog.Reset)
|
||||
|
||||
grok := Provider{ID: "grok", Name: "Grok (SuperGrok)"}
|
||||
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"} {
|
||||
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 {
|
||||
t.Errorf("%s(%q) = %+v, %v; want grok's $2/$6/$0.5", name, id, pr, ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
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"} {
|
||||
if pr, ok := grok.ListPrice(id); ok {
|
||||
t.Errorf("ListPrice(%q) = %+v; want unpriced", id, pr)
|
||||
}
|
||||
if pr, ok := MakerPrice(id); ok {
|
||||
t.Errorf("MakerPrice(%q) = %+v; want unpriced", id, pr)
|
||||
}
|
||||
}
|
||||
if got := PricedName("grok-4.7-xhigh"); got != "grok-4.7" {
|
||||
t.Errorf("PricedName(grok-4.7-xhigh) = %q", got)
|
||||
}
|
||||
if got := PricedName("grok-4.7-low-fast"); got != "grok-4.7-low-fast" {
|
||||
t.Errorf("PricedName(grok-4.7-low-fast) = %q", got)
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"regexp"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -517,17 +518,54 @@ var makerCatalogs = sync.OnceValue(func() []string {
|
||||
// at gpt-6-astra's or gemini-3.8-flash's maker's price, as a Claude
|
||||
// account is at Anthropic's.
|
||||
func (p Provider) ListPrice(model string) (catalog.Price, bool) {
|
||||
if pr, ok := catalog.PricedBy(p.Catalogs(), model); ok {
|
||||
return pr, true
|
||||
for _, m := range pricedNames(model) {
|
||||
if pr, ok := catalog.PricedBy(p.Catalogs(), m); ok {
|
||||
return pr, true
|
||||
}
|
||||
if pr, ok := catalog.PricedBy(makerCatalogs(), m); ok {
|
||||
return pr, true
|
||||
}
|
||||
}
|
||||
return MakerPrice(model)
|
||||
return catalog.Price{}, false
|
||||
}
|
||||
|
||||
// MakerPrice is a model's list price as the first vendor among the presets
|
||||
// that makes the models it serves lists it; for a call whose provider has
|
||||
// gone since.
|
||||
func MakerPrice(model string) (catalog.Price, bool) {
|
||||
return catalog.PricedBy(makerCatalogs(), model)
|
||||
for _, m := range pricedNames(model) {
|
||||
if pr, ok := catalog.PricedBy(makerCatalogs(), m); ok {
|
||||
return pr, true
|
||||
}
|
||||
}
|
||||
return catalog.Price{}, 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 = regexp.MustCompile(`^((?:.*/)?grok-[0-9][^/]*?)-(?:minimal|low|medium|high|xhigh|extra-high)$`)
|
||||
|
||||
// pricedNames are the ids a model is priced by, in order: its own, then,
|
||||
// for a Grok id named at an effort, the model it is that effort of — the
|
||||
// same model, at the same price (#224). Nothing else is renamed: a name no
|
||||
// catalog prices stays unpriced (grok-4.7-build, grok-4.7-mini,
|
||||
// grok-4.7-fast).
|
||||
func pricedNames(model string) []string {
|
||||
out := []string{model}
|
||||
if m := grokEffort.FindStringSubmatch(strings.ToLower(strings.TrimSpace(model))); m != nil {
|
||||
out = append(out, m[1])
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// PricedName is the id a model is priced by where it's looked up by
|
||||
// maker directly (the Sessions page): a Grok id at an effort is its model.
|
||||
func PricedName(model string) string {
|
||||
n := pricedNames(model)
|
||||
return n[len(n)-1]
|
||||
}
|
||||
|
||||
// Chosen reports whether a model is exposed.
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package sessions
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
)
|
||||
|
||||
// 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).
|
||||
func TestPriceOfGrokEffort(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", 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)
|
||||
for _, m := range []string{"grok-4.7", "grok-4.7-low", "grok-4.7-xhigh", "x-ai/grok-4.7-high"} {
|
||||
if pr, ok := priceOf(m); !ok || pr.Input != 2 || pr.Output != 6 || pr.CacheRead != 0.5 {
|
||||
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"} {
|
||||
if pr, ok := priceOf(m); ok {
|
||||
t.Errorf("priceOf(%q) = %+v; want unpriced", m, pr)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -962,7 +962,8 @@ func priceOf(model string) (catalog.Price, bool) {
|
||||
}
|
||||
}
|
||||
bare := strings.ToLower(m[strings.LastIndexByte(m, '/')+1:])
|
||||
for _, id := range []string{bare, dated.ReplaceAllString(bare, "")} {
|
||||
// a Grok id at an effort (grok-4.7-high) at its model's price
|
||||
for _, id := range []string{bare, dated.ReplaceAllString(bare, ""), provider.PricedName(bare)} {
|
||||
for _, c := range makers(id) {
|
||||
if pr, ok := catalog.PriceOf(c, id); ok {
|
||||
return pr, true
|
||||
|
||||
Reference in New Issue
Block a user