codex: Codex's Ultrafast (service_tier "ultrafast") reaches the ChatGPT backend when magpie's pool of Codex accounts serves the turn, as it does on Codex's own sign-in; it was dropped for anything but Fast's "priority", and OpenAI's API still gets it as Fast (yxinyu715 on X: two Pro accounts, Ultrafast does nothing through magpie)
Run: TestCodexPoolKeepsUltrafast fails on the old code (backend asked for <nil>) and passes now; go test ./internal/gateway ./internal/provider ./internal/codexcat pass; go vet clean. Not tried with a real account offering Ultrafast: the owner's accounts don't list it.
This commit is contained in:
@@ -688,3 +688,48 @@ func older(a, b string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Codex's Ultrafast (service_tier "ultrafast", offered on a Pro plan's
|
||||
// models) reaches the ChatGPT backend when the pool of Codex's accounts
|
||||
// serves the turn, as it does on Codex's own sign-in, and Fast's
|
||||
// "priority" still does (yxinyu715 on X: two Pro accounts, Ultrafast
|
||||
// does nothing through magpie and works without it).
|
||||
func TestCodexPoolKeepsUltrafast(t *testing.T) {
|
||||
codexSignedIn(t, "spare@example.com")
|
||||
var tiers []any
|
||||
up := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
b, _ := io.ReadAll(r.Body)
|
||||
var m map[string]any
|
||||
json.Unmarshal(b, &m)
|
||||
tiers = append(tiers, m["service_tier"])
|
||||
io.WriteString(w, sse(
|
||||
`data: {"type":"response.created","response":{"id":"r1","model":"gpt-5.5"}}`,
|
||||
`data: {"type":"response.output_text.delta","delta":"pong"}`,
|
||||
`data: {"type":"response.completed","response":{"id":"r1","usage":{"input_tokens":7,"output_tokens":1}}}`))
|
||||
}))
|
||||
t.Cleanup(up.Close)
|
||||
was := provider.CodexBase
|
||||
provider.CodexBase = up.URL + "/backend-api/codex"
|
||||
t.Cleanup(func() { provider.CodexBase = was })
|
||||
|
||||
s := New()
|
||||
for _, tier := range []string{"ultrafast", "priority", "flex"} {
|
||||
tiers = nil
|
||||
rec := httptest.NewRecorder()
|
||||
req := httptest.NewRequest("POST", CodexPath+"/responses", strings.NewReader(`{"model":"gpt-5.5","stream":true,"input":"ping","service_tier":"`+tier+`"}`))
|
||||
req.Header.Set("Authorization", "Bearer chatgpt-token")
|
||||
req.Header.Set("chatgpt-account-id", "acct-1")
|
||||
req.Header.Set("User-Agent", "codex_cli_rs/0.160.1")
|
||||
s.Handler().ServeHTTP(rec, req)
|
||||
if rec.Code != 200 || len(tiers) != 1 {
|
||||
t.Fatalf("%s: status %d, %d requests: %s", tier, rec.Code, len(tiers), rec.Body.String())
|
||||
}
|
||||
want := any(tier)
|
||||
if tier == "flex" {
|
||||
want = nil
|
||||
}
|
||||
if tiers[0] != want {
|
||||
t.Errorf("%s: backend asked for %v", tier, tiers[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,18 @@ func TestResponsesFastTier(t *testing.T) {
|
||||
t.Errorf("%q: tier sent %v, want %v: %s", host, got, want, b)
|
||||
}
|
||||
}
|
||||
// Codex's Ultrafast goes to the ChatGPT backend, the one that offers
|
||||
// it; OpenAI's API gets it as Fast
|
||||
r, _ = parseResponses([]byte(`{"model":"gpt-5.5","input":"hi","service_tier":"ultrafast"}`))
|
||||
if !r.Fast || !r.Ultrafast {
|
||||
t.Fatalf("ultrafast not read: %+v", r)
|
||||
}
|
||||
for host, want := range map[string]string{"chatgpt.com": `"service_tier":"ultrafast"`, "api.openai.com": `"service_tier":"priority"`, "openrouter.ai": ""} {
|
||||
b := string(buildResponses(r, "gpt-5.5", host, false))
|
||||
if want == "" && strings.Contains(b, "service_tier") || want != "" && !strings.Contains(b, want) {
|
||||
t.Errorf("ultrafast to %q: %s", host, b)
|
||||
}
|
||||
}
|
||||
r, _ = parseResponses([]byte(`{"model":"m","input":"hi","service_tier":"flex"}`))
|
||||
if r.Fast {
|
||||
t.Error("flex read as fast")
|
||||
|
||||
@@ -136,6 +136,10 @@ type Request struct {
|
||||
Parallel *bool // parallel tool calls allowed
|
||||
WebSearch bool // the client offered its provider's own web search
|
||||
Fast bool // the client asked for priority processing: service_tier priority (Codex's Fast mode)
|
||||
// Ultrafast is Codex's Ultrafast (service_tier "ultrafast"), which a
|
||||
// ChatGPT account on a plan with it offers on its models; Fast is set
|
||||
// with it, so where there is no Ultrafast the request goes fast
|
||||
Ultrafast bool
|
||||
// CacheKey is the client's prompt_cache_key (Codex sends its thread's
|
||||
// id), which OpenAI, and relays in front of it, route a conversation by
|
||||
// to where its prompt is cached.
|
||||
|
||||
@@ -255,7 +255,7 @@ func parseResponses(body []byte) (*Request, error) {
|
||||
return nil, fmt.Errorf("invalid request: %v", err)
|
||||
}
|
||||
r := &Request{Model: q.Model, System: q.Instructions, MaxTokens: q.MaxOutputTokens, Temp: q.Temperature,
|
||||
TopP: q.TopP, Stream: q.Stream, Parallel: q.ParallelToolCalls, Fast: q.ServiceTier == "priority", CacheKey: q.PromptCacheKey, Include: q.Include,
|
||||
TopP: q.TopP, Stream: q.Stream, Parallel: q.ParallelToolCalls, Fast: q.ServiceTier == "priority" || q.ServiceTier == "ultrafast", Ultrafast: q.ServiceTier == "ultrafast", CacheKey: q.PromptCacheKey, Include: q.Include,
|
||||
ClientMetadata: sentRaw(q.ClientMetadata)}
|
||||
r.Text, r.Format = textFormat(sentRaw(q.Text))
|
||||
if q.Reasoning != nil {
|
||||
@@ -771,6 +771,10 @@ func buildResponses(r *Request, model, host string, rejectTemp bool) []byte {
|
||||
if r.Fast && (host == "chatgpt.com" || host == "api.openai.com") {
|
||||
out["service_tier"] = "priority"
|
||||
}
|
||||
// Ultrafast only the ChatGPT backend offers
|
||||
if r.Ultrafast && host == "chatgpt.com" {
|
||||
out["service_tier"] = "ultrafast"
|
||||
}
|
||||
if r.Effort != "" {
|
||||
out["reasoning"] = map[string]any{"effort": r.Effort, "summary": "auto"}
|
||||
} else if r.Thinking {
|
||||
|
||||
@@ -236,7 +236,7 @@ func codexInstructions(model string) string {
|
||||
// codexBody makes a Responses request the one Codex CLI would send: it
|
||||
// streams only, keeps nothing (so its items carry no ids), carries Codex's
|
||||
// instructions — the client's own riding first in the input — and rejects
|
||||
// the sampling knobs and any service tier but Fast's.
|
||||
// the sampling knobs and any service tier but Fast's and Ultrafast's.
|
||||
func codexBody(body []byte) []byte {
|
||||
dec := json.NewDecoder(bytes.NewReader(body))
|
||||
dec.UseNumber()
|
||||
@@ -247,8 +247,9 @@ func codexBody(body []byte) []byte {
|
||||
for _, k := range []string{"max_output_tokens", "max_completion_tokens", "temperature", "top_p", "previous_response_id", "user", "safety_identifier"} {
|
||||
delete(m, k)
|
||||
}
|
||||
// Codex's Fast mode sends "priority"; any other tier stays out
|
||||
if m["service_tier"] != "priority" {
|
||||
// Codex's Fast mode sends "priority", its Ultrafast "ultrafast"; any
|
||||
// other tier stays out
|
||||
if t := m["service_tier"]; t != "priority" && t != "ultrafast" {
|
||||
delete(m, "service_tier")
|
||||
}
|
||||
model, _ := m["model"].(string)
|
||||
|
||||
@@ -181,8 +181,8 @@ func TestCodexPromptsSameMtime(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Codex's Fast mode reaches the ChatGPT backend as service_tier "priority";
|
||||
// any other tier is dropped as before.
|
||||
// Codex's Fast mode reaches the ChatGPT backend as service_tier "priority",
|
||||
// its Ultrafast as "ultrafast"; any other tier is dropped as before.
|
||||
func TestCodexBodyServiceTier(t *testing.T) {
|
||||
t.Setenv("CODEX_HOME", t.TempDir())
|
||||
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
||||
@@ -195,6 +195,9 @@ func TestCodexBodyServiceTier(t *testing.T) {
|
||||
if v, _ := tier(`{"model":"gpt-6-sol","service_tier":"priority","input":"hi"}`); v != "priority" {
|
||||
t.Errorf("priority: %v", v)
|
||||
}
|
||||
if v, _ := tier(`{"model":"gpt-6-sol","service_tier":"ultrafast","input":"hi"}`); v != "ultrafast" {
|
||||
t.Errorf("ultrafast: %v", v)
|
||||
}
|
||||
for _, s := range []string{`"flex"`, `"auto"`, `"default"`, `"fast"`, `null`} {
|
||||
if v, ok := tier(`{"model":"gpt-6-sol","service_tier":` + s + `,"input":"hi"}`); ok {
|
||||
t.Errorf("%s kept as %v", s, v)
|
||||
|
||||
Reference in New Issue
Block a user