@paiven_x on X: a Codex session (gpt-6.1-terra) of a few hundred small
screenshots sent ~42 MB a request, and the context map showed 764K
tokens, 413K of them images, while Codex's own count was about 371K.
Every inline image was taken at a flat 1600 tokens (imageTokens), so
~258 small screenshots read as 413K where OpenAI counts an 800x500
one at 480.
Now an image's width and height are read from its header alone
(image.DecodeConfig over a streaming base64 decoder: a few KB of a PNG,
a JPEG up to its frame header, a lean body's imageRef through
keptImageOf), and counted by the rule of the protocol's vendor
(prompt_image.go):
- Anthropic: 28 px patches, ceil(w/28)*ceil(h/28), after the reference
resizedSize; 2576 px / 4784 tokens for Claude 4.7 and later, 1568 /
1568 before.
- OpenAI patch models (GPT-5.2 and after, the minis): 32 px patches
times the model's multiplier, in the side and patch budget each
detail sets (low/high/original/auto per model, as the vision guide
lists them).
- OpenAI tile models (gpt-4o, gpt-4.1, o1/o3, gpt-5/5.1): base plus
512 px tiles after 2048 and 768 fitting; low is the base.
A link, a file, a document, an unreadable image and a Gemini request
stay at 1600; the vendor's count still scales them all (calibrate).
The 475K Codex never reached is Codex's own: 95% (its
effective_context_window_percent) of the 500K its bundled catalog gives
gpt-6.1-terra. magpie writes no auto_compact_token_limit for Terra
unless the user set one (Working keeps its own 500K). Codex compares
the usage the vendor reported (~381K), which was under it, so nothing
compacted until /compact. No workaround added.
Tests: TestPromptImageTokensByVendor builds real PNG and JPEG bytes
(image/png, image/jpeg Encode) and checks each vendor's own doc
numbers: Terra 800x500 auto 480, 2880x1800 high 2949, gpt-5.5 low 192,
gpt-4o 1024x1024 high 765 and low 85, Claude 1920x1080 2691 (high
tier) and 1560 (Sonnet 4.5), 3840x2160 4784, a JPEG behind a 40 KB
APP1 330, \/-escaped base64 480. TestPromptImageSizeReadsHeaderOnly
reads 2880x1800 from the first 4 KB of the base64 and falls back to
1600 for a link, a file and undecodable bytes.
Broken by hand: imageTokensOf replaced by the constant, all 10 cases
of TestPromptImageTokensByVendor red at 1600.
Run at this head (e67b0f4fa, rebased on origin/main 352b124b3): gofmt -l
clean; GOOS=linux go vet -tags nogui ./... and GOOS=windows go vet ./... ok
(mica); go test -count=1 -timeout 45m ./... on mote: every package ok except
internal/gateway, whose only --- FAIL is
TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes, red on origin/main without
this change (#7117). A recovered "close of closed channel" from doneHold.serve
(continuation_test.go:781) is in the log, filed as #6690 and #6505; it fails
no test. TestCoreScriptBudget is in that run (no GUI file changed).
Not tried: a real Codex session with hundreds of screenshots; the counts are
checked against OpenAI's and Anthropic's documented examples only.