Repository navigation
feat: offer a model's service tiers as a speed in the TUI and desktop - #65749
Conversation
There was a problem hiding this comment.
The change looks sound. I couldn't check the feature itself end to end: the simulated model has no service tiers and there are no provider credentials. The added core, tui and app tests pass, and core and app type-check cleanly; tui shows the same type errors as the base, unrelated to this change. With the flag on, the TUI still works as before against the simulated model. Your recordings cover the speed UI.
Public API: adds an optional experimental.speed (Model.Speed: base, id, faster) to Model.Info in the schema, OpenAPI spec and generated client. It also adds the model_speeds flag and the TUI keybinds speed_list / speed_cycle (no default key), plus a speed map in the TUI's model.json and the app's persisted model state. All of this is additive and backwards compatible. Existing -fast model IDs still resolve.
One thing worth fixing: the date-based price multipliers apply even with the flag off (see the inline comment).
Related: #39864
| Option.getOrUndefined(decodeServiceTier(multiplier.when.service_tier))?.equals === tier, | ||
| )?.factor | ||
| // A tier's multiplier may only hold for some dates (an introductory price); the one for today is used. | ||
| const today = new Date().toISOString().slice(0, 10) |
There was a problem hiding this comment.
This date-aware multiplier lookup isn't behind model_speeds, so release builds change too. Mode prices (e.g. gpt-5.5-fast) now pick up multipliers with a date condition, which were ignored before. The description says nothing changes with the flag off, so either gate it or mention it there.
Also, today is read once when the catalog is normalized, and the result is cached with an infinite TTL. A long-running server keeps showing an introductory price after it ends, until the next catalog refresh.
There was a problem hiding this comment.
Keeping the dated lookup ungated: it is a price fix, and the description now says so. Leaving the date read once per catalog load: it only affects the displayed price, and the catalog refresh picks up the new day's price the next time the catalog changes.
There was a problem hiding this comment.
Keeping the multiplier ungated works for me, since the description now covers it. The other half rests on two premises that the code doesn't support.
- It affects more than the displayed price.
SessionUsage.record(usage, model.cost)usesmodel.costto compute the cost it records for a step whenever the provider doesn't report one (session/usage.ts:49). It's called fromsession/runner/step.ts:301,generate.ts:74,title.ts:93andcompaction.ts:567. After an introductory window ends, a stale catalog keeps writing the old price into each session's saved cost and intostats. - The next day's price doesn't load on a schedule.
refresh()checks every 5 minutes, but it only invalidates the catalog caches when the body's digest changes (models-dev.ts:831-838). An unchanged catalog keeps the price normalized when it was loaded. A server running from the bundled snapshot has a second problem:bundledCache(:663) is a module-level cache that is never invalidated, so it keeps that price until the process restarts.
In practice this probably matters little, because models.dev changes often and a price window rarely ends while a server is running. If you're fine with that, leave it. If not, the smallest fix is to invalidate the caches in refresh() when the date has changed since the last normalize, even if the body hasn't:
let day = new Date().toISOString().slice(0, 10)
// in refresh(), before the digest early-return:
const today = new Date().toISOString().slice(0, 10)
const dayChanged = today !== day
day = today
if (dayChanged) yield* Effect.forEach(caches, ([, invalidate]) => invalidate, { discard: true })That doesn't cover bundledCache. It would also need the day in its key, or to skip caching for dated multipliers.
I read the cache and refresh code and the callers of model.cost, but didn't run anything. I made no changes to the checkout; the bun.lock modification there isn't mine.
There was a problem hiding this comment.
You're right on both, and my wording was off: the catalog price also goes into the cost saved for a step when the provider reports none, and the price only reloads when the catalog body changes. Leaving it for now: it needs a server running across the day an introductory price ends with no catalog change in between, and today that is five ultrafast entries on 1 March 2027. If dated prices become common, the day-change invalidation you suggest is the fix.
There was a problem hiding this comment.
That's reasonable. Leaving it as is and noting the fix for later is fine.
Your date checks out against the bundled snapshot (packages/core/src/models-dev/snapshot.txt). Its only dated multipliers tied to a service tier are ultrafast with date: { lt: "2027-03-01" }, which flips on 1 March 2027. The snapshot also has 26 date-only multipliers (gte 2026-12-01, 2027-01-01 and 2027-02-01), but modeCost (models-dev.ts:492-494) skips them because they have no service_tier. So nothing changes on the earlier dates.
I found seven lt entries rather than five. The extra two are probably the same models repeated in the OpenAI subscription lists, which doesn't change your conclusion. I didn't map them to providers.
I only read code and grepped the snapshot. I made no changes to the checkout.
There was a problem hiding this comment.
The new commits only tidy code: formatting, the orderedSpeeds rewrite and the simpler speed pass-through. Behaviour is the same; the app's speed and model-label tests pass and the app type-checks cleanly.
On the earlier thread about the price multipliers: the description now says the date-based price fix applies with the flag off too, which covers the first half. today is still read once and the result cached with an infinite TTL, so I've left that thread open.
Public API is unchanged since the last review.
Offers a model's service tiers (fast, flex, ultrafast…) as a speed of that model, instead of a separate picker entry per tier such as
gpt-5.5-fast.capabilities.service_tier) becomes a model of its own (gpt-5.5-fast), linked to its base model throughexperimental.speed. Sessions and messages store nothing new, and typing or sending a-fastmodel ID works as before. Modes from the catalog only add what the tiers don't cover, such as OpenAI'spro./speedlists the model's speeds with their price. The model picker lists the model once, and the prompt shows the speed after the variant. There arespeed.listandspeed.cyclekeybinds, with no default key./speedmoves to the next speed.Flag:
model_speeds, on in local and dev builds and off in releases. With it off there are no tier models, no/speedand the same picker.One price fix applies with the flag off too: a mode without its own price now uses a tier multiplier that only holds for some dates (an introductory price). Today that is the
ultrafastmode of GPT-6.2 Sol and Astra on OpenAI and of GPT-6.2 Astra on Bedrock, which showed the standard price and now show 3×.How I verified it
bun run checkpasses, and so do the tests ofcore,tui,app,session-uiandschema. Three shell-scan tests incorefail on my machine's bash; they don't touch this change.gpt-6.1-sol-fast, and the timeline shows "Switched speed to fast". Recordings below.flex_unavailablefrom the provider, which is its own capacity answer to a flex request, so the recordings use Fast.TUI
Desktop
Recordings
TUI first, then desktop.
tui-after.mp4
web-after.webm
Added by the opencode bot (AI-generated).
Related: #39864
Public API: adds optional Model.Info.experimental.speed, the model_speeds flag and the speed.list/speed.cycle keybinds (backwards compatible)