Skip to content

feat: add coderd_ai_model_price resource - #445

Merged
ethanndickson merged 5 commits into
mainfrom
terraform-pricing-bbqm
Sep 28, 2026
Merged

ethanndickson merged 5 commits into
mainfrom
terraform-pricing-bbqm

Conversation

@ethanndickson

@ethanndickson ethanndickson commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Closes AIGOV-677

This adds a coderd_ai_model_price resource for managing custom AI Gateway model prices. It replaces the model_config.cost field we removed from coderd_agents_model in #413, which stopped doing anything once cost tracking moved to AI Gateway.

I've made it a standalone resource rather than a field on coderd_agents_model, since prices are deployment-wide and keyed on provider type and model, whilst agents models are org-scoped. Plenty of AI Gateway users (Claude Code, Cursor, Copilot) won't have any agents models at all.

For now the resource takes a provider_type string, since that's how prices are keyed today. AIGOV-612 will add per-provider prices, so we can either ship this as-is and add an optional ai_provider_id once that lands (which wouldn't break existing configs), or just wait for AIGOV-612. I'm happy to pick that up myself if we'd rather wait.

Unfortunately, Coder has no API to delete a custom price, so for now destroying the resource just removes it from state and warns that the custom price is still set in Coder. Adding a delete endpoint to coder/coder would mean waiting on 2.38, whereas everything else the resource needs has been there since 2.37.0. We'll wire up a real delete once that endpoint exists.

@linear-code

linear-code Bot commented Sep 24, 2026

Copy link
Copy Markdown

AIGOV-677

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-25T06:13:02.869098Z 43e93a1 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Comment thread docs/resources/ai_model_price.md Resolved
Comment thread docs/resources/ai_model_price.md Resolved

@ssncferreira ssncferreira left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Overall LGTM, just a few notes especially around the case when a custom model price is already set

Comment thread docs/resources/ai_model_price.md Resolved
Comment thread docs/resources/ai_model_price.md Resolved
Comment thread docs/resources/ai_model_price.md Resolved
- Fail the plan when Coder already has a different custom price for the
  same provider type and model, and tell the user to import it. Adopt an
  existing price that equals the config.
- Report "Unsupported Coder Version" when the model prices API returns
  404, at plan time and at apply time.
- Reword the resource docs, link to the default prices, and note that
  openai-compat is not supported.
- Replace the deferral test with a mock-backed ModifyPlan table test and
  remove redundant test cases.
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 49057992fc

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

@ethanndickson
ethanndickson marked this pull request as ready for review September 25, 2026 05:55

@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: 49057992fc

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

@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

Re: Do not preserve the ID across key replacements

Not an issue. When provider_type or model changes, Terraform core calls PlanResourceChange a second time with a null prior state (source). UseStateForUnknown does nothing when there is no prior state, so id plans as unknown and Create sets the new value. The old ID is only kept when the key is unchanged, and then it is still correct. Both inputs to id are RequiresReplace, so the AGENTS.md rule about config-derived values does not apply.

I checked this with a temporary acceptance test that changed each key in turn. Both plans were destroy-then-create with id unknown, and the state ended up with the new ID.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 43e93a1249

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

@ssncferreira ssncferreira left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM! Thank you for working on this, and addressing the comments 🚀

Comment thread docs/resources/ai_model_price.md Resolved
Comment on lines +76 to +78
"Unable to %s AI model price %s: the deployment returned 404 for /api/experimental/ai/model-prices. "+
"This resource requires Coder version %s or later; upgrade the deployment, or remove "+
"`coderd_ai_model_price` from your configuration. Original error: %s",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice 🤩

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

🚀

@ethanndickson
ethanndickson merged commit aad5e4e into main Sep 28, 2026
13 checks passed
@ethanndickson
ethanndickson deleted the terraform-pricing-bbqm branch September 28, 2026 02:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants