Files
coder/docs/reference/api/chat.md
Cian Johnston 544259b809 feat: add database tables and API routes for agentic chat feature (#17570)
Backend portion of experimental `AgenticChat` feature:
- Adds database tables for chats and chat messages
- Adds functionality to stream messages from LLM providers using
`kylecarbs/aisdk-go`
- Adds API routes with relevant functionality (list, create, update
chats, insert chat message)
- Adds experiment `codersdk.AgenticChat`

---------

Co-authored-by: Kyle Carberry <kyle@carberry.com>
2025-05-02 17:29:57 +01:00

14 KiB
Generated

Chat

List chats

Code samples

# Example request using curl
curl -X GET http://coder-server:8080/api/v2/chats \
  -H 'Accept: application/json' \
  -H 'Coder-Session-Token: API_KEY'

GET /chats

Example responses

200 Response

[
  {
    "created_at": "2019-08-24T14:15:22Z",
    "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
    "title": "string",
    "updated_at": "2019-08-24T14:15:22Z"
  }
]

Responses

Status Meaning Description Schema
200 OK OK array of codersdk.Chat

Response Schema

Status Code 200

Name Type Required Restrictions Description
[array item] array false
» created_at string(date-time) false
» id string(uuid) false
» title string false
» updated_at string(date-time) false

To perform this operation, you must be authenticated. Learn more.

Create a chat

Code samples

# Example request using curl
curl -X POST http://coder-server:8080/api/v2/chats \
  -H 'Accept: application/json' \
  -H 'Coder-Session-Token: API_KEY'

POST /chats

Example responses

201 Response

{
  "created_at": "2019-08-24T14:15:22Z",
  "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
  "title": "string",
  "updated_at": "2019-08-24T14:15:22Z"
}

Responses

Status Meaning Description Schema
201 Created Created codersdk.Chat

To perform this operation, you must be authenticated. Learn more.

Get a chat

Code samples

# Example request using curl
curl -X GET http://coder-server:8080/api/v2/chats/{chat} \
  -H 'Accept: application/json' \
  -H 'Coder-Session-Token: API_KEY'

GET /chats/{chat}

Parameters

Name In Type Required Description
chat path string true Chat ID

Example responses

200 Response

{
  "created_at": "2019-08-24T14:15:22Z",
  "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
  "title": "string",
  "updated_at": "2019-08-24T14:15:22Z"
}

Responses

Status Meaning Description Schema
200 OK OK codersdk.Chat

To perform this operation, you must be authenticated. Learn more.

Get chat messages

Code samples

# Example request using curl
curl -X GET http://coder-server:8080/api/v2/chats/{chat}/messages \
  -H 'Accept: application/json' \
  -H 'Coder-Session-Token: API_KEY'

GET /chats/{chat}/messages

Parameters

Name In Type Required Description
chat path string true Chat ID

Example responses

200 Response

[
  {
    "annotations": [
      null
    ],
    "content": "string",
    "createdAt": [
      0
    ],
    "experimental_attachments": [
      {
        "contentType": "string",
        "name": "string",
        "url": "string"
      }
    ],
    "id": "string",
    "parts": [
      {
        "data": [
          0
        ],
        "details": [
          {
            "data": "string",
            "signature": "string",
            "text": "string",
            "type": "string"
          }
        ],
        "mimeType": "string",
        "reasoning": "string",
        "source": {
          "contentType": "string",
          "data": "string",
          "metadata": {
            "property1": null,
            "property2": null
          },
          "uri": "string"
        },
        "text": "string",
        "toolInvocation": {
          "args": null,
          "result": null,
          "state": "call",
          "step": 0,
          "toolCallId": "string",
          "toolName": "string"
        },
        "type": "text"
      }
    ],
    "role": "string"
  }
]

Responses

Status Meaning Description Schema
200 OK OK array of aisdk.Message

Response Schema

Status Code 200

Name Type Required Restrictions Description
[array item] array false
» annotations array false
» content string false
» createdAt array false
» experimental_attachments array false
»» contentType string false
»» name string false
»» url string false
» id string false
» parts array false
»» data array false
»» details array false
»»» data string false
»»» signature string false
»»» text string false
»»» type string false
»» mimeType string false Type: "file"
»» reasoning string false Type: "reasoning"
»» source aisdk.SourceInfo false Type: "source"
»»» contentType string false
»»» data string false
»»» metadata object false
»»»» [any property] any false
»»» uri string false
»» text string false Type: "text"
»» toolInvocation aisdk.ToolInvocation false Type: "tool-invocation"
»»» args any false
»»» result any false
»»» state aisdk.ToolInvocationState false
»»» step integer false
»»» toolCallId string false
»»» toolName string false
»» type aisdk.PartType false
» role string false

Enumerated Values

Property Value
state call
state partial-call
state result
type text
type reasoning
type tool-invocation
type source
type file
type step-start

To perform this operation, you must be authenticated. Learn more.

Create a chat message

Code samples

# Example request using curl
curl -X POST http://coder-server:8080/api/v2/chats/{chat}/messages \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'Coder-Session-Token: API_KEY'

POST /chats/{chat}/messages

Body parameter

{
  "message": {
    "annotations": [
      null
    ],
    "content": "string",
    "createdAt": [
      0
    ],
    "experimental_attachments": [
      {
        "contentType": "string",
        "name": "string",
        "url": "string"
      }
    ],
    "id": "string",
    "parts": [
      {
        "data": [
          0
        ],
        "details": [
          {
            "data": "string",
            "signature": "string",
            "text": "string",
            "type": "string"
          }
        ],
        "mimeType": "string",
        "reasoning": "string",
        "source": {
          "contentType": "string",
          "data": "string",
          "metadata": {
            "property1": null,
            "property2": null
          },
          "uri": "string"
        },
        "text": "string",
        "toolInvocation": {
          "args": null,
          "result": null,
          "state": "call",
          "step": 0,
          "toolCallId": "string",
          "toolName": "string"
        },
        "type": "text"
      }
    ],
    "role": "string"
  },
  "model": "string",
  "thinking": true
}

Parameters

Name In Type Required Description
chat path string true Chat ID
body body codersdk.CreateChatMessageRequest true Request body

Example responses

200 Response

[
  null
]

Responses

Status Meaning Description Schema
200 OK OK array of undefined

Response Schema

To perform this operation, you must be authenticated. Learn more.