Archivemylife on X sent a Responses request for gpt-6.1-sol on a Codex account with "service_tier": "fast" and got "default" back. magpie dropped the key: codexBody kept only "priority" and "ultrafast", and the IR's Fast (Chat and Responses parse) is set by "priority" alone, so "fast" never reached the ChatGPT backend on either API. "fast" is Codex's own name for its Fast mode. Codex never sends it: ServiceTier::from_request_value reads "fast" and "priority" alike as Fast and request_value sends "priority" (openai/codex codex-rs/protocol/src/config_types.rs; step_settings.rs normalizes the legacy "fast" the same way; read at 7fb4014d5). - handle() turns a top-level string service_tier "fast" into "priority" on Chat and Responses (fastTier), before the Codex and key tier settings, routing and tier_asked. Those settings still win: they are the user's own value. Other tiers, "Fast", nested or non-string values go as they came. - codexBody sends "fast" as "priority" too, for any path that reaches it without the handler. - Anthropic Messages: Claude's equivalent is speed "fast", already read as Fast and sent to the ChatGPT backend as priority (covered by the new test). Anthropic's own service_tier (auto/standard_only) is about capacity, not speed, and is not mapped. - Not changed: "flex" (Codex's Flex) is still dropped for ChatGPT accounts, as before; responses.go untouched. The backend's reply still says "auto" then "default" with priority honoured (servedTierAt already knows this), so the client's response service_tier is not proof either way; speed is. Run: - Red on the old code (production files from HEAD, tests new): TestFastTierWordReachesCodex red on Responses fast, whole fast, Chat fast, whole fast; TestCodexBodyServiceTier red on "fast". Green with the change. - Real Pro ChatGPT account in a sandbox HOME (codex logins only, refresh tokens blanked, no agent config touched), binary built at this change, gpt-6.1-sol: Responses "fast" (whole and streamed), Chat "fast" and Messages speed "fast" each went out with tier priority (trace tries); "default" went with none. Streamed Responses reply said service_tier auto/default. Two pairs, 600-word essay, effort low: priority 28.3 and 30.1 tok/s, none 22.3 and 21.2 tok/s. - mica: go test -count=1 -timeout 45m ./... at this tree: 103 ok, no FAIL. go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./..., go build: ok. gofmt -l: empty. That tree was on be6f8b730; after rebasing onto3f4372cc9(a gateway change), internal/gateway (962s) and internal/provider ran ok again at this tree on mica. Rebased again ontoc5f2a67d0(routing.go, agy quota): go vet ./internal/gateway ./internal/provider and go test -run "Tier|Fast|Codex|Agy" on both packages ok at the pushed tree. Not tried: a Plus account; Codex's own sign-in route (codexBackend), where Codex itself never sends "fast".
73 lines
3.3 KiB
Go
73 lines
3.3 KiB
Go
package gateway
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/tidwall/gjson"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// Archivemylife on X: a Responses request for a Codex account's model with
|
|
// service_tier "fast", Codex's own name for its Fast mode, reached the
|
|
// ChatGPT backend with no tier at all. Codex sends Fast as "priority"
|
|
// (ServiceTier::request_value in openai/codex), so "fast" goes as
|
|
// "priority" on every OpenAI API it can arrive on, and the route says the
|
|
// tier was asked; Claude's speed "fast" already did. Another tier, and a
|
|
// request with none, goes as before.
|
|
func TestFastTierWordReachesCodex(t *testing.T) {
|
|
codexSignedIn(t)
|
|
d := daybreak(t)
|
|
to, _ := url.Parse(provider.CodexBase)
|
|
provider.CodexBase = "https://chatgpt.com/backend-api/codex"
|
|
s := New()
|
|
s.client = &http.Client{Transport: roundTripFunc(func(r *http.Request) (*http.Response, error) {
|
|
r.URL.Scheme, r.URL.Host = to.Scheme, to.Host
|
|
return http.DefaultTransport.RoundTrip(r)
|
|
})}
|
|
const m = `"model":"codex/gpt-daybreak-blue-latest"`
|
|
const msgs = `"messages":[{"role":"user","content":"Respond with OK."}]`
|
|
for _, c := range []struct{ name, path, body, want string }{
|
|
{"Responses, fast", "/v1/responses", `{` + m + `,"input":"Respond with OK.","stream":true,"service_tier":"fast"}`, "priority"},
|
|
{"Responses, whole, fast", "/v1/responses", `{` + m + `,"input":"Respond with OK.","service_tier":"fast"}`, "priority"},
|
|
{"Responses, priority", "/v1/responses", `{` + m + `,"input":"Respond with OK.","stream":true,"service_tier":"priority"}`, "priority"},
|
|
{"Chat, fast", "/v1/chat/completions", `{` + m + `,"stream":true,` + msgs + `,"service_tier":"fast"}`, "priority"},
|
|
{"Chat, whole, fast", "/v1/chat/completions", `{` + m + `,` + msgs + `,"service_tier":"fast"}`, "priority"},
|
|
{"Messages, speed fast", "/v1/messages", `{` + m + `,"max_tokens":64,"stream":true,` + msgs + `,"speed":"fast"}`, "priority"},
|
|
{"Responses, flex", "/v1/responses", `{` + m + `,"input":"Respond with OK.","stream":true,"service_tier":"flex"}`, ""},
|
|
{"Responses, none", "/v1/responses", `{` + m + `,"input":"Respond with OK.","stream":true}`, ""},
|
|
{"Chat, none", "/v1/chat/completions", `{` + m + `,"stream":true,` + msgs + `}`, ""},
|
|
} {
|
|
r := postFrom(t, s, "opencode", c.path, c.body)
|
|
b := d.last(t)
|
|
if got := gjson.GetBytes(b, "service_tier").String(); got != c.want {
|
|
t.Errorf("%s: the backend got service_tier %q, want %q: %s", c.name, got, c.want, b)
|
|
}
|
|
if c.want != "" && r.Tier != "priority" && r.Tier != "fast" {
|
|
t.Errorf("%s: the route says tier %q was asked", c.name, r.Tier)
|
|
}
|
|
}
|
|
}
|
|
|
|
// fastTier changes "fast" alone, and only as a top-level string; every
|
|
// other body comes back byte for byte.
|
|
func TestFastTier(t *testing.T) {
|
|
if got := gjson.GetBytes(fastTier([]byte(`{"model":"m","service_tier":"fast","input":"hi"}`)), "service_tier").String(); got != "priority" {
|
|
t.Errorf("fast went as %q", got)
|
|
}
|
|
for _, in := range []string{
|
|
`{"model":"m","service_tier":"priority"}`,
|
|
`{"model":"m","service_tier":"flex"}`,
|
|
`{"model":"m","service_tier":"Fast"}`,
|
|
`{"model":"m","metadata":{"service_tier":"fast"}}`,
|
|
`{"model":"m","service_tier":["fast"]}`,
|
|
`{"model":"m"}`,
|
|
`not json`,
|
|
} {
|
|
if got := string(fastTier([]byte(in))); got != in {
|
|
t.Errorf("fastTier(%s) = %s", in, got)
|
|
}
|
|
}
|
|
}
|