gateway: Automatic draws with the newest GPT Image, and a ChatGPT account's shows as GPT Image (StarBits on X)

StarBits asked on X whether magpie draws with OpenAI's newest image model,
as the editor showed "gpt-image-2".

- AutoDrawer took the cheapest priced model. An OpenAI key lists
  gpt-image-2.5/2.6 with no price (models.dev prices gpt-image-2 only), so
  Automatic kept an older GPT Image. Now a GPT Image that a newer one set
  up supersedes is never picked (gptImageGenOf: version, then
  base/Sunburst > Flare > mini; dall-e and chatgpt-image-latest under all),
  and an unpriced one is costed as the newest priced one. Another kind of
  model that costs less still wins.
- A ChatGPT (Codex) account's backend ignores the model name (#1865;
  re-checked today with a real account: gpt-image-2, 2.6-sunburst,
  2.5-flare and a bogus id all drew the same 1536x1024 image), so it is
  never superseded, and its chip now reads its name "GPT Image" with the
  id as tooltip (/api/providers drawNames). Unticking still saves the id.
- docs/subsystems/gateway-routing.md says both.

Run (on mote, at this tree):
- go test -tags nogui -run 'AutoDrawer|GPTImageGen|Codex.*Image|ImageGen|Drawer|Draw'
  ./internal/gateway ./internal/gui: ok
- GUI: chatgpt-image-chip (new), image-models-hide, video-models-hide,
  group-pick-drawers, chromium + webkit, en/zh/zh-TW/ja/de, 1000 and
  360px: 100 pass, 0 fail
- gofmt -l: clean
- Full go test ./... -timeout 45m and Linux/Windows vet: running; record
  follows in the next commit or a comment.

Broken by hand: without the supersede filter TestAutoDrawerTakesNewestGPTImage
picks oa/dall-e-3; without the ChatGPT exclusion TestAutoDrawerKeepsChatGPTsOwnPick
picks oa/gpt-image-2.6-sunburst; with the chip label reverted the GUI test
is red.

