Adds `API.getOrganizationAISpendUsers(organizationId, params)` for `GET
/api/v2/organizations/{organization}/ai/spend/users` (period, provider,
model, client filters plus `limit`/`offset`), the
`MockOrganizationAISpendReport` fixture, and a shared
`codersdk.MaxAISpendPeriodDays` constant that the enterprise export
handler now reads and that `make gen` emits into `typesGenerated.ts`.
The model-list endpoint also accepts a literal `model` prefix. The
backend escapes SQL LIKE characters, while `q` keeps its existing search
syntax. Supplying both nonempty parameters returns 400. The filter menu
adopts this parameter in #29632.
## Why
The frontend caps custom ranges at the same 31-day limit the server
enforces; one SDK constant keeps the two from drifting. The fixture is
what every later test and story renders. Literal model identifiers
should not require search-language quoting or SQL escaping in the
frontend.
## What to scrutinize
- `enterprise/coderd/aibridge.go`: `maxAISpendExportPeriod` is now
derived from the SDK constant, same value as before.
- `MockOrganizationAISpendUser` is not exported yet; the table PR
exports it for its stories (knip fails on exports without a consumer).
## Generated files
`site/src/api/typesGenerated.ts`, `coderd/apidoc/docs.go`,
`coderd/apidoc/swagger.json`, and `docs/reference/api/aigateway.md` via
`make gen`.
## Validation
`pnpm test src/api/api.test.ts -t getOrganizationAISpendUsers` (new
case), `go test ./enterprise/coderd/ -run TestAIBridgeListModels
-count=1 -v`, repository pre-commit including `make gen` with no drift.
Model tests cover literal punctuation, prefix matching, existing `q`
behavior, and conflicting parameters.
## Delivery record
Published head `8d9a4faa0aa` passed per-layer integration checks and
commit hooks. The composed head `d899228f798` passed format, check, full
frontend lint, 125 unit tests, and 86 story tests. Pre-push hooks were
skipped as requested. See #28964 for audit findings, their disposition,
and historical UAT limits. No exact-head live UAT or new independent
re-review is claimed.
## Stack context
PR 3 of 9. The stack adds a **User spend** page under **Admin settings**
> **AI** > **User spend**: total and per-user AI Gateway spend for one
organization over a reporting period, read from `GET
/api/v2/organizations/{organization}/ai/spend/users` (#29129, merged).
It is #28964 split into one-concern PRs. Historical UAT covers earlier
heads only; live UAT has not been rerun after these review fixes. Bottom
to top: DateRangePicker limits, shared dimension badge, API client
method, spend table, page view, page container, reporting period,
dimension filters, route and navigation (#28964).
> Xum prepared this PR on behalf of @ibetitsmike.
386 lines
13 KiB
Markdown
Generated
386 lines
13 KiB
Markdown
Generated
---
|
|
# Code generated by make gen. DO NOT EDIT.
|
|
title: AI Gateway
|
|
---
|
|
|
|
<!-- DO NOT EDIT | GENERATED CONTENT -->
|
|
|
|
## List AI Gateway clients
|
|
|
|
### Code samples
|
|
|
|
```sh
|
|
# Example request using curl
|
|
curl -X GET http://coder-server:8080/api/v2/ai-gateway/clients \
|
|
-H 'Accept: application/json' \
|
|
-H 'Coder-Session-Token: API_KEY'
|
|
```
|
|
|
|
`GET /api/v2/ai-gateway/clients`
|
|
|
|
Alias: also available at /api/v2/aibridge/clients for backward compatibility.
|
|
|
|
### Example responses
|
|
|
|
> 200 Response
|
|
|
|
```json
|
|
[
|
|
"string"
|
|
]
|
|
```
|
|
|
|
### Responses
|
|
|
|
| Status | Meaning | Description | Schema |
|
|
|--------|---------------------------------------------------------|-------------|-----------------|
|
|
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | array of string |
|
|
|
|
<h3 id="list-ai-gateway-clients-responseschema">Response Schema</h3>
|
|
|
|
To perform this operation, you must be authenticated. [Learn more](authentication.md).
|
|
|
|
## List AI Gateway models
|
|
|
|
### Code samples
|
|
|
|
```sh
|
|
# Example request using curl
|
|
curl -X GET http://coder-server:8080/api/v2/ai-gateway/models \
|
|
-H 'Accept: application/json' \
|
|
-H 'Coder-Session-Token: API_KEY'
|
|
```
|
|
|
|
`GET /api/v2/ai-gateway/models`
|
|
|
|
Alias: also available at /api/v2/aibridge/models for backward compatibility.
|
|
|
|
### Parameters
|
|
|
|
| Name | In | Type | Required | Description |
|
|
|---------|-------|--------|----------|----------------------------------------------------------------------------------------------------------|
|
|
| `q` | query | string | false | Search query in the format `key:value`. Available keys are: model. A bare term searches by model prefix. |
|
|
| `model` | query | string | false | Literal model identifier prefix. Cannot be combined with q. |
|
|
|
|
### Example responses
|
|
|
|
> 200 Response
|
|
|
|
```json
|
|
[
|
|
"string"
|
|
]
|
|
```
|
|
|
|
### Responses
|
|
|
|
| Status | Meaning | Description | Schema |
|
|
|--------|---------------------------------------------------------|-------------|-----------------|
|
|
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | array of string |
|
|
|
|
<h3 id="list-ai-gateway-models-responseschema">Response Schema</h3>
|
|
|
|
To perform this operation, you must be authenticated. [Learn more](authentication.md).
|
|
|
|
## List AI Gateway providers
|
|
|
|
### Code samples
|
|
|
|
```sh
|
|
# Example request using curl
|
|
curl -X GET http://coder-server:8080/api/v2/ai-gateway/providers \
|
|
-H 'Accept: application/json' \
|
|
-H 'Coder-Session-Token: API_KEY'
|
|
```
|
|
|
|
`GET /api/v2/ai-gateway/providers`
|
|
|
|
### Example responses
|
|
|
|
> 200 Response
|
|
|
|
```json
|
|
[
|
|
{
|
|
"display_name": "string",
|
|
"icon": "string",
|
|
"name": "string",
|
|
"type": "openai"
|
|
}
|
|
]
|
|
```
|
|
|
|
### Responses
|
|
|
|
| Status | Meaning | Description | Schema |
|
|
|--------|---------------------------------------------------------|-------------|---------------------------------------------------------------------------|
|
|
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | array of [codersdk.AIBridgeProvider](schemas.md#codersdkaibridgeprovider) |
|
|
|
|
<h3 id="list-ai-gateway-providers-responseschema">Response Schema</h3>
|
|
|
|
Status Code **200**
|
|
|
|
| Name | Type | Required | Restrictions | Description |
|
|
|------------------|--------------------------------------------------------------|----------|--------------|-------------|
|
|
| `[array item]` | array | false | | |
|
|
| `» display_name` | string | false | | |
|
|
| `» icon` | string | false | | |
|
|
| `» name` | string | false | | |
|
|
| `» type` | [codersdk.AIProviderType](schemas.md#codersdkaiprovidertype) | false | | |
|
|
|
|
#### Enumerated Values
|
|
|
|
| Property | Value(s) |
|
|
|----------|---------------------------------------------------------------------------------------------------------|
|
|
| `type` | `anthropic`, `azure`, `bedrock`, `copilot`, `google`, `openai`, `openai-compat`, `openrouter`, `vercel` |
|
|
|
|
To perform this operation, you must be authenticated. [Learn more](authentication.md).
|
|
|
|
## List AI Gateway sessions
|
|
|
|
### Code samples
|
|
|
|
```sh
|
|
# Example request using curl
|
|
curl -X GET http://coder-server:8080/api/v2/ai-gateway/sessions \
|
|
-H 'Accept: application/json' \
|
|
-H 'Coder-Session-Token: API_KEY'
|
|
```
|
|
|
|
`GET /api/v2/ai-gateway/sessions`
|
|
|
|
Alias: also available at /api/v2/aibridge/sessions for backward compatibility.
|
|
|
|
### Parameters
|
|
|
|
| Name | In | Type | Required | Description |
|
|
|--------------------|-------|---------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
| `q` | query | string | false | Search query in the format `key:value`. Available keys are: initiator, provider, provider_name, model, client, session_id, started_after, started_before. |
|
|
| `limit` | query | integer | false | Page limit |
|
|
| `after_session_id` | query | string | false | Cursor pagination after session ID (cannot be used with offset) |
|
|
| `offset` | query | integer | false | Offset pagination (cannot be used with after_session_id) |
|
|
|
|
### Example responses
|
|
|
|
> 200 Response
|
|
|
|
```json
|
|
{
|
|
"count": 0,
|
|
"sessions": [
|
|
{
|
|
"client": "string",
|
|
"ended_at": "2019-08-24T14:15:22Z",
|
|
"id": "string",
|
|
"initiator": {
|
|
"avatar_url": "http://example.com",
|
|
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
|
|
"name": "string",
|
|
"username": "string"
|
|
},
|
|
"last_active_at": "2019-08-24T14:15:22Z",
|
|
"last_prompt": "string",
|
|
"metadata": {
|
|
"property1": null,
|
|
"property2": null
|
|
},
|
|
"models": [
|
|
"string"
|
|
],
|
|
"network_calls": {
|
|
"blocked": 0,
|
|
"total": 0
|
|
},
|
|
"providers": [
|
|
"string"
|
|
],
|
|
"started_at": "2019-08-24T14:15:22Z",
|
|
"threads": 0,
|
|
"token_usage_summary": {
|
|
"cache_read_input_tokens": 0,
|
|
"cache_write_input_tokens": 0,
|
|
"input_tokens": 0,
|
|
"output_tokens": 0
|
|
}
|
|
}
|
|
]
|
|
}
|
|
```
|
|
|
|
### Responses
|
|
|
|
| Status | Meaning | Description | Schema |
|
|
|--------|---------------------------------------------------------|-------------|------------------------------------------------------------------------------------------|
|
|
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.AIBridgeListSessionsResponse](schemas.md#codersdkaibridgelistsessionsresponse) |
|
|
|
|
To perform this operation, you must be authenticated. [Learn more](authentication.md).
|
|
|
|
## Get AI Gateway session threads
|
|
|
|
### Code samples
|
|
|
|
```sh
|
|
# Example request using curl
|
|
curl -X GET http://coder-server:8080/api/v2/ai-gateway/sessions/{session_id} \
|
|
-H 'Accept: application/json' \
|
|
-H 'Coder-Session-Token: API_KEY'
|
|
```
|
|
|
|
`GET /api/v2/ai-gateway/sessions/{session_id}`
|
|
|
|
Alias: also available at /api/v2/aibridge/sessions/{session_id} for backward compatibility.
|
|
|
|
### Parameters
|
|
|
|
| Name | In | Type | Required | Description |
|
|
|--------------|-------|---------|----------|-----------------------------------------------------|
|
|
| `session_id` | path | string | true | Session ID (client_session_id or interception UUID) |
|
|
| `after_id` | query | string | false | Thread pagination cursor (forward/older) |
|
|
| `before_id` | query | string | false | Thread pagination cursor (backward/newer) |
|
|
| `limit` | query | integer | false | Number of threads per page (default 50) |
|
|
|
|
### Example responses
|
|
|
|
> 200 Response
|
|
|
|
```json
|
|
{
|
|
"client": "string",
|
|
"ended_at": "2019-08-24T14:15:22Z",
|
|
"id": "string",
|
|
"initiator": {
|
|
"avatar_url": "http://example.com",
|
|
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
|
|
"name": "string",
|
|
"username": "string"
|
|
},
|
|
"metadata": {
|
|
"property1": null,
|
|
"property2": null
|
|
},
|
|
"models": [
|
|
"string"
|
|
],
|
|
"network_call_logs": [
|
|
{
|
|
"allowed": true,
|
|
"captured_at": "2019-08-24T14:15:22Z",
|
|
"created_at": "2019-08-24T14:15:22Z",
|
|
"detail": "string",
|
|
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
|
|
"matched_rule": "string",
|
|
"method": "string",
|
|
"proto": "string",
|
|
"sequence_number": 0,
|
|
"session_id": "1ffd059c-17ea-40a8-8aef-70fd0307db82"
|
|
}
|
|
],
|
|
"network_calls": {
|
|
"blocked": 0,
|
|
"total": 0
|
|
},
|
|
"network_domain_count": 0,
|
|
"network_top_domains": [
|
|
{
|
|
"count": 0,
|
|
"domain": "string"
|
|
}
|
|
],
|
|
"page_ended_at": "2019-08-24T14:15:22Z",
|
|
"page_started_at": "2019-08-24T14:15:22Z",
|
|
"providers": [
|
|
"string"
|
|
],
|
|
"started_at": "2019-08-24T14:15:22Z",
|
|
"threads": [
|
|
{
|
|
"agent_firewall_sequence_number": 0,
|
|
"agent_firewall_session_id": "3735294f-18b1-4e7a-a269-99c30f0b30e7",
|
|
"agentic_actions": [
|
|
{
|
|
"attribution": {
|
|
"property1": "string",
|
|
"property2": "string"
|
|
},
|
|
"interception_id": "34d9b688-63ad-46f4-88b5-665c1e7f7824",
|
|
"model": "string",
|
|
"thinking": [
|
|
{
|
|
"text": "string"
|
|
}
|
|
],
|
|
"token_usage": {
|
|
"cache_read_input_tokens": 0,
|
|
"cache_write_input_tokens": 0,
|
|
"input_tokens": 0,
|
|
"metadata": {
|
|
"property1": null,
|
|
"property2": null
|
|
},
|
|
"output_tokens": 0
|
|
},
|
|
"tool_calls": [
|
|
{
|
|
"created_at": "2019-08-24T14:15:22Z",
|
|
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
|
|
"injected": true,
|
|
"input": "string",
|
|
"interception_id": "34d9b688-63ad-46f4-88b5-665c1e7f7824",
|
|
"metadata": {
|
|
"property1": null,
|
|
"property2": null
|
|
},
|
|
"provider_response_id": "string",
|
|
"server_url": "string",
|
|
"tool": "string"
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"attribution": {
|
|
"property1": "string",
|
|
"property2": "string"
|
|
},
|
|
"credential_hint": "string",
|
|
"credential_kind": "string",
|
|
"ended_at": "2019-08-24T14:15:22Z",
|
|
"error_message": "string",
|
|
"error_type": "string",
|
|
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
|
|
"model": "string",
|
|
"prompt": "string",
|
|
"provider": "string",
|
|
"started_at": "2019-08-24T14:15:22Z",
|
|
"token_usage": {
|
|
"cache_read_input_tokens": 0,
|
|
"cache_write_input_tokens": 0,
|
|
"input_tokens": 0,
|
|
"metadata": {
|
|
"property1": null,
|
|
"property2": null
|
|
},
|
|
"output_tokens": 0
|
|
}
|
|
}
|
|
],
|
|
"token_usage_summary": {
|
|
"cache_read_input_tokens": 0,
|
|
"cache_write_input_tokens": 0,
|
|
"input_tokens": 0,
|
|
"metadata": {
|
|
"property1": null,
|
|
"property2": null
|
|
},
|
|
"output_tokens": 0
|
|
}
|
|
}
|
|
```
|
|
|
|
### Responses
|
|
|
|
| Status | Meaning | Description | Schema |
|
|
|--------|---------------------------------------------------------|-------------|----------------------------------------------------------------------------------------------|
|
|
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.AIBridgeSessionThreadsResponse](schemas.md#codersdkaibridgesessionthreadsresponse) |
|
|
|
|
To perform this operation, you must be authenticated. [Learn more](authentication.md).
|