catalog: a relay's deepseek-v4.1-flash is priced at DeepSeek's, whose entry names it by a dated canonical id (Winnie7572 on X, #4811, #5622)

models.dev lists DeepSeek's V4.1 Flash only as deepseek-flash with
canonical_model_id deepseek/deepseek-v4.1-flash-1017. The canonical
fallback (#1520) matched the undated id alone, so every relay serving
deepseek-v4.1-flash (Open Design, WorkBuddy, Tencent Cloud) had no price
and no estimated cost. priceIndex now also keys a maker's own canonical
entries with a trailing snapshot date (-MMDD, -YYYYMMDD, -YYYY-MM-DD)
taken off, tried after the exact and dashed keys, so a price a vendor
lists by the id as given still wins. Only the provider that is the
canonical's maker counts, as before, so no other vendor's model is priced.

Open Design's other models were checked with the plugin's real ids
(packages/opendesign models.mjs) against models.dev: every one but
deepseek-v4.1-flash and deepseek-v4.1-flash-eco was already priced.
-eco is the plugin's own id, not a snapshot, and stays unpriced (filed).

Run (mote, at this tree): go test -count=1 for internal/provider,
catalog, usage, gui all ok; go vet darwin, windows, linux nogui ok.
New TestRelayDeepSeekSnapshotCanonicalPriced (models.dev entries in
testdata/models_dev_opendesign.json) is red with the snapshot key
disabled by hand. TestCommandCodePlanPrice's relay case asserted the gap
("a relay took Command Code's list price" for an unpriced model); it now
asserts DeepSeek's price, which Command Code's plan still beats with its
own catalog. Not tried: a live Open Design account.
This commit is contained in:
yetone
2026-11-13 01:01:23 +08:00
parent 76ceff87c9
commit 1ca2c62c49
4 changed files with 77 additions and 7 deletions
+21 -2
View File
@@ -13,6 +13,7 @@ import (
"net/http"
"os"
"path/filepath"
"regexp"
"slices"
"sort"
"strconv"
@@ -979,6 +980,9 @@ type priceIndex struct {
// canon and canonDashed are the price the vendor's own entries under a
// canonical id (bare, and dashed) give, nil where they disagree
canon, canonDashed map[string]*Price
// canonSnap is canonDashed with the canonical's snapshot date taken
// off (deepseek-v4.1-flash-1017 is deepseek-v4.1-flash)
canonSnap map[string]*Price
}
var priceIndexes struct {
@@ -998,13 +1002,13 @@ func priceIndexOf(all map[string]mdProvider, at int, pid string) *priceIndex {
if x, ok := priceIndexes.by[pid]; ok {
return x
}
x := &priceIndex{bare: map[string]string{}, dashed: map[string]string{}, canon: map[string]*Price{}, canonDashed: map[string]*Price{}}
x := &priceIndex{bare: map[string]string{}, dashed: map[string]string{}, canon: map[string]*Price{}, canonDashed: map[string]*Price{}, canonSnap: map[string]*Price{}}
first := func(by map[string]string, k, key string) {
if was, ok := by[k]; !ok || key < was {
by[k] = key
}
}
seen := map[*map[string]*Price]map[string]bool{&x.canon: {}, &x.canonDashed: {}}
seen := map[*map[string]*Price]map[string]bool{&x.canon: {}, &x.canonDashed: {}, &x.canonSnap: {}}
agree := func(by *map[string]*Price, k string, p *Price) {
if !seen[by][k] {
seen[by][k] = true
@@ -1027,6 +1031,9 @@ func priceIndexOf(all map[string]mdProvider, at int, pid string) *priceIndex {
c := bareID(m.Canonical)
agree(&x.canon, c, m.Cost)
agree(&x.canonDashed, dashed(c), m.Cost)
if sn := snapshotOf(dashed(c)); sn != dashed(c) {
agree(&x.canonSnap, sn, m.Cost)
}
}
priceIndexes.by[pid] = x
return x
@@ -1047,6 +1054,10 @@ func canonicallyPriced(all map[string]mdProvider, at int, providers []string, b
for _, by := range []func(*priceIndex) (*Price, bool){
func(x *priceIndex) (*Price, bool) { p, ok := x.canon[b]; return p, ok },
func(x *priceIndex) (*Price, bool) { p, ok := x.canonDashed[dashed(b)]; return p, ok },
// and as the snapshot it is: models.dev says DeepSeek's deepseek-flash
// is deepseek/deepseek-v4.1-flash-1017, and the relays serve it as
// deepseek-v4.1-flash (Open Design's, Winnie7572 on X)
func(x *priceIndex) (*Price, bool) { p, ok := x.canonSnap[dashed(b)]; return p, ok },
} {
for _, pid := range providers {
if p, ok := by(priceIndexOf(all, at, pid)); ok && p != nil {
@@ -1168,6 +1179,14 @@ func makerPriced(all map[string]mdProvider, at int, prefer []string, id string)
return Price{}, false
}
// mmddSnapshot is the date a vendor ends a snapshot's id with: -0813,
// -1017 (month and day), -20261017 or -2026-10-17.
var mmddSnapshot = regexp.MustCompile(`-(?:(?:0[1-9]|1[0-2])(?:0[1-9]|[12][0-9]|3[01])|20[0-9]{2}(?:-?)(?:0[1-9]|1[0-2])(?:-?)(?:0[1-9]|[12][0-9]|3[01]))$`)
// snapshotOf is an id without the date of its snapshot, as the model it is
// a snapshot of: deepseek-v4.1-flash-1017 is deepseek-v4.1-flash.
func snapshotOf(id string) string { return mmddSnapshot.ReplaceAllString(id, "") }
// dashed is an id with its dots as dashes: the spelling two ids are compared
// in when one vendor writes a model's version 4.6 and another 4-6.
func dashed(id string) string { return strings.ReplaceAll(id, ".", "-") }
+7 -5
View File
@@ -290,8 +290,8 @@ func TestOllamaCloudOffPeakPrice(t *testing.T) {
// commandCodeCatalog is models.dev's api.json as magpie had it on
// 2026-10-30, these entries byte for byte (descriptions and the like left
// out). DeepSeek lists V4.1 Flash only as deepseek-flash, by a dated
// canonical id, so no maker price is found for Command Code's undated
// deepseek/deepseek-v4.1-flash; Command Code's own catalog lists it.
// canonical id; Command Code's own catalog lists its undated
// deepseek/deepseek-v4.1-flash, which comes first for its plan.
const commandCodeCatalog = `{
"deepseek":{"id":"deepseek","api":"https://api.deepseek.com","name":"DeepSeek","models":{
"deepseek-flash":{"id":"deepseek-flash","name":"DeepSeek Flash","cost":{"input":0.15,"output":0.6,"cache_read":0.003},"canonical_model_id":"deepseek/deepseek-v4.1-flash-1017"},
@@ -350,8 +350,10 @@ func TestCommandCodePlanPrice(t *testing.T) {
t.Errorf("set at %s: %+v at peak, %+v off-peak", key, a, b)
}
}
// another provider's id says nothing of Command Code's catalog
if _, ok := (Provider{ID: "relay", Chat: "https://relay.example/v1"}).ListPrice("deepseek/deepseek-v4.1-flash"); ok {
t.Error("a relay took Command Code's list price")
// another provider's id says nothing of Command Code's catalog: a relay
// has its maker's price, DeepSeek's deepseek-flash, whose dated
// canonical id (deepseek-v4.1-flash-1017) is this model's snapshot
if pr, ok := (Provider{ID: "relay", Chat: "https://relay.example/v1"}).ListPrice("deepseek/deepseek-v4.1-flash"); !ok || pr.Input != 0.15 || pr.Output != 0.6 || pr.CacheRead != 0.003 {
t.Errorf("a relay's price: %+v %v; want DeepSeek's 0.15/0.6/0.003", pr, ok)
}
}
@@ -0,0 +1,48 @@
package provider
import (
"os"
"path/filepath"
"testing"
"github.com/yetone/magpie/internal/catalog"
)
// A relay that serves DeepSeek's V4.1 Flash under the id the maker's
// canonical_model_id gives it, with a snapshot date on it in models.dev
// (deepseek-flash is deepseek/deepseek-v4.1-flash-1017), is priced at
// DeepSeek's list price: the Open Design plugin's deepseek-v4.1-flash showed
// no estimated cost (Winnie7572 on X). The ids are those the plugin lists
// (packages/opendesign models.mjs); testdata is models.dev's entries for them,
// as read 2026-11-13.
func TestRelayDeepSeekSnapshotCanonicalPriced(t *testing.T) {
claudeHome(t)
b, err := os.ReadFile("testdata/models_dev_opendesign.json")
if err != nil {
t.Fatal(err)
}
os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755)
os.WriteFile(catalog.CachePath(), b, 0o644)
catalog.Reset()
t.Cleanup(catalog.Reset)
for _, c := range []struct {
model string
input, outp float64
}{
{"deepseek-v4.1-flash", 0.15, 0.6},
{"deepseek-v4-flash", 0.15, 0.6},
{"deepseek-v4-flash-vision-exp", 0.15, 0.6},
{"deepseek-v4-pro", 0.66, 1.98},
} {
pr, ok := EffectivePrice("opendesign", c.model)
if !ok || pr.Input != c.input || pr.Output != c.outp {
t.Errorf("opendesign/%s: %+v, %v; want DeepSeek's $%v/$%v", c.model, pr, ok, c.input, c.outp)
}
}
// another vendor's id that only looks alike stays unpriced
for _, m := range []string{"deepseek-v4.1-flash-0000", "other-v4.1-flash", "deepseek-v4.1-flash-turbo"} {
if pr, ok := EffectivePrice("opendesign", m); ok {
t.Errorf("opendesign/%s priced %+v", m, pr)
}
}
}
File diff suppressed because one or more lines are too long