Not tried: a real OpenAI key's live model list in the app.
This commit is contained in:
yetone
2026-11-05 19:56:08 +08:00
parent 8c733bb362
commit 2d6939ec64
7 changed files with 336 additions and 10 deletions
+18
View File
@@ -2093,6 +2093,24 @@ pick stays listed as picked, and `imageGenHidden` puts a line under the
row that it is unticked and leaves the list once another is picked.
Refusing a model outright is Disabled models, below.
The editor shows each image model by its name where it has one
(`drawNames`), with the id as the chip's tooltip: a ChatGPT account's
`gpt-image-2`, the id Codex CLI asks for, is its one GPT Image, since its
backend draws with the model it picks whichever is named (#1865; StarBits
on X read the id as an old model). Unticking it still saves the id.
`AutoDrawer` never picks a GPT Image that a newer one set up supersedes
(`gptImageGenOf`: by version, gpt-image-2.6 over 2.5 over 2, unversioned
dall-e and chatgpt-image-latest under them all; then the base or Sunburst
over Flare over mini). An OpenAI key's list names 2.5 and 2.6 with no
price while models.dev prices gpt-image-2, so cost alone took the old one.
A GPT Image with no price is costed as the newest priced one, as OpenAI
prices them alike. A ChatGPT account's GPT Image is never superseded, as
its name says nothing of what draws, so the plan's images stay Automatic's
choice. Another kind of model that costs less is still the cheaper choice.
`TestAutoDrawerTakesNewestGPTImage`, `TestAutoDrawerKeepsChatGPTsOwnPick`,
`chatgpt-image-chip.test.cjs`.
Video models are listed the same way, under Video models (axelburks on
Discord: an Ark key's Seedance had nowhere to be ticked). The editor's
`filmIds` are `gateway.VideomakersOf` the listing it already has, and an
+83 -7
View File
@@ -467,9 +467,21 @@ func kindModel(p provider.Provider, id string) catalog.Model {
// AutoDrawer is the model magpie draws with when the Settings name none:
// a ChatGPT account's, which its plan pays for, else the cheapest of the
// models the API keys set up can draw with, the newest of those whose price
// isn't known. "" when none can.
// isn't known. A GPT Image that a newer one set up supersedes is never its
// choice (StarBits on X): an OpenAI key lists gpt-image-2.6-sunburst with no
// price, so cost alone left Automatic on the priced gpt-image-2. A GPT Image
// with no price is costed as the newest priced one, as OpenAI has priced each
// alike (gpt-image-2 to 2.6: $5 in, $30 out). "" when none can.
func AutoDrawer() string {
best, bestCost, bestDate := "", 0.0, ""
type cand struct {
ref, released string
cost float64
priced, gen bool
key gptImageGen
}
var cands []cand
newest, newestPriced := gptImageGen{}, gptImageGen{}
familyCost, haveFamilyCost := 0.0, false
for _, p := range provider.All() {
if !p.On() || p.DecideOnly() || drawsWorkBuddy(p) {
// WorkBuddy's images cost the plan's credits: it draws only
@@ -483,21 +495,85 @@ func AutoDrawer() string {
// refused the others (chatgpt.com: 403, #545)
continue
}
cost := 1e9
c := cand{ref: p.ID + "/" + m.ID, released: m.Released, cost: 1e9}
switch {
case drawsCodex(p), drawsGrok(p):
cost = 0 // a ChatGPT or Grok plan's images come with it
c.cost, c.priced = 0, true // a ChatGPT or Grok plan's images come with it
case m.Price != nil:
cost = m.Price.Input + m.Price.Output
c.cost, c.priced = m.Price.Input+m.Price.Output, true
}
if best == "" || cost < bestCost || cost == bestCost && m.Released > bestDate {
best, bestCost, bestDate = p.ID+"/"+m.ID, cost, m.Released
// a ChatGPT account's name says nothing of the model its
// backend draws with (#1865), so it is never one superseded
if k, ok := gptImageGenOf(m.ID); ok && !drawsCodex(p) {
c.gen, c.key = true, k
if newest.less(k) {
newest = k
}
if c.priced && (!haveFamilyCost || newestPriced.less(k)) {
newestPriced, familyCost, haveFamilyCost = k, c.cost, true
}
}
cands = append(cands, c)
}
}
best, bestCost, bestDate := "", 0.0, ""
for _, c := range cands {
if c.gen && c.key.less(newest) {
continue
}
if c.gen && !c.priced && haveFamilyCost {
c.cost = familyCost
}
if best == "" || c.cost < bestCost || c.cost == bestCost && c.released > bestDate {
best, bestCost, bestDate = c.ref, c.cost, c.released
}
}
return best
}
// gptImageGen orders OpenAI's image models: by version (gpt-image-2.6 over
// 2.5 over 2 over 1.5; dall-e and chatgpt-image-latest, unversioned, under
// every gpt-image), then by variant (the base or Sunburst, the most capable,
// over Flare over mini). A dated snapshot is its model's version.
type gptImageGen struct {
version float64
variant int
}
func (g gptImageGen) less(o gptImageGen) bool {
return g.version < o.version || g.version == o.version && g.variant < o.variant
}
// gptImageGenOf is id's place among OpenAI's image models, a namespace
// (openai/gpt-image-2) aside; false for any other model.
func gptImageGenOf(id string) (gptImageGen, bool) {
id = strings.ToLower(id[strings.LastIndexByte(id, '/')+1:])
g := gptImageGen{variant: 2}
switch {
case strings.Contains(id, "mini"):
g.variant = 0
case strings.Contains(id, "flare"):
g.variant = 1
}
rest, ok := strings.CutPrefix(id, "gpt-image-")
if !ok {
if strings.HasPrefix(id, "dall-e") || strings.HasPrefix(id, "chatgpt-image") {
return gptImageGen{}, true
}
return gptImageGen{}, false
}
n := 0
for n < len(rest) && (rest[n] >= '0' && rest[n] <= '9' || rest[n] == '.') {
n++
}
v, err := strconv.ParseFloat(rest[:n], 64)
if err != nil {
return gptImageGen{}, false
}
g.version = v
return g, true
}
// picture is an image sent along to draw from, or one drawn.
type picture struct {
Mime string
+99
View File
@@ -0,0 +1,99 @@
package gateway
import (
"testing"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/provider"
)
// StarBits on X: Automatic draws with the newest GPT Image a key sets up.
// An OpenAI key's list names gpt-image-2.5 and 2.6 with no price, while
// models.dev prices gpt-image-2 and older; by cost alone Automatic took the
// cheapest old one.
func TestAutoDrawerTakesNewestGPTImage(t *testing.T) {
fresh(t)
priced := func(in, out float64) *catalog.Price { return &catalog.Price{Input: in, Output: out} }
p := provider.Provider{ID: "oa", Name: "OpenAI", Chat: "http://127.0.0.1:9/v1", Key: "key"}
if err := provider.Save(p); err != nil {
t.Fatal(err)
}
save := func(ms ...catalog.Model) {
t.Helper()
for i := range ms {
ms[i].Draws = true
}
if err := catalog.SaveLive("oa", p.Chat, ms); err != nil {
t.Fatal(err)
}
}
save(
catalog.Model{ID: "dall-e-3", Price: priced(1, 1)},
catalog.Model{ID: "gpt-image-1-mini", Price: priced(2, 8), Released: "2025-09-26"},
catalog.Model{ID: "chatgpt-image-latest", Released: "2025-12-16"},
catalog.Model{ID: "gpt-image-2", Price: priced(5, 30), Released: "2026-04-21"},
catalog.Model{ID: "gpt-image-2.5-flare"},
catalog.Model{ID: "gpt-image-2.6-flare"},
catalog.Model{ID: "gpt-image-2.6-sunburst"},
catalog.Model{ID: "gpt-image-2.5-sunburst-2026-09-08"},
)
if a := AutoDrawer(); a != "oa/gpt-image-2.6-sunburst" {
t.Fatalf("automatic draws with %q, want oa/gpt-image-2.6-sunburst", a)
}
// unticked in its editor, the newest left is taken
p.HiddenDrawers = []string{"gpt-image-2.6-sunburst", "gpt-image-2.6-flare"}
if err := provider.Save(p); err != nil {
t.Fatal(err)
}
if a := AutoDrawer(); a != "oa/gpt-image-2.5-sunburst-2026-09-08" {
t.Fatalf("with 2.6 unticked automatic draws with %q", a)
}
p.HiddenDrawers = nil
if err := provider.Save(p); err != nil {
t.Fatal(err)
}
// another kind of model, cheaper, is still the cheaper choice
if err := provider.Save(provider.Provider{ID: "fx", Name: "Flux", Chat: "http://127.0.0.1:9/v1", Key: "key"}); err != nil {
t.Fatal(err)
}
if err := catalog.SaveLive("fx", "http://127.0.0.1:9/v1", []catalog.Model{{ID: "flux-schnell", Draws: true, Price: priced(1, 2)}}); err != nil {
t.Fatal(err)
}
if a := AutoDrawer(); a != "fx/flux-schnell" {
t.Fatalf("automatic draws with %q, want the cheaper fx/flux-schnell", a)
}
}
// A ChatGPT account's one GPT Image is named gpt-image-2, as Codex CLI asks
// for it, but its backend picks the model itself (#1865): a key's newer GPT
// Image doesn't supersede it, and the plan's images stay Automatic's choice.
func TestAutoDrawerKeepsChatGPTsOwnPick(t *testing.T) {
codexSignedIn(t)
if err := provider.Save(provider.Provider{ID: "oa", Name: "OpenAI", Chat: "http://127.0.0.1:9/v1", Key: "key"}); err != nil {
t.Fatal(err)
}
if err := catalog.SaveLive("oa", "http://127.0.0.1:9/v1", []catalog.Model{{ID: "gpt-image-2.6-sunburst", Draws: true}}); err != nil {
t.Fatal(err)
}
if a := AutoDrawer(); a != "codex/"+codexDrawer {
t.Fatalf("automatic draws with %q, want the ChatGPT plan's", a)
}
}
func TestGPTImageGenOrder(t *testing.T) {
order := []string{"dall-e-3", "gpt-image-1-mini", "gpt-image-1", "gpt-image-1.5", "gpt-image-2", "gpt-image-2.5-flare", "openai/gpt-image-2.5-sunburst", "gpt-image-2.6-flare", "gpt-image-2.6-sunburst-2026-10-01"}
for i := 1; i < len(order); i++ {
a, ok1 := gptImageGenOf(order[i-1])
b, ok2 := gptImageGenOf(order[i])
if !ok1 || !ok2 || !a.less(b) {
t.Errorf("%s (%v) should come before %s (%v)", order[i-1], a, order[i], b)
}
}
for _, id := range []string{"flux-schnell", "grok-imagine-image", "gemini-3.1-flash-image"} {
if _, ok := gptImageGenOf(id); ok {
t.Errorf("%s taken for a GPT Image", id)
}
}
}
+6 -3
View File
@@ -11992,7 +11992,7 @@ function renderModels(p) {
}
function renderDrawers(p) {
return field(t("Image models"), mediaChips("mchips drawers", p.drawIds, "hiddenDrawers", p), p.drawPicks ? t("ChatGPT's image backend picks the model itself, whichever is named, so one GPT Image is listed") : t("Settings → Images lists the ticked ones. Agents don't chat with these, so they aren't among its models."));
return field(t("Image models"), mediaChips("mchips drawers", p.drawIds, "hiddenDrawers", p, p.drawNames), p.drawPicks ? t("ChatGPT's image backend picks the model itself, whichever is named, so one GPT Image is listed") : t("Settings → Images lists the ticked ones. Agents don't chat with these, so they aren't among its models."));
}
// renderVideomakers: its video models, ticked to be offered (axelburks on Discord)
@@ -12000,13 +12000,16 @@ function renderVideomakers(p) {
return field(t("Video models"), mediaChips("mchips videomakers", p.filmIds, "hiddenVideomakers", p), t("Only the ticked ones are offered when making a video. Agents don't chat with these, so they aren't among its models."));
}
function mediaChips(cls, ids, key, p) {
// names: the name a chip shows for an id that has one (a ChatGPT account's
// gpt-image-2 is its GPT Image); the id is then its tooltip
function mediaChips(cls, ids, key, p, names) {
const chips = el("div", cls);
draft[key] ||= [...(p[key] || [])];
for (const id of ids) {
const c = el("button", "mchip pick");
c.type = "button";
c.append(el("span", "", id));
c.append(el("span", "", names?.[id] || id));
if (names?.[id]) c.title = id;
const show = () => { const on = !draft[key].includes(id); c.classList.toggle("on", on); c.setAttribute("aria-pressed", on); };
c.onclick = () => {
draft[key] = draft[key].includes(id) ? draft[key].filter((x) => x !== id) : [...draft[key], id];
+3
View File
@@ -69,5 +69,8 @@ func TestImageGenCodexOneEntry(t *testing.T) {
}
if j := providerInfo(*p, nil); !j.DrawPicks || len(j.DrawIDs) != 1 {
t.Fatalf("editor's drawIds %v, drawPicks %v", j.DrawIDs, j.DrawPicks)
} else if j.DrawNames[j.DrawIDs[0]] != "GPT Image" {
// StarBits on X read the chip's gpt-image-2 as an old model
t.Fatalf("editor shows %q by %v", j.DrawIDs[0], j.DrawNames)
}
}
+10
View File
@@ -301,6 +301,10 @@ type providerJSON struct {
Exposed int `json:"exposed"` // how many reach the agents
Draws int `json:"draws,omitempty"` // how many of its models draw images (gateway.Drawers)
DrawIDs []string `json:"drawIds,omitempty"` // those models' ids, listed apart in its editor
// the names those are shown by where one isn't its id: a ChatGPT
// account's gpt-image-2 is its one GPT Image, whichever model its
// backend draws with (StarBits on X read the id as an old model)
DrawNames map[string]string `json:"drawNames,omitempty"`
// its vendor draws with the model it picks, whichever is named: a
// ChatGPT account's one GPT Image (gateway.VendorPicksDrawer)
DrawPicks bool `json:"drawPicks,omitempty"`
@@ -1024,6 +1028,12 @@ func providerInfoWith(p provider.Provider, ls provider.Listing, agents []agentUs
// lists them apart, as Settings → Images is where one is picked
for _, m := range gateway.DrawersOf(p, func() []catalog.Model { return ls.Available }) {
out.DrawIDs = append(out.DrawIDs, m.ID)
if m.Name != "" && m.Name != m.ID {
if out.DrawNames == nil {
out.DrawNames = map[string]string{}
}
out.DrawNames[m.ID] = m.Name
}
}
out.Draws = len(out.DrawIDs)
out.DrawPicks = out.Draws > 0 && gateway.VendorPicksDrawer(p)
@@ -0,0 +1,117 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// StarBits on X: a ChatGPT (Codex) account's editor showed its one image
// model as "gpt-image-2", read as an old model, while its backend draws
// with the model ChatGPT picks whichever is named (#1865). The chip shows
// the model's name, GPT Image, with the id as its tooltip, and unticking
// it still saves the id. A key's image model with no name of its own
// shows its id. Every language, wide and at a phone's width; the API is
// faked here.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const assets = path.resolve(__dirname, "../assets");
const fetched = new Date(Date.now() - 3600e3).toISOString();
function codex(hidden) {
return {
id: "codex", name: "Codex", icon: "codex-color", host: "", chat: "", responses: "https://chatgpt.com/backend-api/codex", anthropic: "", catalog: "",
models: [{ id: "gpt-6-astra", name: "GPT-6-Astra", on: true }], chosen: [], fetched, agents: [], fallback: [], headers: {},
key: { set: false, masked: "", optional: true }, keyList: [], balanceToken: { takes: false, set: false }, proxy: "", ready: true,
draws: 1, drawIds: ["gpt-image-2"], drawNames: { "gpt-image-2": "GPT Image" }, drawPicks: true, hiddenDrawers: hidden,
};
}
function openai() {
return {
id: "openai", name: "OpenAI", icon: "openai", host: "", chat: "https://api.openai.com/v1", responses: "", anthropic: "", catalog: "",
models: [{ id: "gpt-6", name: "GPT-6", on: true }], chosen: [], fetched, agents: [], fallback: [], headers: {},
key: { set: true, masked: "sk-…one", optional: false }, keyList: [], balanceToken: { takes: false, set: false }, proxy: "", ready: true,
draws: 2, drawIds: ["gpt-image-2.6-sunburst", "gpt-image-2"], drawNames: { "gpt-image-2.6-sunburst": "GPT Image 2.6 Sunburst" }, hiddenDrawers: [],
};
}
function serve(lang, saves) {
let hidden = [];
const providers = () => ({ providers: [codex(hidden), openai()], presets: [], excluded: [], gateway: { running: true, window: true }, plugins: [] });
return async (route) => {
const req = route.request(), url = new URL(req.url());
const json = (data) => route.fulfill({ json: data });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true,textSize:100};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light", textSize: 100 } });
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/providers") return json(providers());
if (url.pathname === "/api/provider/save") {
const body = req.postDataJSON();
saves.push(body.hiddenDrawers);
if (body.hiddenDrawers) hidden = body.hiddenDrawers;
return json(providers());
}
if (url.pathname === "/api/usage/quotas") return json([]);
if (url.pathname === "/api/groups") return json({ groups: [], pools: [], models: [] });
if (url.pathname === "/api/gateway/trace") return json({ routes: [] });
if (url.pathname === "/api/window/fit") return route.fulfill({ status: 204 });
if (url.pathname.startsWith("/api/")) return json({});
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
const body = await fs.readFile(file).catch(() => null);
await (body ? route.fulfill({ body, contentType }) : route.fulfill({ status: 404, body: "" }));
};
}
const words = {
en: { save: "Save", hint: /ChatGPT's image backend picks the model itself/ },
zh: { save: "保存", hint: /ChatGPT 的生图后端自己决定用哪个模型/ },
"zh-TW": { save: "儲存", hint: /ChatGPT 的生圖後端自己決定用哪個模型/ },
ja: { save: "保存", hint: /ChatGPT の画像生成バックエンドは/ },
de: { save: "Speichern", hint: /Das Bild-Backend von ChatGPT wählt das Modell selbst/ },
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": a ChatGPT account's image model shows as GPT Image", async (t) => {
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
for (const lang of Object.keys(words)) {
const w = words[lang];
for (const width of [1000, 360]) {
await t.test(`${lang} at ${width}px`, async () => {
const saves = [];
const page = await (await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" })).newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang, saves));
await page.goto("http://magpie.test/?view=providers");
const editor = page.locator("#modal:not([hidden]) .editor");
const chips = editor.locator(".mchips.drawers .mchip");
const texts = () => chips.evaluateAll((cs) => cs.map((c) => [c.textContent, c.title]));
const open = async (name) => {
await page.locator(".row.provider", { hasText: name }).first().click();
await chips.first().waitFor();
};
await open("Codex");
await editor.getByText(w.hint).waitFor();
assert.deepEqual(await texts(), [["GPT Image", "gpt-image-2"]]);
assert.equal(await editor.getByText("gpt-image-2", { exact: true }).count(), 0, "the id isn't shown");
await chips.first().click();
assert.equal(await chips.first().getAttribute("aria-pressed"), "false");
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth), 0);
await editor.getByRole("button", { name: w.save, exact: true }).click();
await editor.waitFor({ state: "detached" });
assert.deepEqual(saves.at(-1), ["gpt-image-2"], "unticking saves the id");
await open("OpenAI");
assert.deepEqual(await texts(), [["GPT Image 2.6 Sunburst", "gpt-image-2.6-sunburst"], ["gpt-image-2", ""]]);
assert.deepEqual(errors, []);
await page.context().close();
});
}
}
});
}