Claude Code 2.1.296 parses a Claude model id whose version has a dot
(relay/claude-opus-4.6-us[1m], as many relays name them) as Claude Opus
4: it warns the model is retired, asks with max_tokens 32000 and offers
no effort. The same id with dashes (relay/claude-opus-4-6-us) is Opus
4.6 to it: max_tokens 64000, adaptive thinking, effort.
What changed:
- provider/claudedash.go: ClaudeDashed (a Claude-family version's dots
to dashes; other vendors' ids untouched), ClaudeSpelled (dashed only
when that spelling comes back to exactly this served id), and
ClaudeUndashed/ClaudeRead (a dashed spelling back to the one served
id; an id served as spelled always wins, two ids dashing alike are
neither; :level and [1m] kept). ClaudeRead also knows a switched-off
provider's models, so Reseat still moves Claude Code off one
(TestReseatOff went red without it: opus read "", not
cop/claude-sonnet-4.5).
- agent/claude.go: every model magpie writes into Claude Code's
settings is spelled so: model, the ANTHROPIC_DEFAULT_*_MODEL tiers,
ANTHROPIC_SMALL_FAST_MODEL, CLAUDE_CODE_SUBAGENT_MODEL, modelPicker.
Every read of them (env, claudeMain, claudeStandInAt) takes the
spelling back, so fields, applied state and Drift keep the dotted id.
The user's own values are stashed and given back raw. A Sync rewrites
what an older magpie wrote dotted. claudeName, the capabilities env
and the compact-window lookup see the dashed spelling.
- agent/t3code.go and gateway/desktop.go (claudeLooking): T3 Code's
Claude slugs and Claude Desktop's Code-tab ids without efforts are
spelled dashed too. Desktop entries with efforts still use the mythos
alias, which Claude Code doesn't misparse.
- gateway.go: validateModel and unprefixed take the dashed spelling
back to the served dotted id, before key limits, middleware and
usage see it.
- docs/subsystems agent-wiring and gateway-routing say so.
What was run:
- New tests: TestClaudeDashedIDsReachTheDottedModel (gateway),
TestClaudeDottedVersionsGoInDashed, TestClaudeDottedServedDashedToo
(agent), TestClaudeDashedOnlyClaudeVersions, TestUndashInExactWins,
TestClaudeSplitKeepsEffortAndMark (provider).
- Break-it checks:
- With ClaudeSpelled/ClaudeUndashed made identity:
TestClaudeDottedVersionsGoInDashed fails ("the main model and its
followers": model relay/claude-opus-4.6-us).
TestClaudeDashedIDsReachTheDottedModel fails (sent
"claude-opus-4-6-us", want "claude-opus-4.6-us").
- With ClaudeRead alone made identity, the agent test fails at
"read back" (model:relay/claude-opus-4-6-us).
- Real use: the installed claude 2.1.296 in a sandbox HOME and
CLAUDE_CONFIG_DIR, against an in-process gateway on a free port and
a fake Anthropic upstream. The settings.json was written by
agent.Find("claude").Apply("model", "relay/claude-opus-4.6-us").
- Dashed (magpie's write): the upstream got model claude-opus-4.6-us,
max_tokens 64000, thinking adaptive, effort high. Claude Code
reported canonicalModel claude-opus-4-6, maxOutputTokens 64000.
- The same config with the dotted id by hand: max_tokens 32000,
canonicalModel claude-opus-4-0.
- Full go test -tags nogui ./... (TestReseatOff red on the first
run, fixed as above; agent, provider, gateway and main rerun green),
gofmt -l, go vet, and GOOS=linux and
GOOS=windows go vet -tags nogui on the touched packages.
80 lines
3.0 KiB
Go
80 lines
3.0 KiB
Go
package gateway
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// misteer_ti. on Discord: Claude Code reads a relay's claude-opus-4.6 as
|
|
// Claude Opus 4, so magpie gives it relay/claude-opus-4-6-us. The gateway
|
|
// takes that dashed spelling back to the model the relay serves, its
|
|
// effort and [1m] mark kept; a model served by the dashed name itself is
|
|
// that one, and another vendor's id is never respelled.
|
|
func TestClaudeDashedIDsReachTheDottedModel(t *testing.T) {
|
|
fresh(t)
|
|
reply := func(id string) *fake {
|
|
return &fake{t: t, ctype: "application/json", reply: `{"id":"` + id + `","type":"message","role":"assistant","model":"m","content":[{"type":"text","text":"hi"}],"stop_reason":"end_turn","usage":{"input_tokens":1,"output_tokens":1}}`}
|
|
}
|
|
relay, both := reply("from-relay"), reply("from-both")
|
|
for _, x := range []struct {
|
|
p provider.Provider
|
|
f *fake
|
|
}{
|
|
{provider.Provider{ID: "relay", Name: "Relay", Key: "k", Models: []string{"claude-opus-4.6-us", "claude-haiku-4.5", "glm-4.6"}}, relay},
|
|
{provider.Provider{ID: "both", Name: "Both", Key: "k", Models: []string{"claude-opus-4.6", "claude-opus-4-6"}}, both},
|
|
} {
|
|
up := httptest.NewServer(x.f)
|
|
t.Cleanup(up.Close)
|
|
x.p.Anthropic = up.URL
|
|
if err := provider.Save(x.p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
h := New().Handler()
|
|
do := func(path, model string) *httptest.ResponseRecorder {
|
|
body := `{"model":"` + model + `","max_tokens":10,"messages":[{"role":"user","content":"hi"}]}`
|
|
r := httptest.NewRequest("POST", path, strings.NewReader(body))
|
|
r.Header.Set("Authorization", "Bearer "+Token)
|
|
r.Header.Set("User-Agent", "claude-cli/2.1.296 (external, cli)")
|
|
w := httptest.NewRecorder()
|
|
h.ServeHTTP(w, r)
|
|
return w
|
|
}
|
|
sent := func(f *fake) string {
|
|
var b struct{ Model string }
|
|
json.Unmarshal(f.got, &b)
|
|
return b.Model
|
|
}
|
|
for _, c := range []struct {
|
|
asked string
|
|
f *fake
|
|
want string
|
|
}{
|
|
{"relay/claude-opus-4-6-us", relay, "claude-opus-4.6-us"},
|
|
{"relay/claude-opus-4-6-us[1m]", relay, "claude-opus-4.6-us"},
|
|
{"relay/claude-opus-4-6-us:high", relay, "claude-opus-4.6-us"},
|
|
{"relay/claude-haiku-4-5", relay, "claude-haiku-4.5"},
|
|
{"relay/claude-opus-4.6-us", relay, "claude-opus-4.6-us"},
|
|
// served by the dashed name itself: that one
|
|
{"both/claude-opus-4-6", both, "claude-opus-4-6"},
|
|
{"both/claude-opus-4.6", both, "claude-opus-4.6"},
|
|
// another vendor's id is as asked
|
|
{"relay/glm-4-6", relay, "glm-4-6"},
|
|
} {
|
|
if w := do("/v1/messages", c.asked); w.Code != 200 || sent(c.f) != c.want {
|
|
t.Fatalf("%s: %d %s, sent %q, want %q", c.asked, w.Code, w.Body.String(), sent(c.f), c.want)
|
|
}
|
|
}
|
|
do("/v1/messages", "relay/claude-opus-4-6-us")
|
|
if rec := lastUsage(t); rec.Provider != "relay" || rec.Requested != "relay/claude-opus-4.6-us" {
|
|
t.Fatalf("recorded as %+v", rec)
|
|
}
|
|
if w := do("/v1/messages/count_tokens", "relay/claude-opus-4-6-us"); w.Code != 200 {
|
|
t.Fatalf("count_tokens: %d %s", w.Code, w.Body.String())
|
|
}
|
|
}
|