Skip to content

feat: add coderd_ai_group_budget resource - #453

Open
ssncferreira wants to merge 1 commit into
mainfrom
ssncf/ai-group-budget
Open

ssncferreira wants to merge 1 commit into
mainfrom
ssncf/ai-group-budget

Conversation

@ssncferreira

@ssncferreira ssncferreira commented Oct 12, 2026 •

Copy link
Copy Markdown

Description

Adds the coderd_ai_group_budget resource, which manages the AI spend limit that AI Gateway applies to each member of a group (/api/v2/groups/{group}/ai/budget). coderd_ai_user_budget_override follows in #454.

Changes

  • Add coderd_ai_group_budget with group_id and spend_limit, registered under the "AI Governance" docs subcategory.
  • spend_limit is in integer micro-units, like coderd_ai_model_price, and is validated against codersdk.MaxAISpendLimitMicros at plan time.
  • Import by group ID or <organization-name>/<group-name>, like coderd_group.
  • Add an example, import docs, mock-server plan tests, and an acceptance test.

Related to AIGOV-682

Note

Generated by Coder Agents on behalf of @ssncferreira.

@linear-code

linear-code Bot commented Oct 12, 2026

Copy link
Copy Markdown

AIGOV-682

@ssncferreira
ssncferreira force-pushed the ssncf/ai-group-budget branch 4 times, most recently from 6ad1300 to e0a507f Compare October 15, 2026 16:27
@ssncferreira
ssncferreira force-pushed the ssncf/ai-group-budget branch from e0a507f to defcf52 Compare October 15, 2026 16:43
@ssncferreira
ssncferreira marked this pull request as ready for review October 15, 2026 16:52
@ssncferreira
ssncferreira requested a review from SasSwart October 15, 2026 16:52
Comment on lines +51 to +66
// aiGroupBudgetDiag converts an error from the group AI budget API into a
// diagnostic. The upsert call returns 404 only when the group does not exist,
// or when the deployment has no group AI budget API.
func aiGroupBudgetDiag(action string, groupID uuid.UUID, err error) diag.Diagnostics {
var diags diag.Diagnostics
if isHTTPNotFound(err) {
diags.AddError("Group Not Found or Unsupported Coder Version", fmt.Sprintf(
"Unable to %s AI budget for group %s: the deployment returned 404 for /api/v2/groups/%s/ai/budget. "+
"Either the group does not exist, or the deployment is older than Coder version %s, which this resource requires. "+
"Original error: %s",
action, groupID, groupID, aiGroupBudgetMinVersion, err))
return diags
}
diags.AddError("Client Error", fmt.Sprintf("Unable to %s AI budget for group %s, got error: %s", action, groupID, err))
return diags
}

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.

A 404 here doesn't only mean a missing group or an old Coder. Coder also returns 404 when the token can read the group but can't update it: UpsertGroupAIBudget checks update on the group, and the handler maps the denial to 404 through httpapi.Is404Error.

A Template Admin or Auditor token hits this, and so do the organization versions of those roles. Those roles can read groups but can't update them, so the plan-time conflict check passes, then the apply fails with "Group Not Found or Unsupported Coder Version" while the group exists and Coder is new enough.

Could the comment and the message cover the missing permission case too, similar to the 404 message in agentsSystemPromptDiag?

Generated by an agent on behalf of the user

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.

2 participants