Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

provider: a proxy's level- or speed-named model takes its model's levels (nianshou5)

yetoneea33a78a0567
diff --git a/internal/catalog/catalog.go b/internal/catalog/catalog.go
index 56db532c9..66c2bab56 100644
--- a/internal/catalog/catalog.go
+++ b/internal/catalog/catalog.go
@@ -1297,6 +1297,24 @@ func listedBy(providers []string, id string, providerOverrides bool) ([]string,
return nil, false
}
+// variantSuffix is a word a proxy puts after a model's id to name the
+// level or speed it serves the model at: CLIProxyAPI's Antigravity
+// channel lists gemini-3.8-flash-high, claude-opus-5-5-high,
+// claude-opus-4-6-thinking and gpt-oss-120b-medium, and its xAI channel
+// grok-3-mini-fast. Its "(high)" form is found's.
+var variantSuffix = regexp.MustCompile(`(?i)-(minimal|low|medium|high|xhigh|max|thinking|fast)$`)
+
+// Unsuffixed is id with a proxy's level or speed word taken off
+// (variantSuffix), and whether it had one. It is for borrowing levels a
+// model has no word on alone: the vendor's own list, which may name a
+// model so, goes first.
+func Unsuffixed(id string) (string, bool) {
+ if loc := variantSuffix.FindStringIndex(id); loc != nil && loc[0] > 0 {
+ return id[:loc[0]], true
+ }
+ return "", false
+}
+
// KinEfforts are the reasoning levels of a model none of the providers
// named lists, taken from the newest of their thinking models of the same
// name but for its version (gpt-6.1-sol's from gpt-6-sol, mimo-v2.7-flash's
diff --git a/internal/provider/cpa_efforts_test.go b/internal/provider/cpa_efforts_test.go
new file mode 100644
index 000000000..e47c3fe17
--- /dev/null
+++ b/internal/provider/cpa_efforts_test.go
@@ -0,0 +1,133 @@
+package provider
+
+import (
+ "context"
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+
+ "github.com/yetone/magpie/internal/catalog"
+ "github.com/yetone/magpie/internal/codexcat"
+)
+
+// nianshou5 on Discord: a CLIProxyAPI (CPA) the user hosts, added as a
+// custom provider, offered no reasoning effort in the ChatGPT app. CPA's
+// /v1/models gives id, object, created and owned_by alone, and its
+// Antigravity and xAI channels name a model for the level or speed they
+// serve it at (gemini-3.8-flash-high, claude-opus-5-5-high,
+// grok-3-mini-fast), which models.dev lists by no such name. The model's
+// own levels are borrowed, as for any custom provider's model, and reach
+// every list Codex and the ChatGPT app are handed; one whose base magpie
+// doesn't know still takes none, and a vendor's own word stays its own.
+func TestCPAVariantModelsBorrowLevels(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"))
+ if err := os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(catalog.CachePath(), []byte(`{
+ "google": {"models": {
+ "gemini-3.8-flash": {"id":"gemini-3.8-flash","reasoning":true,"reasoning_options":[{"type":"effort","values":["low","medium","high"]}]}}},
+ "anthropic": {"models": {
+ "claude-opus-5-5": {"id":"claude-opus-5-5","reasoning":true,"reasoning_options":[{"type":"effort","values":["low","medium","high","xhigh","max"]}]}}},
+ "xai": {"models": {
+ "grok-3-mini": {"id":"grok-3-mini","reasoning":true,"reasoning_options":[{"type":"effort","values":["low","medium","high"]}]}}},
+ "acme": {"models": {
+ "acme-1-high": {"id":"acme-1-high","reasoning":true},
+ "acme-1": {"id":"acme-1","reasoning":true,"reasoning_options":[{"type":"effort","values":["low","high"]}]}}}
+ }`), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ catalog.Reset()
+ t.Cleanup(catalog.Reset)
+
+ // CPA's /v1/models as its OpenAIModels handler writes it (router-for-
+ // me/CLIProxyAPI sdk/api/handlers/openai): the four fields, nothing of
+ // the thinking levels its registry has
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json; charset=utf-8")
+ w.Write([]byte(`{"data":[` +
+ `{"id":"gemini-3.8-flash-high","object":"model","owned_by":"antigravity"},` +
+ `{"id":"claude-opus-5-5-high","object":"model","owned_by":"antigravity"},` +
+ `{"id":"grok-3-mini-fast","object":"model","created":1740960000,"owned_by":"xai"},` +
+ `{"id":"gemini-3.8-flash","object":"model","owned_by":"google"},` +
+ `{"id":"grok-4.7-build-fast","object":"model","created":1776211200,"owned_by":"xai"}` +
+ `],"object":"list"}`))
+ }))
+ defer srv.Close()
+ live, err := catalog.Fetch(context.Background(), srv.URL+"/v1", "k", false, nil)
+ if err != nil || len(live) != 5 {
+ t.Fatalf("fetch: %v %v", live, err)
+ }
+ ids := []string{"gemini-3.8-flash-high", "claude-opus-5-5-high", "grok-3-mini-fast", "gemini-3.8-flash", "grok-4.7-build-fast"}
+ if err := Save(Provider{ID: "cpa", Name: "CPA", Chat: srv.URL + "/v1", Key: "k", Models: ids}); err != nil {
+ t.Fatal(err)
+ }
+ if err := catalog.SaveLive("cpa", srv.URL+"/v1", live); err != nil {
+ t.Fatal(err)
+ }
+ // acme lists acme-1-high itself, with a thinking switch alone
+ if err := Save(Provider{ID: "acme", Name: "Acme", Catalog: "acme", Chat: "https://acme.test/v1", Key: "k", Models: []string{"acme-1-high"}}); err != nil {
+ t.Fatal(err)
+ }
+
+ want := map[string]string{
+ "cpa/gemini-3.8-flash-high": "low,medium,high",
+ "cpa/claude-opus-5-5-high": "low,medium,high,xhigh,max",
+ "cpa/grok-3-mini-fast": "low,medium,high",
+ "cpa/gemini-3.8-flash": "low,medium,high",
+ "cpa/grok-4.7-build-fast": "",
+ "acme/acme-1-high": "",
+ }
+ got := map[string]string{}
+ for _, e := range Catalog() {
+ got[e.ID] = strings.Join(e.Efforts, ",")
+ }
+ for id, w := range want {
+ if g, ok := got[id]; !ok || g != w {
+ t.Errorf("%s: efforts %q (listed %v), want %q", id, g, ok, w)
+ }
+ }
+ p, err := Find("cpa")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if g := strings.Join(p.Efforts("gemini-3.8-flash-high"), ","); g != "low,medium,high" {
+ t.Errorf("the gateway fits gemini-3.8-flash-high to %q", g)
+ }
+
+ // what the Codex app and the ChatGPT app beside it are handed
+ body, err := json.Marshal(codexcat.Entries(CodexListed(), 0))
+ if err != nil {
+ t.Fatal(err)
+ }
+ var entries []struct {
+ Slug string `json:"slug"`
+ Levels []struct {
+ Effort string `json:"effort"`
+ } `json:"supported_reasoning_levels"`
+ }
+ if err := json.Unmarshal(body, &entries); err != nil {
+ t.Fatal(err)
+ }
+ listed := map[string]string{}
+ for _, e := range entries {
+ var ls []string
+ for _, l := range e.Levels {
+ ls = append(ls, l.Effort)
+ }
+ listed[e.Slug] = strings.Join(ls, ",")
+ }
+ for _, id := range []string{"cpa/gemini-3.8-flash-high", "cpa/claude-opus-5-5-high", "cpa/grok-3-mini-fast"} {
+ if listed[id] != want[id] {
+ t.Errorf("Codex list: %s offers %q, want %q (list %v)", id, listed[id], want[id], listed)
+ }
+ }
+}
diff --git a/internal/provider/models.go b/internal/provider/models.go
index 03cbed114..e51182ec3 100644
--- a/internal/provider/models.go
+++ b/internal/provider/models.go
@@ -1742,8 +1742,17 @@ func borrowedEfforts(id string) []string {
}
// one newer than this machine's catalog: its maker's line's levels
// (gpt-6.1-sol, NextCommit on Discord)
- e, _ := catalog.KinEfforts(makerCatalogs(), id)
- return e
+ if e, ok := catalog.KinEfforts(makerCatalogs(), id); ok {
+ return e
+ }
+ // a proxy's variant of a known model, named for the level or speed
+ // it is served at (CLIProxyAPI's gemini-3.8-flash-high,
+ // claude-opus-5-5-high, grok-3-mini-fast; nianshou5 on Discord): the
+ // model's own levels, which the proxy fits a request's effort to
+ if base, ok := catalog.Unsuffixed(id); ok {
+ return borrowedEfforts(base)
+ }
+ return nil
}
// makerCatalogs are the models.dev ids of the vendors among the presets