Skip to content

feat: offer a model's service tiers as a speed in the TUI and desktop - #65749

Merged
vimtor merged 2 commits into
devfrom
speed-selector
Nov 23, 2026
Merged

vimtor merged 2 commits into
devfrom
speed-selector

Conversation

@vimtor

@vimtor vimtor commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

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.

  • Core: each tier a model lists in the catalog (capabilities.service_tier) becomes a model of its own (gpt-5.5-fast), linked to its base model through experimental.speed. Sessions and messages store nothing new, and typing or sending a -fast model ID works as before. Modes from the catalog only add what the tiers don't cover, such as OpenAI's pro.
  • TUI: /speed lists the model's speeds with their price. The model picker lists the model once, and the prompt shows the speed after the variant. There are speed.list and speed.cycle keybinds, with no default key.
  • Desktop: a speed dropdown next to the variant, hidden at the standard speed. /speed moves to the next speed.
  • The speed is remembered per model, and a model's speeds are offered only while the model itself is enabled.

Flag: model_speeds, on in local and dev builds and off in releases. With it off there are no tier models, no /speed and 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 ultrafast mode 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 check passes, and so do the tests of core, tui, app, session-ui and schema. Three shell-scan tests in core fail on my machine's bash; they don't touch this change.
  • Ran the TUI and the web app from this branch against OpenCode Zen with GPT-6.1 Sol: Fast is sent and saved as gpt-6.1-sol-fast, and the timeline shows "Switched speed to fast". Recordings below.
  • One Flex request during recording came back as flex_unavailable from the provider, which is its own capacity answer to a flex request, so the recordings use Fast.

TUI

The speed list in the TUI, with the price of each speed

A reply at the fast speed, with the speed shown after the variant in the prompt

Desktop

The model picker lists GPT-6.1 Sol once

The speed dropdown next to the variant

The timeline notes the speed switch

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)

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) uses model.cost to compute the cost it records for a step whenever the provider doesn't report one (session/usage.ts:49). It's called from session/runner/step.ts:301, generate.ts:74, title.ts:93 and compaction.ts:567. After an introductory window ends, a stale catalog keeps writing the old price into each session's saved cost and into stats.
  • 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@vimtor
vimtor merged commit 7edab78 into dev Nov 23, 2026
21 of 22 checks passed
@vimtor
vimtor deleted the speed-selector branch November 23, 2026 09:13
@opencodejr opencodejr Bot mentioned this pull request Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant