mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add user AI spend endpoint (#26978)
## Description
Adds the `GET /api/v2/users/{user}/ai/spend` endpoint returning the
user's current AI spend, effective budget, and period bounds.
## Changes
- Add `userAISpendStatus` handler under the same feature/experiment gate
as `/api/v2/users/{user}/ai/budget`.
- Add `codersdk.UserAIBudgetSummary` (embedded into `UserAISpendStatus`)
and a `UserAISpendStatus` client method.
- Move `LimitSource` from `coderd/aibridge/budget` to `codersdk` so the
type is shared across endpoints.
Closes https://linear.app/codercom/issue/AIGOV-472
> [!NOTE]
> Initially generated by Claude Opus 4.7, modified and reviewed by
@ssncferreira
This commit is contained in:
Generated
+43
@@ -3777,6 +3777,49 @@ curl -X DELETE http://coder-server:8080/api/v2/users/{user}/ai/budget \
|
||||
|
||||
To perform this operation, you must be authenticated. [Learn more](authentication.md).
|
||||
|
||||
## Get user AI spend
|
||||
|
||||
### Code samples
|
||||
|
||||
```shell
|
||||
# Example request using curl
|
||||
curl -X GET http://coder-server:8080/api/v2/users/{user}/ai/spend \
|
||||
-H 'Accept: application/json' \
|
||||
-H 'Coder-Session-Token: API_KEY'
|
||||
```
|
||||
|
||||
`GET /api/v2/users/{user}/ai/spend`
|
||||
|
||||
### Parameters
|
||||
|
||||
| Name | In | Type | Required | Description |
|
||||
|--------|------|--------|----------|--------------------------|
|
||||
| `user` | path | string | true | User ID, username, or me |
|
||||
|
||||
### Example responses
|
||||
|
||||
> 200 Response
|
||||
|
||||
```json
|
||||
{
|
||||
"current_spend_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"
|
||||
}
|
||||
```
|
||||
|
||||
### Responses
|
||||
|
||||
| Status | Meaning | Description | Schema |
|
||||
|--------|---------------------------------------------------------|-------------|--------------------------------------------------------------------|
|
||||
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.UserAISpendStatus](schemas.md#codersdkuseraispendstatus) |
|
||||
|
||||
To perform this operation, you must be authenticated. [Learn more](authentication.md).
|
||||
|
||||
## Get user quiet hours schedule
|
||||
|
||||
### Code samples
|
||||
|
||||
Generated
+40
@@ -905,6 +905,20 @@
|
||||
| `server_url` | string | false | | |
|
||||
| `tool` | string | false | | |
|
||||
|
||||
## codersdk.AIBudgetLimitSource
|
||||
|
||||
```json
|
||||
"user_override"
|
||||
```
|
||||
|
||||
### Properties
|
||||
|
||||
#### Enumerated Values
|
||||
|
||||
| Value(s) |
|
||||
|--------------------------|
|
||||
| `group`, `user_override` |
|
||||
|
||||
## codersdk.AIConfig
|
||||
|
||||
```json
|
||||
@@ -13925,6 +13939,32 @@ If the schedule is empty, the user will be updated to use the default schedule.|
|
||||
| `updated_at` | string | false | | |
|
||||
| `user_id` | string | false | | |
|
||||
|
||||
## codersdk.UserAISpendStatus
|
||||
|
||||
```json
|
||||
{
|
||||
"current_spend_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. Null when no budget applies. |
|
||||
| `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 | | |
|
||||
|
||||
## codersdk.UserActivity
|
||||
|
||||
```json
|
||||
|
||||
Reference in New Issue
Block a user