feat: add AI budget policy and period deployment config (#25122)

Closes
https://linear.app/codercom/issue/AIGOV-283/add-deployment-config-for-ai-budget-policy-and-period

Adds `CODER_AI_BUDGET_POLICY` and `CODER_AI_BUDGET_PERIOD` deployment
options for AI Governance cost controls.
This commit is contained in:
Yevhenii Shcherbina
2026-05-12 10:48:36 -04:00
committed by GitHub
parent fabf7d31fc
commit b5e1ea33d8
11 changed files with 202 additions and 0 deletions
+52
View File
@@ -574,6 +574,34 @@ var PostgresAuthDrivers = []string{
// based on max open connections.
const PostgresConnMaxIdleAuto = "auto"
// AIBudgetPolicy determines how the effective group is selected when a user
// belongs to multiple groups with AI budgets configured.
type AIBudgetPolicy string
const (
// AIBudgetPolicyHighest selects the group with the highest spend limit.
AIBudgetPolicyHighest AIBudgetPolicy = "highest"
)
// AIBudgetPolicies lists the supported AIBudgetPolicy values.
var AIBudgetPolicies = []string{
string(AIBudgetPolicyHighest),
}
// AIBudgetPeriod determines when accumulated AI spend resets to zero,
// aligned to UTC calendar boundaries.
type AIBudgetPeriod string
const (
// AIBudgetPeriodMonth resets spend at the start of each UTC calendar month.
AIBudgetPeriodMonth AIBudgetPeriod = "month"
)
// AIBudgetPeriods lists the supported AIBudgetPeriod values.
var AIBudgetPeriods = []string{
string(AIBudgetPeriodMonth),
}
// DeploymentValues is the central configuration values the coder server.
type DeploymentValues struct {
Verbose serpent.Bool `json:"verbose,omitempty"`
@@ -3893,6 +3921,27 @@ Write out the current server config as YAML to stdout.`,
YAML: "circuit_breaker_max_requests",
},
{
Name: "AI Budget Policy",
Description: "Determines the effective group when a user belongs to multiple groups with AI budgets. \"highest\" selects the group with the largest spend limit, and is currently the only supported value.",
Flag: "ai-budget-policy",
Env: "CODER_AI_BUDGET_POLICY",
Value: serpent.EnumOf(&c.AI.BridgeConfig.BudgetPolicy, AIBudgetPolicies...),
Default: string(AIBudgetPolicyHighest),
Group: &deploymentGroupAIBridge,
YAML: "budget_policy",
},
{
Name: "AI Budget Period",
Description: "Determines when accumulated AI spend resets to zero, aligned to UTC calendar boundaries. Only \"month\" is currently supported.",
Flag: "ai-budget-period",
Env: "CODER_AI_BUDGET_PERIOD",
Value: serpent.EnumOf(&c.AI.BridgeConfig.BudgetPeriod, AIBudgetPeriods...),
Default: string(AIBudgetPeriodMonth),
Group: &deploymentGroupAIBridge,
YAML: "budget_period",
},
// AI Bridge Proxy Options
{
Name: "AI Bridge Proxy Enabled",
@@ -4107,6 +4156,9 @@ type AIBridgeConfig struct {
StructuredLogging serpent.Bool `json:"structured_logging" typescript:",notnull"`
SendActorHeaders serpent.Bool `json:"send_actor_headers" typescript:",notnull"`
AllowBYOK serpent.Bool `json:"allow_byok" typescript:",notnull"`
// Budget settings for AI Governance cost controls.
BudgetPolicy string `json:"budget_policy,omitempty" typescript:",notnull"`
BudgetPeriod string `json:"budget_period,omitempty" typescript:",notnull"`
// Circuit breaker protects against cascading failures from upstream AI
// provider overload (503, 529).
CircuitBreakerEnabled serpent.Bool `json:"circuit_breaker_enabled" typescript:",notnull"`