Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(site): show best-effort model pricing on the model form - #28290

Merged
DanielleMaywood merged 5 commits into
mainfrom
feat/models-page-pricing-estimate
Aug 19, 2026
Merged

feat(site): show best-effort model pricing on the model form#28290
DanielleMaywood merged 5 commits into
mainfrom
feat/models-page-pricing-estimate

Conversation

@DanielleMaywood

Copy link
Copy Markdown
Contributor

Adds a read-only "Cost estimate" section to the Coder Agents model form (AI Settings > Models > add/edit). It revives the per-token pricing layout removed in #27330, but the fields are immutable and populated rather than editable.

Prices come from the live GET /api/experimental/ai/model-prices price book when the AI Gateway feature is entitled, so admin price overrides are reflected. Otherwise they fall back to the models.dev catalog already bundled for the model identifier autocomplete. A price book row wins outright, a null category means the model bills as zero there, and the catalog only fills in when the model has no row at all. Models with no price data get an empty state instead of a blank box.

No backend changes. The model-prices endpoint is enterprise-gated, so unlicensed deployments never call it and see catalog prices, which are always accurate there since overrides cannot exist.

Implementation plan and review notes

Data sources

  • Live: GET /api/experimental/ai/model-prices (?provider=&model=, exact match, micro-units per million tokens). Used only when useFeatureVisibility().aibridge.
  • Fallback: knownModels/knownModelsGenerated.json, the static models.dev catalog the autocomplete already loads. Its KnownModel type carries inputCost, outputCost, cacheReadCost, cacheWriteCost.

Key decisions

  • Row-level precedence over per-field merge. The cost engine (coderd/aibridgedserver/cost.go) treats a null price on a present row as "bills as zero", so a row is the deployment's deliberate pricing for that model and the catalog must not fill its null categories.
  • The query is gated on Boolean(useFeatureVisibility().aibridge). aibridge is undefined (not false) when unlicensed, and TanStack only disables when enabled === false, so without the Boolean() the not-entitled path would still fire a doomed request.
  • Model id is trimmed and debounced (300ms) since it is a free-text field in edit and duplicate modes.
  • readOnly without disabled so screen readers still announce the values.
  • formatPricePerMillionTokens keeps two decimals for cents ($0.10) and up to four for sub-cent prices ($0.075, $0.0036) so small prices are not rounded to $0.00.

Self-review

Three reviewers (GLM 5.3, Kimi K3, Qwen 3.8 Max) plus an FE1 to FE10 audit. Fixed: sub-cent rounding to $0.00, the entitlement gate leak, per-field to row-level precedence, per-keystroke requests, empty state, and a vacuous not-entitled test that now asserts the endpoint is not called. 25 story tests and 24 unit tests pass, typecheck and lint clean.

@DanielleMaywood

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: da823a4f1d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Show a loading placeholder in each cost estimate box while the live
price-book query is in flight, and only fall back to the baked-in catalog
after a successful response confirms no row exists.
@DanielleMaywood

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c2a41becc5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Show a load failure message in the cost estimate section instead of
falling back to the catalog when the price book request errors, and
render positive prices below four decimals as a threshold rather than
$0.00 so they are not read as free.
@DanielleMaywood

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 997dac6fc1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@DanielleMaywood

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 997dac6fc1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@DanielleMaywood
DanielleMaywood marked this pull request as ready for review August 19, 2026 10:06
@coderagents

coderagents Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Documentation Check

Updates Needed

  • docs/ai-coder/agents/models.md - Document the new read-only Cost estimate section on the model add/edit form (AI Settings > Models). The page documents this form in detail (### Add a model and ## Model options) but has no mention of the new collapsible that shows per-token pricing. Worth noting: prices are read-only, shown per million tokens in USD; they come from the live price book when the AI Gateway feature is entitled (reflecting admin overrides) and fall back to the bundled models.dev catalog otherwise; and models with no price data show a "No pricing data for this model" empty state.

Automated review via Coder Agents

@johnstcn johnstcn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @DanielleMaywood!

Potential follow-up: do we need a premium license banner in case of lack of license entitlement?

@DanielleMaywood

Copy link
Copy Markdown
Contributor Author

Potential follow-up: do we need a premium license banner in case of lack of license entitlement?

Unsure. It does gracefully fall back to the models.dev pricing list that is embedded in the frontend if you don't have a premium license.

@DanielleMaywood
DanielleMaywood merged commit 8405bbb into main Aug 19, 2026
30 of 31 checks passed
@DanielleMaywood
DanielleMaywood deleted the feat/models-page-pricing-estimate branch August 19, 2026 10:45
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 19, 2026

@ssncferreira ssncferreira 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.

I think there is a different behaviour here when I'm adding a new model vs when I'm editing an existing model. When I'm adding a new model, the API call only happens once I click somewhere outside the model identifier textbox, however, when I'm editing an existing model, the API call happens whenever I update the model identifier textbox (each new character results in an API call). Is this expected? 🤔

expect(formatPricePerMillionTokens(0.0001)).toBe("$0.0001");
});

it("formats zero", () => {

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.

nit: should we also add a test that if a price is null it shows as empty?

const cost = costs?.[key];
const fieldId = `${fieldIdPrefix}-${label.toLowerCase().replace(/\s+/g, "-")}`;
const displayValue =
cost === undefined ? "" : formatPricePerMillionTokens(cost).slice(1);

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.

I think this is slicing the < for the case formatPricePerMillionTokens returns a value lower than < 0.0001

Image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants