mirror of
https://github.com/coder/coder.git
synced 2026-06-04 21:48:22 +00:00
43a1af3cd6
<!-- If you have used AI to produce some or all of this PR, please ensure you have read our [AI Contribution guidelines](https://coder.com/docs/about/contributing/AI_CONTRIBUTING) before submitting. --> _Disclaimer:_ _initially_ _produced_ _by_ _Claude_ _Opus_ _4\.6,_ _heavily_ _modified_ _and_ _reviewed_ _by_ _me._ Closes https://github.com/coder/internal/issues/1360 Adds a new `/api/v2/aibridge/sessions` API which returns "sessions". Sessions, as defined in the [RFC](https://www.notion.so/coderhq/AI-Bridge-Sessions-Threads-2ccd579be59280f28021d3baf7472fbe?source=copy_link), are a set of interceptions logically grouped by a session key issued by the client. The API design for this endpoint was done in [this doc](https://github.com/coder/internal/issues/1360). If the client has not provided a session ID, we will revert to the thread root ID, and if that's not present we use the interception's own ID (i.e. a session of a single interception - which is effectively what we show currently in our `/api/v2/aibridge/interceptions` API). The SQL query looks gnarly but it's relatively simple, and seems to perform well (~200ms) even when I import dogfood's `aibridge_*` tables into my workspace. If we need to improve performance on this later we can investigate materialized views, perhaps, but for now I don't think it's warranted. --- _The PR looks large but it's got a lot of generated code; the actual changes aren't huge._
210 lines
7.3 KiB
Markdown
Generated
210 lines
7.3 KiB
Markdown
Generated
# AI Bridge
|
|
|
|
## List AI Bridge interceptions
|
|
|
|
### Code samples
|
|
|
|
```shell
|
|
# Example request using curl
|
|
curl -X GET http://coder-server:8080/api/v2/aibridge/interceptions \
|
|
-H 'Accept: application/json' \
|
|
-H 'Coder-Session-Token: API_KEY'
|
|
```
|
|
|
|
`GET /aibridge/interceptions`
|
|
|
|
### Parameters
|
|
|
|
| Name | In | Type | Required | Description |
|
|
|------------|-------|---------|----------|------------------------------------------------------------------------------------------------------------------------|
|
|
| `q` | query | string | false | Search query in the format `key:value`. Available keys are: initiator, provider, model, started_after, started_before. |
|
|
| `limit` | query | integer | false | Page limit |
|
|
| `after_id` | query | string | false | Cursor pagination after ID (cannot be used with offset) |
|
|
| `offset` | query | integer | false | Offset pagination (cannot be used with after_id) |
|
|
|
|
### Example responses
|
|
|
|
> 200 Response
|
|
|
|
```json
|
|
{
|
|
"count": 0,
|
|
"results": [
|
|
{
|
|
"api_key_id": "string",
|
|
"client": "string",
|
|
"ended_at": "2019-08-24T14:15:22Z",
|
|
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
|
|
"initiator": {
|
|
"avatar_url": "http://example.com",
|
|
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
|
|
"name": "string",
|
|
"username": "string"
|
|
},
|
|
"metadata": {
|
|
"property1": null,
|
|
"property2": null
|
|
},
|
|
"model": "string",
|
|
"provider": "string",
|
|
"started_at": "2019-08-24T14:15:22Z",
|
|
"token_usages": [
|
|
{
|
|
"created_at": "2019-08-24T14:15:22Z",
|
|
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
|
|
"input_tokens": 0,
|
|
"interception_id": "34d9b688-63ad-46f4-88b5-665c1e7f7824",
|
|
"metadata": {
|
|
"property1": null,
|
|
"property2": null
|
|
},
|
|
"output_tokens": 0,
|
|
"provider_response_id": "string"
|
|
}
|
|
],
|
|
"tool_usages": [
|
|
{
|
|
"created_at": "2019-08-24T14:15:22Z",
|
|
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
|
|
"injected": true,
|
|
"input": "string",
|
|
"interception_id": "34d9b688-63ad-46f4-88b5-665c1e7f7824",
|
|
"invocation_error": "string",
|
|
"metadata": {
|
|
"property1": null,
|
|
"property2": null
|
|
},
|
|
"provider_response_id": "string",
|
|
"server_url": "string",
|
|
"tool": "string"
|
|
}
|
|
],
|
|
"user_prompts": [
|
|
{
|
|
"created_at": "2019-08-24T14:15:22Z",
|
|
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
|
|
"interception_id": "34d9b688-63ad-46f4-88b5-665c1e7f7824",
|
|
"metadata": {
|
|
"property1": null,
|
|
"property2": null
|
|
},
|
|
"prompt": "string",
|
|
"provider_response_id": "string"
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
```
|
|
|
|
### Responses
|
|
|
|
| Status | Meaning | Description | Schema |
|
|
|--------|---------------------------------------------------------|-------------|----------------------------------------------------------------------------------------------------|
|
|
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.AIBridgeListInterceptionsResponse](schemas.md#codersdkaibridgelistinterceptionsresponse) |
|
|
|
|
To perform this operation, you must be authenticated. [Learn more](authentication.md).
|
|
|
|
## List AI Bridge models
|
|
|
|
### Code samples
|
|
|
|
```shell
|
|
# Example request using curl
|
|
curl -X GET http://coder-server:8080/api/v2/aibridge/models \
|
|
-H 'Accept: application/json' \
|
|
-H 'Coder-Session-Token: API_KEY'
|
|
```
|
|
|
|
`GET /aibridge/models`
|
|
|
|
### 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-bridge-models-responseschema">Response Schema</h3>
|
|
|
|
To perform this operation, you must be authenticated. [Learn more](authentication.md).
|
|
|
|
## List AI Bridge sessions
|
|
|
|
### Code samples
|
|
|
|
```shell
|
|
# Example request using curl
|
|
curl -X GET http://coder-server:8080/api/v2/aibridge/sessions \
|
|
-H 'Accept: application/json' \
|
|
-H 'Coder-Session-Token: API_KEY'
|
|
```
|
|
|
|
`GET /aibridge/sessions`
|
|
|
|
### Parameters
|
|
|
|
| Name | In | Type | Required | Description |
|
|
|--------------------|-------|---------|----------|--------------------------------------------------------------------------------------------------------------------------------------------|
|
|
| `q` | query | string | false | Search query in the format `key:value`. Available keys are: initiator, provider, 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_prompt": "string",
|
|
"metadata": {
|
|
"property1": null,
|
|
"property2": null
|
|
},
|
|
"models": [
|
|
"string"
|
|
],
|
|
"providers": [
|
|
"string"
|
|
],
|
|
"started_at": "2019-08-24T14:15:22Z",
|
|
"threads": 0,
|
|
"token_usage_summary": {
|
|
"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).
|