feat: remove native chat cost tracking in favor of AI Gateway cost data by ibetitsmike · Pull Request #27330 · coder/coder · GitHub
Skip to content

feat: remove native chat cost tracking in favor of AI Gateway cost data - #27330

Merged
ibetitsmike merged 9 commits into
mainfrom
mike/chat-cost/remove-native-cost
Aug 4, 2026
Merged

feat: remove native chat cost tracking in favor of AI Gateway cost data#27330
ibetitsmike merged 9 commits into
mainfrom
mike/chat-cost/remove-native-cost

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Stack Context

This stack makes AI Gateway data and budgets the source of truth for AI spend controls.

  1. Re-back the per-chat cost endpoint with AI Gateway data (feat: back the per-chat cost endpoint with AI Gateway data #27328, merged).
  2. Remove native chat usage limits (feat: remove native chat usage limits in favor of AI Gateway budgets #27329, merged).
  3. This PR, now based on main: remove native chat cost tracking and its dedicated admin UI.

Summary

Removes native per-message price calculation, model pricing fields, cost persistence, aggregate cost queries, and admin cost API types. It also deletes the Analytics and Spend pages plus their legacy redirects. The AI Gateway-backed per-chat cost row and compact budget indicators remain.

The spend documentation is renamed to spend-management.md and updated for the remaining surfaces, group budget APIs, CSV export, upgrade handling for native pricing and cost history, and the absence of a deployment-wide spend dashboard. The per-chat cost API documents that data follows AI Gateway retention and reports zero after all matching requests are purged.

No schema is dropped in this release. chat_messages.total_cost_micros remains nullable and unwritten so replicas from the previous release can continue inserting messages during rolling upgrades. #27600 tracks removal after the compatibility window.

Mux prepared this PR on Mike's behalf.

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@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: 95cbc02c86

ℹ️ 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".

Comment thread codersdk/chats.go Outdated
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 7252fd8c58

ℹ️ 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".

@ibetitsmike
ibetitsmike force-pushed the mike/chat-cost/remove-native-cost branch from 7252fd8 to 4109148 Compare July 18, 2026 23:23
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 4109148bf6

ℹ️ 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".

@ibetitsmike
ibetitsmike force-pushed the mike/chat-cost/remove-native-cost branch from 4109148 to 0ee5f17 Compare July 18, 2026 23:38
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 0ee5f174bd

ℹ️ 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".

@ibetitsmike
ibetitsmike force-pushed the mike/chat-cost/remove-native-cost branch from 0ee5f17 to 57e4f39 Compare July 18, 2026 23:55
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 57e4f39c5e

ℹ️ 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".

@ibetitsmike
ibetitsmike force-pushed the mike/chat-cost/remove-native-cost branch from 57e4f39 to 850b601 Compare July 19, 2026 00:01
@ibetitsmike

Copy link
Copy Markdown
Collaborator 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: 850b601baf

ℹ️ 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".

Comment thread coderd/database/migrations/000557_drop_chat_message_cost.up.sql Outdated
@ibetitsmike
ibetitsmike force-pushed the mike/chat-cost/remove-native-cost branch from 850b601 to 28425bb Compare July 19, 2026 00:07
@ibetitsmike

Copy link
Copy Markdown
Collaborator 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: 28425bb24a

ℹ️ 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".

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

1 similar comment
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 5f688fdd04

ℹ️ 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".

@ibetitsmike
ibetitsmike force-pushed the mike/chat-cost/remove-native-cost branch 2 times, most recently from 14f7276 to 693e298 Compare July 19, 2026 00:29
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

Force-pushed after rebasing the stack onto main. New head: e3178ae2ab9.

Upstream #27579 removed the ai-gateway-cost-control experiment, which this stack still gated on. Git merged cleanly but the result did not compile, so CI on #27328 failed lint, check-build, test-e2e, and Storybook with Type '"ai-gateway-cost-control"' is not assignable to type 'Experiment'. The descendant PRs passed only because their bases are stack branches rather than main.

Change here: the chat lifecycle hook response types from upstream #27429 share a codersdk/chats.go region with the admin cost types this PR deletes, so only the cost types were removed. This PR now also carries the "no dedicated deployment-wide spend dashboard" statement, in the same commit that deletes the route and page.

Validated per branch: go build ./..., go vet ./... (no new findings), pnpm run lint:types, make lint, make gen clean, TestGetChatCost, and the affected Storybook and unit tests. Earlier review approvals were given on the pre-rebase heads.

Mux is acting on Mike's behalf.

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Mux is acting on Mike's behalf.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: e3178ae2ab

ℹ️ 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".

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

Docs LGTM with changes. Thanks for this!

Comment thread docs/ai-coder/agents/platform-controls/usage-insights.md Outdated

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.

As a total aside, I was confused when I tried to search for "usage insights" in the docs, and I had to go to manifest.json to figure out that the page's title is actually "Spend management" now. Should we rename and redirect this page? Is "Spend management" closer to what we want to convey for this page? If so, the URL should also be updated.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Accepted the rename in 533779f7cf8: the page is now spend-management.md, and the manifest plus all in-repo links use the new path. The public redirect from the old URL must be added to coder/coder.com's redirects.json, so I am leaving this thread open until that companion change lands.\n\n> Mux applied this feedback on Mike's behalf.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Nick, could you add the companion redirect in coder/coder.com? The coder/coder rename and link updates are already pushed.

{"source":"/docs/ai-coder/agents/platform-controls/usage-insights","destination":"/docs/ai-coder/agents/platform-controls/spend-management","permanent":true}

Mux posted this request on Mike's behalf.

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.

Done — companion redirect is up in coder/coder.com#1001, and I've added you as reviewer there. It adds the permanent /docs/ai-coder/agents/platform-controls/usage-insights/docs/ai-coder/agents/platform-controls/spend-management redirect.

I flagged on that PR that it should not merge until this one lands, so we don't redirect the still-live page to a path that doesn't exist yet. Leaving this thread open until both merge.

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.

Comment thread docs/ai-coder/agents/platform-controls/usage-insights.md Outdated
Comment thread docs/ai-coder/agents/platform-controls/usage-insights.md Outdated
Comment thread docs/ai-coder/agents/platform-controls/usage-insights.md Outdated
Comment thread docs/ai-coder/agents/platform-controls/usage-insights.md Outdated

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

This approval is for docs only, which LGTM!

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Mux requested this review on Mike's behalf.

@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: 3dd61f2c9a

ℹ️ 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".

Comment thread docs/ai-coder/agents/platform-controls/spend-management.md Outdated
Comment thread docs/ai-coder/agents/platform-controls/spend-management.md
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Mux requested this review on Mike's behalf.

@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

> Native chat usage limits are removed from the application.
> Existing native limit values are not migrated to AI Gateway budgets and are no longer enforced.
> Configure AI Gateway budgets separately.

P2 Badge Explain how native cost history is handled

When an administrator upgrades with existing per-model pricing and accumulated chat_messages.total_cost_micros data, this page explains that usage-limit values are not migrated but never gives the equivalent warning for native cost tracking. This change removes the pricing controls and aggregate cost APIs without migrating or exposing those historical totals through the AI Gateway surfaces, so operators cannot tell that old spend history becomes inaccessible or whether they should export it before upgrading. Add explicit migration guidance for the removed pricing metadata and cost history.

AGENTS.md reference: AGENTS.md:L12-L12

ℹ️ 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".

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

Addressed the native cost migration guidance in 2a4d91d49e6. The page now tells administrators how to preserve model prices and native aggregate reports before upgrading, and distinguishes the temporary compatibility column from AI Gateway reporting.

@codex review

Mux addressed this feedback and requested review on Mike's behalf.

@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: 2a4d91d49e

ℹ️ 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".

Comment thread docs/ai-coder/agents/platform-controls/spend-management.md Outdated
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

The current head 8238fc026c8 includes explicit native export date ranges, complete user pagination, and per-user summary instructions.

Mux requested this review on Mike's behalf.

@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: 8238fc026c

ℹ️ 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".

Comment thread docs/ai-coder/agents/platform-controls/spend-management.md Outdated
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

The current head e6e04fdd7bd now has an explicit, terminating pagination rule for full and partial final pages.

Mux requested this review on Mike's behalf.

Chats priced their own messages: chatcost computed a per-message cost from
per-model prices stored in each model config, persisted it on
chat_messages.total_cost_micros, and aggregated it for the admin cost views.
The AI Gateway already records cost for every request it proxies, so this was a
second, divergent accounting of the same spend with no admin UI for its prices.

Removes the chatcost package and all total_cost_micros plumbing, the admin cost
aggregate endpoints and SQL, the per-model pricing form fields, and the
Analytics and Spend cost UI. The column itself is not dropped here.
InsertChatMessages stops writing it, so it lingers nullable and unwritten until
a follow-up release drops it. Dropping it now would break InsertChatMessages,
and therefore every chat message insert, on a replica still running the
previous release.

The per-chat cost endpoint gains a retention caveat in its swagger description,
so docs/reference/api/chats.md states that cost comes from AI Gateway data
under its own retention period and that fully purged chats report zero.

Two things deliberately survive. GetChatMessageSummariesPerChat keeps feeding
telemetry, with only its cost projection removed. ChatModelCallConfig still
tolerates a stored cost object and the older top-level pricing keys, since
existing model configs contain them and strict decoding would otherwise reject
those rows.
The comment still referred to analytics nav buttons after this stack removed
the Analytics page. mobileBack hides the whole mobile actions menu, which
carries settings plus the sound and notification toggles.
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: e6e04fdd7b

ℹ️ 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".

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

PR #27329 is merged. PR #27330 is now rebased directly onto current main at head fb6c996f891, with the same nine child-layer patches preserved by range-diff.

Mux requested this exact-head review on Mike's behalf.

@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: fb6c996f89

ℹ️ 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".

Comment thread docs/manifest.json
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

The current head remains fb6c996f891. The requested public-path redirect is verified in companion PR coder/coder.com#1001, with a permanent mapping from usage-insights to spend-management.

Mux requested this exact-head review on Mike's behalf.

@chatgpt-codex-connector

Copy link
Copy Markdown

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