> For the complete documentation index, see [llms.txt](https://docs.scaleconnect.com.au/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.scaleconnect.com.au/api/rest-api/scaleapp-rest-api/chat.md).

# Chat

AI chat interactions and conversation history

## Send chat message to AI assistant

> Sends a message to the AI assistant and receives a response.

```json
{"openapi":"3.0.0","info":{"title":"ScaleApp API","version":"1.0.0"},"tags":[{"name":"Chat","description":"AI chat interactions and conversation history"}],"security":[{"bearer":[]}],"components":{"securitySchemes":{"bearer":{"scheme":"bearer","bearerFormat":"JWT","type":"http"}},"schemas":{"ChatRequestDto":{"type":"object","properties":{"messages":{"description":"Array of chat messages forming the conversation","type":"array","items":{"$ref":"#/components/schemas/ChatMessageDto"}},"guidance":{"type":"string","description":"Optional guidance for AI response"},"context":{"type":"object","description":"Optional context data for the conversation"}},"required":["messages"]},"ChatMessageDto":{"type":"object","properties":{"role":{"type":"string","description":"Message role","enum":["user","assistant","system"]},"content":{"type":"string","description":"Message content"}},"required":["role","content"]},"ChatMessageResponseDto":{"type":"object","properties":{"id":{"type":"string","description":"Message identifier"},"message":{"type":"string","description":"Message content"},"timestamp":{"type":"string","description":"Message timestamp","format":"date-time"},"type":{"type":"string","description":"Message sender type","enum":["user","assistant"]}},"required":["id","message","timestamp","type"]}}},"paths":{"/v1/ai-chat":{"post":{"description":"Sends a message to the AI assistant and receives a response.","operationId":"ChatController_chat_v1","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ChatRequestDto"}}}},"responses":{"200":{"description":"Successfully received AI response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ChatMessageResponseDto"}}}},"400":{"description":"Bad Request"},"401":{"description":"Unauthorized"}},"summary":"Send chat message to AI assistant","tags":["Chat"]}}}}
```

## List chat sessions for a user

> Returns all chat sessions for a user with the last user message as a preview.

```json
{"openapi":"3.0.0","info":{"title":"ScaleApp API","version":"1.0.0"},"tags":[{"name":"Chat","description":"AI chat interactions and conversation history"}],"security":[{"bearer":[]}],"components":{"securitySchemes":{"bearer":{"scheme":"bearer","bearerFormat":"JWT","type":"http"}}},"paths":{"/v1/ai-chat/sessions/{userId}":{"get":{"description":"Returns all chat sessions for a user with the last user message as a preview.","operationId":"ChatController_sessionsByUser_v1","parameters":[{"name":"userId","required":true,"in":"path","schema":{"type":"string"}}],"responses":{"200":{"description":"Successfully retrieved sessions"},"401":{"description":"Unauthorized"}},"summary":"List chat sessions for a user","tags":["Chat"]}}}}
```

## Get AI assistant messages by user ID

> Returns AI assistant chat history for a specific client user ID, in chronological order.

```json
{"openapi":"3.0.0","info":{"title":"ScaleApp API","version":"1.0.0"},"tags":[{"name":"Chat","description":"AI chat interactions and conversation history"}],"security":[{"bearer":[]}],"components":{"securitySchemes":{"bearer":{"scheme":"bearer","bearerFormat":"JWT","type":"http"}}},"paths":{"/v1/ai-chat/user/{userId}/messages":{"get":{"description":"Returns AI assistant chat history for a specific client user ID, in chronological order.","operationId":"ChatController_messagesByUserId_v1","parameters":[{"name":"userId","required":true,"in":"path","schema":{"type":"string"}}],"responses":{"200":{"description":"Successfully retrieved sessions with messages"},"401":{"description":"Unauthorized"}},"summary":"Get AI assistant messages by user ID","tags":["Chat"]}}}}
```

## Get full messages for a chat session

> Returns all messages for a specific chatId in chronological order.

```json
{"openapi":"3.0.0","info":{"title":"ScaleApp API","version":"1.0.0"},"tags":[{"name":"Chat","description":"AI chat interactions and conversation history"}],"security":[{"bearer":[]}],"components":{"securitySchemes":{"bearer":{"scheme":"bearer","bearerFormat":"JWT","type":"http"}}},"paths":{"/v1/ai-chat/messages/{chatId}":{"get":{"description":"Returns all messages for a specific chatId in chronological order.","operationId":"ChatController_messagesByChatId_v1","parameters":[{"name":"chatId","required":true,"in":"path","schema":{"type":"string"}},{"name":"limit","required":false,"in":"query","schema":{"type":"number"}},{"name":"page","required":false,"in":"query","schema":{"type":"number"}}],"responses":{"200":{"description":"Successfully retrieved messages"},"401":{"description":"Unauthorized"}},"summary":"Get full messages for a chat session","tags":["Chat"]}}}}
```

## PATCH /v1/ai-chat/{chatId}/messages/metadata

> Update persisted rich metadata for AI messages

```json
{"openapi":"3.0.0","info":{"title":"ScaleApp API","version":"1.0.0"},"tags":[{"name":"Chat","description":"AI chat interactions and conversation history"}],"security":[{"bearer":[]}],"components":{"securitySchemes":{"bearer":{"scheme":"bearer","bearerFormat":"JWT","type":"http"}},"schemas":{"UpdateChatMessageMetadataDto":{"type":"object","properties":{}}}},"paths":{"/v1/ai-chat/{chatId}/messages/metadata":{"patch":{"operationId":"ChatController_updateMessageMetadata_v1","parameters":[{"name":"chatId","required":true,"in":"path","schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateChatMessageMetadataDto"}}}},"responses":{"200":{"description":"Metadata updated"},"404":{"description":"Chat not found for this reader"}},"summary":"Update persisted rich metadata for AI messages","tags":["Chat"]}}}}
```

## Delete an AI chat session

> Deletes a single AI chat session and all of its messages. Works for both client and broker chats. The owner is taken from the authenticated request, so a caller can only delete their own chats.

```json
{"openapi":"3.0.0","info":{"title":"ScaleApp API","version":"1.0.0"},"tags":[{"name":"Chat","description":"AI chat interactions and conversation history"}],"security":[{"bearer":[]}],"components":{"securitySchemes":{"bearer":{"scheme":"bearer","bearerFormat":"JWT","type":"http"}}},"paths":{"/v1/ai-chat/{chatId}":{"delete":{"description":"Deletes a single AI chat session and all of its messages. Works for both client and broker chats. The owner is taken from the authenticated request, so a caller can only delete their own chats.","operationId":"ChatController_deleteChat_v1","parameters":[{"name":"chatId","required":true,"in":"path","schema":{"type":"string"}}],"responses":{"200":{"description":"Successfully deleted the chat"},"401":{"description":"Unauthorized"},"404":{"description":"Chat not found for this owner"}},"summary":"Delete an AI chat session","tags":["Chat"]}}}}
```

## Rename an AI chat session

> Sets a custom name on a chat session so the history list shows it instead of the generated title.

```json
{"openapi":"3.0.0","info":{"title":"ScaleApp API","version":"1.0.0"},"tags":[{"name":"Chat","description":"AI chat interactions and conversation history"}],"security":[{"bearer":[]}],"components":{"securitySchemes":{"bearer":{"scheme":"bearer","bearerFormat":"JWT","type":"http"}},"schemas":{"RenameChatSessionDto":{"type":"object","properties":{"title":{"type":"string","description":"New name for the chat session"}},"required":["title"]}}},"paths":{"/v1/ai-chat/{chatId}":{"patch":{"description":"Sets a custom name on a chat session so the history list shows it instead of the generated title.","operationId":"ChatController_renameChat_v1","parameters":[{"name":"chatId","required":true,"in":"path","schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RenameChatSessionDto"}}}},"responses":{"200":{"description":"Successfully renamed the chat"},"401":{"description":"Unauthorized"},"404":{"description":"Chat not found for this owner"}},"summary":"Rename an AI chat session","tags":["Chat"]}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.scaleconnect.com.au/api/rest-api/scaleapp-rest-api/chat.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
