mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
refactor: make user AI budget and spend endpoints consistent (#27611)
## Description
Makes the user AI cost control endpoints consistent.
## Changes
- Replaces the flat `spend_limit_micros` and `limit_source` fields on
`GET /users/{user}/ai/spend` with a nested `effective_budget`, reusing
the type behind `group_budget`. The flat pair made it possible to encode
a limit without a source.
- Renames `AIGroupBudget` to `AIBudgetLimit`, since it also carries
`user_override` limits and is no longer group-specific. The type name is
not part of the wire format.
- Moves `/users/{user}/ai/budget` to `/users/{user}/ai/budget/override`.
The endpoint only ever managed the per-user override, which the type,
the handlers, and the operation IDs all already said; the path was the
only place that didn't.
> [!NOTE]
> Initially generated by Claude Opus 4.7, modified and reviewed by
@ssncferreira
This commit is contained in:
Generated
+10
-8
@@ -3982,12 +3982,12 @@ To perform this operation, you must be authenticated. [Learn more](authenticatio
|
||||
|
||||
```sh
|
||||
# Example request using curl
|
||||
curl -X GET http://coder-server:8080/api/v2/users/{user}/ai/budget \
|
||||
curl -X GET http://coder-server:8080/api/v2/users/{user}/ai/budget/override \
|
||||
-H 'Accept: application/json' \
|
||||
-H 'Coder-Session-Token: API_KEY'
|
||||
```
|
||||
|
||||
`GET /api/v2/users/{user}/ai/budget`
|
||||
`GET /api/v2/users/{user}/ai/budget/override`
|
||||
|
||||
### Parameters
|
||||
|
||||
@@ -4023,13 +4023,13 @@ To perform this operation, you must be authenticated. [Learn more](authenticatio
|
||||
|
||||
```sh
|
||||
# Example request using curl
|
||||
curl -X PUT http://coder-server:8080/api/v2/users/{user}/ai/budget \
|
||||
curl -X PUT http://coder-server:8080/api/v2/users/{user}/ai/budget/override \
|
||||
-H 'Content-Type: application/json' \
|
||||
-H 'Accept: application/json' \
|
||||
-H 'Coder-Session-Token: API_KEY'
|
||||
```
|
||||
|
||||
`PUT /api/v2/users/{user}/ai/budget`
|
||||
`PUT /api/v2/users/{user}/ai/budget/override`
|
||||
|
||||
> Body parameter
|
||||
|
||||
@@ -4075,11 +4075,11 @@ To perform this operation, you must be authenticated. [Learn more](authenticatio
|
||||
|
||||
```sh
|
||||
# Example request using curl
|
||||
curl -X DELETE http://coder-server:8080/api/v2/users/{user}/ai/budget \
|
||||
curl -X DELETE http://coder-server:8080/api/v2/users/{user}/ai/budget/override \
|
||||
-H 'Coder-Session-Token: API_KEY'
|
||||
```
|
||||
|
||||
`DELETE /api/v2/users/{user}/ai/budget`
|
||||
`DELETE /api/v2/users/{user}/ai/budget/override`
|
||||
|
||||
### Parameters
|
||||
|
||||
@@ -4121,11 +4121,13 @@ curl -X GET http://coder-server:8080/api/v2/users/{user}/ai/spend \
|
||||
```json
|
||||
{
|
||||
"current_spend_micros": 0,
|
||||
"effective_budget": {
|
||||
"limit_source": "user_override",
|
||||
"spend_limit_micros": 0
|
||||
},
|
||||
"effective_group_id": "85e2b926-ddfb-4c66-b68e-b66e5acec6c0",
|
||||
"limit_source": "user_override",
|
||||
"period_end": "2019-08-24T14:15:22Z",
|
||||
"period_start": "2019-08-24T14:15:22Z",
|
||||
"spend_limit_micros": 0,
|
||||
"user_id": "a169451c-8525-4352-b8ca-070dd449a1a5"
|
||||
}
|
||||
```
|
||||
|
||||
Generated
+29
-28
@@ -938,6 +938,22 @@
|
||||
| `server_url` | string | false | | |
|
||||
| `tool` | string | false | | |
|
||||
|
||||
## codersdk.AIBudgetLimit
|
||||
|
||||
```json
|
||||
{
|
||||
"limit_source": "user_override",
|
||||
"spend_limit_micros": 0
|
||||
}
|
||||
```
|
||||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Required | Restrictions | Description |
|
||||
|----------------------|--------------------------------------------------------------|----------|--------------|-------------|
|
||||
| `limit_source` | [codersdk.AIBudgetLimitSource](#codersdkaibudgetlimitsource) | false | | |
|
||||
| `spend_limit_micros` | integer | false | | |
|
||||
|
||||
## codersdk.AIBudgetLimitSource
|
||||
|
||||
```json
|
||||
@@ -1071,22 +1087,6 @@
|
||||
| `last_heartbeat_at` | string | false | | |
|
||||
| `name` | string | false | | |
|
||||
|
||||
## codersdk.AIGroupBudget
|
||||
|
||||
```json
|
||||
{
|
||||
"limit_source": "user_override",
|
||||
"spend_limit_micros": 0
|
||||
}
|
||||
```
|
||||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Required | Restrictions | Description |
|
||||
|----------------------|--------------------------------------------------------------|----------|--------------|-------------|
|
||||
| `limit_source` | [codersdk.AIBudgetLimitSource](#codersdkaibudgetlimitsource) | false | | |
|
||||
| `spend_limit_micros` | integer | false | | |
|
||||
|
||||
## codersdk.AIProvider
|
||||
|
||||
```json
|
||||
@@ -8029,7 +8029,7 @@ Only certain features set these fields: - FeatureManagedAgentLimit - FeatureAgen
|
||||
| Name | Type | Required | Restrictions | Description |
|
||||
|----------------------|--------------------------------------------------|----------|--------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `effective_group_id` | string | false | | Effective group ID is the user's effective budget group within the queried group's organization, falling back to the Everyone group when no budget applies. Null when the effective group belongs to a different organization than the queried group. |
|
||||
| `group_budget` | [codersdk.AIGroupBudget](#codersdkaigroupbudget) | false | | Group budget is the budget when the queried group is this user's effective budget source. Null when the user's budget resolves to another group or no budget applies to the user. |
|
||||
| `group_budget` | [codersdk.AIBudgetLimit](#codersdkaibudgetlimit) | false | | Group budget is the budget when the queried group is this user's effective budget source. Null when the user's budget resolves to another group or no budget applies to the user. |
|
||||
| `group_spend_micros` | integer | false | | Group spend micros is the user's spend attributed to the queried group over the current budget period. |
|
||||
| `user_id` | string | false | | |
|
||||
|
||||
@@ -14478,26 +14478,27 @@ If the schedule is empty, the user will be updated to use the default schedule.|
|
||||
```json
|
||||
{
|
||||
"current_spend_micros": 0,
|
||||
"effective_budget": {
|
||||
"limit_source": "user_override",
|
||||
"spend_limit_micros": 0
|
||||
},
|
||||
"effective_group_id": "85e2b926-ddfb-4c66-b68e-b66e5acec6c0",
|
||||
"limit_source": "user_override",
|
||||
"period_end": "2019-08-24T14:15:22Z",
|
||||
"period_start": "2019-08-24T14:15:22Z",
|
||||
"spend_limit_micros": 0,
|
||||
"user_id": "a169451c-8525-4352-b8ca-070dd449a1a5"
|
||||
}
|
||||
```
|
||||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Required | Restrictions | Description |
|
||||
|------------------------|--------------------------------------------------------------|----------|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `current_spend_micros` | integer | false | | Current spend micros is the user's spend on their effective group over the current budget period. |
|
||||
| `effective_group_id` | string | false | | Effective group ID is the group the spend is attributed to, falling back to the Everyone group when no budget applies. Null only when the user has no organization membership. |
|
||||
| `limit_source` | [codersdk.AIBudgetLimitSource](#codersdkaibudgetlimitsource) | false | | Limit source identifies which tier produced the limit. Null when no budget applies. |
|
||||
| `period_end` | string | false | | Period end is the exclusive upper bound of the current budget period. |
|
||||
| `period_start` | string | false | | Period start is the inclusive lower bound of the current budget period. |
|
||||
| `spend_limit_micros` | integer | false | | Spend limit micros is the effective spend limit in micro-units. Null when no budget applies to the user (unlimited). |
|
||||
| `user_id` | string | false | | |
|
||||
| Name | Type | Required | Restrictions | Description |
|
||||
|------------------------|--------------------------------------------------|----------|--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `current_spend_micros` | integer | false | | Current spend micros is the user's spend on their effective group over the current budget period. |
|
||||
| `effective_budget` | [codersdk.AIBudgetLimit](#codersdkaibudgetlimit) | false | | Effective budget is the spend limit that applies to the user, whether it came from a group budget or a user override. Null when no budget applies, leaving the user's spend unlimited. |
|
||||
| `effective_group_id` | string | false | | Effective group ID is the group the spend is attributed to, falling back to the Everyone group when no budget applies. Null only when the user has no organization membership. |
|
||||
| `period_end` | string | false | | Period end is the exclusive upper bound of the current budget period. |
|
||||
| `period_start` | string | false | | Period start is the inclusive lower bound of the current budget period. |
|
||||
| `user_id` | string | false | | |
|
||||
|
||||
## codersdk.UserActivity
|
||||
|
||||
|
||||
Reference in New Issue
Block a user