usage: a ChatGPT card's image row tells the window its replies' headers say, not a 15-minute guess (#6412, Green14964 on X)

ChatGPT's images API answers every drawing, a 200 too, with the image
allowance it counted: x-codex-active-limit: imagegen_premium and the
window in x-codex-primary-* (window-minutes 1440, reset-at), as the
reporter captured on a Pro account; Codex 0.160.1 also reads it from a
family named for the limit (x-imagegen-premium-primary-*,
parse_all_rate_limits). magpie read none of it on the image path: the
row said "Unknown" until a refusal, and a refusal whose body names no
resets_at rested the image model for quotaRest's 15 minutes, so the
card said "2 minutes" of a 24-hour window.

- gateway/codex_image_limits.go: codexImageHeaderLimit reads the image
  window from the limit's own family or, when x-codex-active-limit names
  an image limit, from x-codex-*; heardCodexImage keeps it per account
  (in memory), handed to provider.ImageHeard.
- Both drawing routes hear it: magpie's own (sendWith in draw.go) and
  Codex's relayed /images/generations and /images/edits
  (codex_backend.go).
- codexHeaderLimits tells no chat window when the active limit is an
  image one, so the 1440-minute window never lands on the 5-hour or
  weekly row.
- restDrawer: a 429 with the heard window at 100% counts as the quota
  (ChatGPT's "image limit reached" read as a rate limit), and with no
  resets_at in the body it rests until the heard reset, capped at
  longestQuota.
- provider.WithImageLane: the row says Available (or Used up at 100%)
  with that reset; a rest still says Used up. "Available" translated
  (zh, zh-TW, ja, de).
- docs/subsystems/providers-accounts.md updated.

Run (mote): at base 610ae1f54, go test -count=1 -timeout 45m
./internal/gateway ./internal/provider: provider ok; gateway red only
in TestRefusalAfterShownThinkingGoesToTheNext/chat_content_filter_to_
responses (#5761, refusal handover, load 61). At the pushed head's
tree (rebased on 54b6d4d39): gofmt -l clean; go vet darwin,
GOOS=windows, GOOS=linux -tags nogui ok; -count=3 of that test, the
TestCodexImage*/TestCodexRelayed*/TestCodexLimits*/TestCodexDraw*/
TestWithImageLane tests ok. GUI, chromium and webkit: codex-image-row,
i18n-keys, i18n-en-no-cjk ok; 57 of the 118 quota-*/usage-* files run
before the run was stopped, 51 ok, reds all filed on main:
quota-refresh-order (#6180), usage-agents-hide (#3414, #6003),
usage-cards-hide (#6294), usage-computers (#5224), usage-focus-steady
(#3501), usage-fold (#3415, #6003). app.js is unchanged.

Broken by hand, each red: without the sendWith hook,
TestCodexImageRowFromA200sHeaders and TestCodexImageRefusalRests-
UntilItsWindow; without the relay hook, TestCodexRelayedImageWindowHeard;
without the active-limit guard in codexHeaderLimits, TestCodexImage-
Headers; without the heard-reset branch, the refusal test rests 15
minutes (the reporter's symptom); without the 429 gating, it doesn't
rest at all.

Not tried: a real ChatGPT account's drawing (the fixtures are the
reporter's captured headers); Plus and other plans' limit names beyond
imagegen*/image_gen; the heard window doesn't survive a restart (the
row is Unknown until the next drawing); no share or count is shown.
This commit is contained in:
yetone
2026-11-13 12:38:22 +08:00
parent 5eac086aec
commit 436d507f0e
9 changed files with 399 additions and 28 deletions
File diff suppressed because one or more lines are too long
+7
View File
@@ -1410,6 +1410,13 @@ func (s *Server) codexUpstreamOn(w http.ResponseWriter, r *http.Request, rest st
}
body = b
}
if rest == "/images/generations" || rest == "/images/edits" {
if acct, ok := codexRelayedAccount(base, r.Header, on); ok {
// Codex's own drawing, relayed: the image window its reply
// tells is the account's image row (#6412)
heardCodexImage(acct, res.Header)
}
}
if rest == "/responses" {
if acct, ok := codexRelayedAccount(base, r.Header, on); ok {
// the windows the reply tells of the account it went out on
+94
View File
@@ -0,0 +1,94 @@
package gateway
import (
"net/http"
"strings"
"sync"
"time"
"github.com/yetone/magpie/internal/lazyre"
"github.com/yetone/magpie/internal/provider"
)
// ChatGPT's images API tells the image allowance of the account it drew on
// in every reply, a 200 as well as a 429 (#6412, hqqqqqqqh): it names the
// limit counted, x-codex-active-limit: imagegen_premium, and the window in
// the x-codex-primary-* headers (window-minutes 1440, reset-at), or, as
// Codex 0.160.1 reads it (codex-api rate_limits.rs, parse_all_rate_limits),
// in a family named for the limit: x-imagegen-premium-primary-*, or
// x-image-gen-primary-* for image_gen. That window is the image row's
// (provider.ImageLane), never the account's 5-hour or weekly one: it is
// kept apart from them (provider.NoteCodexLimits is never told it), and a
// chat reply that names an image limit tells no chat window either.
// imageLimitName is a limit id of the image allowance: imagegen_premium,
// image_gen, as x-codex-active-limit or a header family names it.
func imageLimitName(name string) bool {
n := strings.ReplaceAll(strings.ToLower(strings.TrimSpace(name)), "-", "_")
return strings.HasPrefix(n, "imagegen") || strings.HasPrefix(n, "image_gen")
}
// imageFamily is a header of a limit's own family's window
// (x-imagegen-premium-primary-window-minutes), with the limit's name.
var imageFamily = lazyre.New(`^x-(.+)-(?:primary|secondary)-window-minutes$`)
// codexImageHeaderLimit is the image window h tells: of the family named
// for the image limit first, else, when x-codex-active-limit names an
// image limit, of the x-codex-* family; false when it tells none.
func codexImageHeaderLimit(h http.Header, now time.Time) (provider.CodexLimit, bool) {
var fams []string
for k := range h {
if m := imageFamily.FindStringSubmatch(strings.ToLower(k)); m != nil && m[1] != "codex" && imageLimitName(m[1]) {
fams = append(fams, m[1])
}
}
if imageLimitName(h.Get("x-codex-active-limit")) {
fams = append(fams, "codex")
}
for _, fam := range fams {
if ls := headerLimitsOf(h, "x-"+fam+"-", now); len(ls) > 0 {
l := ls[0]
for _, o := range ls[1:] {
// of two windows, the fuller is the one that holds
if o.Used > l.Used {
l = o
}
}
return l, true
}
}
return provider.CodexLimit{}, false
}
// codexImageHeard is the image window each ChatGPT account's last reply
// told, by agent (as its usage is read)/lower-cased user.
var codexImageHeard = struct {
sync.Mutex
m map[string]provider.CodexLimit
}{m: map[string]provider.CodexLimit{}}
func init() { provider.ImageHeard = imageHeardOf }
// heardCodexImage keeps the image window h tells of p's ChatGPT account.
func heardCodexImage(p provider.Provider, h http.Header) {
if p.Account == nil || p.Account.Agent != "codex" || p.Account.User == "" || h == nil {
return
}
l, ok := codexImageHeaderLimit(h, time.Now())
if !ok {
return
}
codexImageHeard.Lock()
codexImageHeard.m[p.Account.UsageAgent()+"/"+strings.ToLower(p.Account.User)] = l
codexImageHeard.Unlock()
}
// imageHeardOf is the image window a reply last told of agent's account
// user, while it has not renewed: one with no reset said, or one past
// it, tells nothing of now.
func imageHeardOf(agent, user string, now time.Time) (provider.CodexLimit, bool) {
codexImageHeard.Lock()
l, ok := codexImageHeard.m[agent+"/"+strings.ToLower(user)]
codexImageHeard.Unlock()
return l, ok && l.Resets.After(now)
}
+212
View File
@@ -0,0 +1,212 @@
package gateway
import (
"encoding/base64"
"io"
"net/http"
"net/http/httptest"
"strconv"
"strings"
"sync"
"testing"
"time"
"github.com/yetone/magpie/internal/provider"
)
// forgetImageHeard forgets every image window heard, now and when t ends.
func forgetImageHeard(t *testing.T) {
t.Helper()
clear := func() {
codexImageHeard.Lock()
codexImageHeard.m = map[string]provider.CodexLimit{}
codexImageHeard.Unlock()
}
clear()
t.Cleanup(clear)
}
// imageRowOf is the image row of user's ChatGPT card as it is handed out.
func imageRowOf(t *testing.T, user string) provider.QuotaWindow {
t.Helper()
in := []provider.SubscriptionQuota{{Provider: "codex", User: user, Windows: []provider.QuotaWindow{{Name: "5 hours", Used: 40}, {Name: "7 days", Used: 10}}}}
out := provider.WithImageLane(in, time.Now())
if len(out[0].Windows) != 3 || out[0].Windows[2].Lane != provider.ImageLane {
t.Fatalf("windows = %+v", out[0].Windows)
}
return out[0].Windows[2]
}
// #6412 (hqqqqqqqh): a drawing's 200 carries the account's image window,
// x-codex-active-limit: imagegen_premium with x-codex-primary-* of 1440
// minutes, as the reporter captured it on a Pro account. The image row
// then says when it renews, not "unknown"; and those headers are never
// taken for the account's 5-hour or weekly window.
func TestCodexImageRowFromA200sHeaders(t *testing.T) {
codexSignedIn(t)
forgetImageHeard(t)
at := time.Now().Add(12 * time.Hour).Truncate(time.Second)
up := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
io.ReadAll(r.Body)
// the reporter's capture, its reset moved to the test's time
w.Header().Set("x-codex-active-limit", "imagegen_premium")
w.Header().Set("x-codex-plan-type", "pro")
w.Header().Set("x-codex-primary-used-percent", "0")
w.Header().Set("x-codex-primary-window-minutes", "1440")
w.Header().Set("x-codex-primary-reset-after-seconds", strconv.FormatInt(int64(time.Until(at)/time.Second), 10))
w.Header().Set("x-codex-primary-reset-at", strconv.FormatInt(at.Unix(), 10))
w.Header().Set("Content-Type", "application/json")
io.WriteString(w, `{"created":1,"data":[{"b64_json":"`+base64.StdEncoding.EncodeToString(pngBytes)+`"}],"usage":{"input_tokens":5,"output_tokens":196}}`)
}))
t.Cleanup(up.Close)
was := provider.CodexBase
provider.CodexBase = up.URL + "/backend-api/codex"
t.Cleanup(func() { provider.CodexBase = was })
var mu sync.Mutex
var chat []provider.CodexLimit
old := noteCodexLimits
noteCodexLimits = func(_, _ string, ls []provider.CodexLimit) { mu.Lock(); chat = append(chat, ls...); mu.Unlock() }
t.Cleanup(func() { noteCodexLimits = old })
if w := imageRowOf(t, "me@example.com"); w.Display != "Unknown" || w.ResetsAt != nil {
t.Fatalf("before any drawing the row = %+v", w)
}
code, _, raw := postImages(t, New(), "/v1/images/generations", "application/json", `{"model":"codex/gpt-image-2","prompt":"a magpie","size":"1024x1024"}`)
if code != 200 {
t.Fatalf("%d %s", code, raw)
}
w := imageRowOf(t, "me@example.com")
if w.ResetsAt == nil || !w.ResetsAt.Equal(at) || w.Display != "Available" || !w.Text || !w.Aside || w.Used != 0 {
t.Fatalf("after a drawing the row = %+v, want available until %v, no share", w, at)
}
if w.ResetSecs < int64(11*time.Hour/time.Second) {
t.Fatalf("resets in %ds, want about 12h", w.ResetSecs)
}
if other := imageRowOf(t, "other@example.com"); other.ResetsAt != nil {
t.Fatalf("another account's row took it: %+v", other)
}
mu.Lock()
defer mu.Unlock()
if len(chat) != 0 {
t.Fatalf("the image window was taken for the account's own: %+v", chat)
}
}
// A refusal whose body names no reset, as Codex's own test has
// imagegen_premium's (app-server imagegen_extension.rs), rests the image
// model until the window its headers tell renews, in the limit's own
// family (x-imagegen-premium-primary-*), not quotaRest's 15 minutes: the
// card said "2 minutes" of a 24-hour window (#6412).
func TestCodexImageRefusalRestsUntilItsWindow(t *testing.T) {
codexSignedIn(t)
forgetImageHeard(t)
at := time.Now().Add(20 * time.Hour).Truncate(time.Second)
up := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
io.ReadAll(r.Body)
w.Header().Set("x-codex-active-limit", "imagegen_premium")
w.Header().Set("x-imagegen-premium-primary-used-percent", "100")
w.Header().Set("x-imagegen-premium-primary-window-minutes", "1440")
w.Header().Set("x-imagegen-premium-primary-reset-at", strconv.FormatInt(at.Unix(), 10))
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusTooManyRequests)
io.WriteString(w, `{"error":{"type":"usage_limit_reached","message":"image limit reached","resets_at":null,"plan_type":"plus"}}`)
}))
t.Cleanup(up.Close)
was := provider.CodexBase
provider.CodexBase = up.URL + "/backend-api/codex"
t.Cleanup(func() { provider.CodexBase = was })
t.Cleanup(func() {
restingUntil.Lock()
var keys []string
for k, r := range restingUntil.note {
if strings.EqualFold(r.user, "me@example.com") {
keys = append(keys, k)
}
}
restingUntil.Unlock()
for _, k := range keys {
clearRest(k)
}
})
code, _, raw := postImages(t, New(), "/v1/images/generations", "application/json", `{"model":"codex/gpt-image-2","prompt":"a magpie"}`)
if code != http.StatusTooManyRequests {
t.Fatalf("%d %s", code, raw)
}
// the model rests until then, so the next drawing asks another account first
if until, ok := imageRestOf("codex", "me@example.com", time.Now()); !ok || until.Sub(at).Abs() > 2*time.Second {
t.Fatalf("rests until %v (%v), want %v", until, ok, at)
}
w := imageRowOf(t, "me@example.com")
if w.ResetsAt == nil || w.ResetsAt.Sub(at).Abs() > 2*time.Second || w.Display != "Used up" {
t.Fatalf("after the refusal the row = %+v, want used up until %v", w, at)
}
}
// Codex's own drawing, relayed to ChatGPT with its sign-in the only
// account, tells the image row too.
func TestCodexRelayedImageWindowHeard(t *testing.T) {
codexSignedIn(t)
forgetImageHeard(t)
at := time.Now().Add(6 * time.Hour).Truncate(time.Second)
up := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
io.ReadAll(r.Body)
w.Header().Set("x-codex-active-limit", "imagegen_premium")
w.Header().Set("x-codex-primary-used-percent", "100")
w.Header().Set("x-codex-primary-window-minutes", "1440")
w.Header().Set("x-codex-primary-reset-at", strconv.FormatInt(at.Unix(), 10))
w.Header().Set("Content-Type", "application/json")
io.WriteString(w, `{"created":1,"data":[{"b64_json":"`+base64.StdEncoding.EncodeToString(pngBytes)+`"}]}`)
}))
t.Cleanup(up.Close)
was := provider.CodexBase
provider.CodexBase = up.URL + "/backend-api/codex"
t.Cleanup(func() { provider.CodexBase = was })
rec := httptest.NewRecorder()
req := httptest.NewRequest("POST", CodexPath+"/images/generations", strings.NewReader(`{"model":"gpt-image-2","prompt":"a magpie"}`))
req.Header.Set("Authorization", "Bearer chatgpt-token")
req.Header.Set("Content-Type", "application/json")
req.Header.Set("chatgpt-account-id", "acct-1")
New().Handler().ServeHTTP(rec, req)
if rec.Code != 200 {
t.Fatalf("%d %s", rec.Code, rec.Body)
}
if w := imageRowOf(t, "me@example.com"); w.ResetsAt == nil || !w.ResetsAt.Equal(at) || w.Display != "Used up" {
t.Fatalf("row = %+v, want used up until %v", w, at)
}
}
// Which headers tell the image window: the limit's own family, or the
// x-codex-* one when x-codex-active-limit names an image limit; and then
// never the account's own windows. A chat reply's are as they were.
func TestCodexImageHeaders(t *testing.T) {
now := time.Unix(1_800_000_000, 0)
h := http.Header{}
h.Set("x-codex-primary-used-percent", "0")
h.Set("x-codex-primary-window-minutes", "1440")
h.Set("x-codex-primary-reset-after-seconds", "600")
if _, ok := codexImageHeaderLimit(h, now); ok {
t.Fatal("x-codex-* with no image limit named taken for the image window")
}
if ls := codexHeaderLimits(h, now); len(ls) != 1 {
t.Fatalf("a chat reply's window lost: %+v", ls)
}
for _, name := range []string{"imagegen_premium", "image_gen", "imagegen_basic"} {
h.Set("x-codex-active-limit", name)
if l, ok := codexImageHeaderLimit(h, now); !ok || l.Span != 24*time.Hour || !l.Resets.Equal(now.Add(10*time.Minute)) {
t.Fatalf("%s: %+v %v", name, l, ok)
}
if ls := codexHeaderLimits(h, now); ls != nil {
t.Fatalf("%s: the image window taken for the account's: %+v", name, ls)
}
}
f := http.Header{}
f.Set("x-codex-active-limit", "image_gen")
f.Set("x-image-gen-primary-used-percent", "100")
f.Set("x-image-gen-primary-window-minutes", "1440")
f.Set("x-image-gen-primary-reset-at", "1800003600")
if l, ok := codexImageHeaderLimit(f, now); !ok || l.Used != 100 || l.Resets.Unix() != 1800003600 {
t.Fatalf("image_gen's own family: %+v %v", l, ok)
}
}
+14 -2
View File
@@ -77,11 +77,23 @@ func codexAnsweredLately(agent, user string, now time.Time) bool {
// codexHeaderLimits are the windows the x-codex-primary-* and
// x-codex-secondary-* headers tell; one that doesn't say how long it runs
// is left out, as no window read can be told to be it.
// is left out, as no window read can be told to be it. None when
// x-codex-active-limit names the image allowance, whose window they then
// are (codexImageHeaderLimit).
func codexHeaderLimits(h http.Header, now time.Time) []provider.CodexLimit {
if imageLimitName(h.Get("x-codex-active-limit")) {
// the x-codex-* windows are the image allowance's (#6412)
return nil
}
return headerLimitsOf(h, "x-codex-", now)
}
// headerLimitsOf are the windows of the header family fam (x-codex-,
// x-imagegen-premium-) tells: its primary- and secondary- ones.
func headerLimitsOf(h http.Header, fam string, now time.Time) []provider.CodexLimit {
var out []provider.CodexLimit
for _, which := range []string{"primary", "secondary"} {
pre := "x-codex-" + which + "-"
pre := fam + which + "-"
used, err := strconv.ParseFloat(strings.TrimSpace(h.Get(pre+"used-percent")), 64)
if err != nil {
continue
+31 -10
View File
@@ -1312,24 +1312,40 @@ func (s *Server) drawOnAccounts(ctx context.Context, r *http.Request, p provider
// restDrawer rests the image model on c's account when the account is out
// of its quota for it, until the reset the refusal names (Antigravity's
// "Your quota will reset after 3h19m30s.", resetsAt), else quotaRest. Only
// the model rests (restID), never the account: its text models draw on
// allowances of their own. The next drawing then asks the accounts that
// still have it first (restLast in candidates), and a chat on that image
// model goes past it too, where before every drawing asked the spent
// account first again (01huadalang on Discord). A failure of any other
// kind rests nothing, as before: a key, a request refused, a vendor down;
// nor does any on a provider set never to rest for a limit (LimitRestOff).
// "Your quota will reset after 3h19m30s.", resetsAt), or a ChatGPT
// account's image window's as its headers told it (imageHeardOf), else
// quotaRest; a 429 the headers said came with that window full is out of
// quota whatever its words. Only the model rests (restID), never the
// account: its text models draw on allowances of their own. The next
// drawing then asks the accounts that still have it first (restLast in
// candidates), and a chat on that image model goes past it too, where
// before every drawing asked the spent account first again (01huadalang
// on Discord). A failure of any other kind rests nothing, as before: a
// key, a request refused, a vendor down; nor does any on a provider set
// never to rest for a limit (LimitRestOff).
func restDrawer(c candidate, code int, msg string) {
if c.p.Account == nil || c.p.LimitRestOff || c.model == "" || failure(code, []byte(msg)) != failQuota {
if c.p.Account == nil || c.p.LimitRestOff || c.model == "" {
return
}
now := time.Now()
agent, user := c.p.Account.UsageAgent(), c.p.Account.User
// the image window a ChatGPT account's reply told (#6412)
heard, told := imageHeardOf(agent, user, now)
told = told && strings.HasPrefix(c.model, codexDrawerFamily)
if failure(code, []byte(msg)) != failQuota && (code != http.StatusTooManyRequests || !told || heard.Used < 100) {
// a 429 whose words read as a short rate limit ("image limit
// reached") is the allowance's when the headers said it is full
return
}
r := Rest{Why: failQuota, Status: code, By: "quota", Key: c.restID(), Model: c.model,
agent: c.p.Account.UsageAgent(), user: c.p.Account.User, said: msg}
agent: agent, user: user, said: msg}
d := quotaRest
if w := resetsAt([]byte(msg), now); w > 0 {
d, r.By = min(w, longestQuota), "resets"
} else if told {
// a ChatGPT image refusal whose body names no reset: its window's,
// as the reply's headers told it, not quotaRest's guess
d, r.By = min(heard.Resets.Sub(now), longestQuota), "resets"
}
r.Until = now.Add(d)
restingUntil.Lock()
@@ -1499,6 +1515,11 @@ func (s *Server) sendWith(ctx context.Context, p provider.Provider, method, url,
return nil, 502, err
}
defer res.Body.Close()
if drawsCodex(p) {
// the image window a ChatGPT account's reply tells, a 200's too,
// for its card and a refusal's rest (#6412)
heardCodexImage(p, res.Header)
}
answered := time.Since(asked)
rb := &tracked{r: res.Body, last: time.Now()}
b, err := io.ReadAll(io.LimitReader(rb, 256<<20))
+4
View File
@@ -2380,6 +2380,7 @@ const I18N = {
"Droid Core · 30 days": "Droid Core · 30 天",
"Extra usage": "额外用量",
"Used up": "已用完",
"Available": "可用",
"Usage credits": "额外用量额度",
"Gift plans to claim in the ZCode app": "待在 ZCode 客户端领取的赠送额度",
"ZCode gift plans (-Trial models) need ZCode's sign-in": "ZCode 赠送额度(-Trial 模型)需要 ZCode 登录",
@@ -7525,6 +7526,7 @@ const I18N = {
"Droid Core · 30 days": "Droid Core · 30 天",
"Extra usage": "額外用量",
"Used up": "已用完",
"Available": "可用",
"Usage credits": "額外用量額度",
"Gift plans to claim in the ZCode app": "待在 ZCode 用戶端領取的贈送額度",
"ZCode gift plans (-Trial models) need ZCode's sign-in": "ZCode 贈送額度(-Trial 模型)需要 ZCode 登入",
@@ -12646,6 +12648,7 @@ const I18N = {
"Droid Core · 30 days": "Droid Core · 30日",
"Extra usage": "追加使用量",
"Used up": "使い切り",
"Available": "利用可能",
"Usage credits": "追加使用量のクレジット",
"Gift plans to claim in the ZCode app": "ZCode アプリで受け取れるギフト枠",
"ZCode gift plans (-Trial models) need ZCode's sign-in": "ZCode のギフト枠(-Trial モデル)には ZCode でのサインインが必要",
@@ -17798,6 +17801,7 @@ const I18N = {
"Droid Core · 30 days": "Droid Core · 30 Tage",
"Extra usage": "Zusätzliche Nutzung",
"Used up": "Aufgebraucht",
"Available": "Verfügbar",
"Usage credits": "Nutzungsguthaben",
"Gift plans to claim in the ZCode app": "In der ZCode-App abzuholen",
"ZCode gift plans (-Trial models) need ZCode's sign-in": "ZCode-Geschenkpläne (-Trial-Modelle) brauchen die ZCode-Anmeldung",
+8 -6
View File
@@ -18,14 +18,16 @@ const chat = [{ name: "5 hours", used: 40, resetSecs: 3600 }, { name: "7 days",
const quotas = [
{ provider: "codex", name: "Codex", icon: "codex-color", user: "spent@example.com", windows: [...chat, img({ display: "Used up", resetsAt: soon, resetSecs: 10800 })] },
{ provider: "codex", name: "Codex", icon: "codex-color", user: "fresh@example.com", windows: [...chat, img({})] },
// a drawing's 200 told the window's renewal (#6412)
{ provider: "codex", name: "Codex", icon: "codex-color", user: "drew@example.com", windows: [...chat, img({ display: "Available", resetsAt: soon, resetSecs: 10800 })] },
];
const words = {
en: { name: "Image generation", used: "Used up", unknown: "Unknown" },
zh: { name: "生图模型", used: "已用完", unknown: "未知" },
"zh-TW": { name: "生圖模型", used: "已用完", unknown: "未知" },
ja: { name: "画像生成", used: "使い切り", unknown: "不明" },
de: { name: "Bilderzeugung", used: "Aufgebraucht", unknown: "Unbekannt" },
en: { name: "Image generation", used: "Used up", unknown: "Unknown", ok: "Available" },
zh: { name: "生图模型", used: "已用完", unknown: "未知", ok: "可用" },
"zh-TW": { name: "生圖模型", used: "已用完", unknown: "未知", ok: "可用" },
ja: { name: "画像生成", used: "使い切り", unknown: "不明", ok: "利用可能" },
de: { name: "Bilderzeugung", used: "Aufgebraucht", unknown: "Unbekannt", ok: "Verfügbar" },
};
function serve(lang) {
@@ -66,7 +68,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.locator("#subscriptionUsage .quota").first().waitFor();
await page.locator(".quota-more").click();
const w = words[lang];
for (const [user, text, resets] of [["spent@example.com", w.used, true], ["fresh@example.com", w.unknown, false]]) {
for (const [user, text, resets] of [["spent@example.com", w.used, true], ["fresh@example.com", w.unknown, false], ["drew@example.com", w.ok, true]]) {
const mine = page.locator(`[data-card="codex|${user}"] + .quota-windows`);
const row = mine.locator(".quota", { hasText: w.name });
await row.waitFor();
+28 -9
View File
@@ -7,12 +7,14 @@ import (
// ImageLane is the name of a ChatGPT account's image window (QuotaWindow.Lane).
// Drawing with gpt-image-2 counts against an allowance of its own, apart from
// Codex's 5-hour and weekly windows (#6160), and the backend tells no share of
// it: /wham/usage has no image window (additional_rate_limits is null) and a
// reply carries no x-codex-* header for one. What magpie knows is the refusal
// it got, usage_limit_reached with the time it comes back, which the gateway
// keeps as the image model's rest (ImageRest). So the row says that time, or
// "unknown": never a share, which nothing told.
// Codex's 5-hour and weekly windows (#6160). /wham/usage has no image window
// (additional_rate_limits is null), but each reply of the images API tells
// it, a 200's too: x-codex-active-limit names the image limit and its
// window's headers say when it renews (#6412), which the gateway keeps
// (ImageHeard). A refusal, usage_limit_reached, rests the image model until
// the time it names, or that window's renewal (ImageRest). So the row says
// that time, or "unknown": never a share, as the share the headers tell
// stayed 0 on an account that had drawn.
const ImageLane = "images"
// ImageRest is, set by the gateway, when the image model of the ChatGPT
@@ -20,11 +22,17 @@ const ImageLane = "images"
// vendor's refusal keeps it resting; false when it is not.
var ImageRest func(agent, user string, now time.Time) (time.Time, bool)
// ImageHeard is, set by the gateway, the image window the ChatGPT account
// user's last reply of the images API told, while it has not renewed;
// false when none told one.
var ImageHeard func(agent, user string, now time.Time) (CodexLimit, bool)
// WithImageLane is qs with a row for the image allowance added to each
// ChatGPT account's card that was read: Text and Aside, so no share is told
// and routing never reads it, with ResetsAt when a refusal named the time it
// comes back and no time otherwise. A card of another magpie is as it came;
// qs and its windows, which the caches share, are left as they were.
// and routing never reads it, with ResetsAt when a refusal or a reply's
// headers named the time it comes back and no time otherwise. A card of
// another magpie is as it came; qs and its windows, which the caches share,
// are left as they were.
func WithImageLane(qs []SubscriptionQuota, now time.Time) []SubscriptionQuota {
out := make([]SubscriptionQuota, len(qs))
for i, q := range qs {
@@ -39,6 +47,17 @@ func WithImageLane(qs []SubscriptionQuota, now time.Time) []SubscriptionQuota {
}
}
w := QuotaWindow{Name: "Image generation", Lane: ImageLane, Text: true, Aside: true, Display: "Unknown"}
if ImageHeard != nil {
// the window the last drawing's reply told: its renewal, and
// used up when it said so; "Available" while it was not
if l, ok := ImageHeard("codex", strings.ToLower(q.User), now); ok {
until := l.Resets
w.Display, w.ResetsAt, w.ResetSecs = "Available", &until, int64(until.Sub(now)/time.Second)
if l.Used >= 100 {
w.Display = "Used up"
}
}
}
if ImageRest != nil {
if until, ok := ImageRest("codex", strings.ToLower(q.User), now); ok {
w.Display, w.ResetsAt, w.ResetSecs = "Used up", &until, int64(until.Sub(now)/time.Second)