fix: ai cost control cap configurable AI spend limit - #27640
Conversation
Docs previewCheck off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here. |
9187241 to
515158f
Compare
515158f to
dd0c624
Compare
| return ( | ||
| <span className="text-left text-xs text-content-secondary"> | ||
| <span className="font-medium text-content-primary"> | ||
| {usdBudgetFormatter.format(budgetAmount * memberCount)} |
There was a problem hiding this comment.
I think we should also use the total budget here no? Though I guess it depends on what we want to show 🤔
There was a problem hiding this comment.
I thought of that as well, but decided against it. The total returned by /groups/{group}/ai/spend is computed from the saved budget on the database, so it can't preview the value being typed. We'd need the group's member count and override sum instead, which the endpoint doesn't expose, and that query isn't free.
Nevertheless, I removed "maximum" from the message instead, since that was the misleading part.
There was a problem hiding this comment.
Oh yes that would clear things up a bit
|
|
||
| type UpsertGroupAIBudgetRequest struct { | ||
| // SpendLimitMicros must not exceed MaxAISpendLimitMicros. | ||
| SpendLimitMicros int64 `json:"spend_limit_micros" validate:"gte=0"` |
There was a problem hiding this comment.
Why not enforce this? (lte)
Unless we want to configure this later on?
There was a problem hiding this comment.
It is enforced, just in the handler rather than the tag. A lte tag can't reference the constant, so the number would be duplicated (maintenance drift), and the generated message doesn't name the maximum. It would show something like
Validation failed for tag "lte" with value: "2000000000000"
While the handler returns Must not exceed 1000000000000. instead.
dd0c624 to
b2cd558
Compare
|
|
||
| type UpsertGroupAIBudgetRequest struct { | ||
| // SpendLimitMicros must not exceed MaxAISpendLimitMicros. | ||
| SpendLimitMicros int64 `json:"spend_limit_micros" validate:"gte=0"` |
| return ( | ||
| <span className="text-left text-xs text-content-secondary"> | ||
| <span className="font-medium text-content-primary"> | ||
| {usdBudgetFormatter.format(budgetAmount * memberCount)} |
There was a problem hiding this comment.
Oh yes that would clear things up a bit
b2cd558 to
d3f2ea3
Compare

Problem
A configured AI spend limit was only validated as
gte=0, with no upper bound. The group spend query multiplies the per-member limit by the number of attributed members, so a large enough limit overflowsbigintand fails the whole query, returning an error for every group in the request rather than just the misconfigured one.Changes
MaxAISpendLimitMicros, $1,000,000 per member per budget period.Follow-up #27589 (comment)
Depends on #27589
Note
Initially generated by Claude Opus 5, modified and reviewed by @ssncferreira