Skip to main content

Save the whole chat after a finished answer

PUT/v2/aissistant-chats/{chatId}
API version
v2
Request method
PUT
Operation ID
aissistant-save-chat

revision is the revision the chat was loaded with, 0 for a new chat. A revision that differs from the stored one answers 409, so a second device cannot overwrite a newer chat. A request body over 1 MiB (1048576 bytes) answers 413. A chat that could not be loaded again within 4 MiB minus a 64 KiB safety margin answers 400. Creating a chat beyond the per-user chat quota (200 chats by default) answers 429; updating an existing chat remains possible at the quota. messages must follow the AG-UI message schema, and image parts are refused: the client replaces every image with a text part before it saves. A message may nest at most 64 levels, the message object counting as level 1; a deeper one answers 400. turnMarks is optional and replaces the stored marks on every save ({} without it); each key must be the id of a message of the same save, else the save answers 400.

Request​

  • chatIdstring (uuid)required

    The chat's AG-UI threadId, a UUID the client creates.

    Example:"7f0c6a52-3a8e-4b8f-9d1e-2c4b5a6d7e8f"

Responses​

Format
application/json
Description

Saved; the chat's new revision.

  • revisioninteger (≥ 1)required
The first save of a new chat
Content-Type: application/json

{
"revision": 1
}
A later save of a chat that was loaded with revision 3
Content-Type: application/json

{
"revision": 4
}
{
"additionalProperties": false,
"example": {
"revision": 1
},
"properties": {
"revision": {
"minimum": 1,
"type": "integer"
}
},
"required": [
"revision"
],
"type": "object"
}

Usage examples​

$ curl \
--fail \
--location \
-X PUT \
-d '{"messages":[{"content":"How do I add a domain to project p-XXXXXX?","id":"msg-user-1","role":"user"}],"revision":0,"title":"Set up a domain for my project"}' \
-H "Authorization: Bearer $MITTWALD_API_TOKEN" \
-H 'Content-Type: application/json' \
https://api.mittwald.de/v2/aissistant-chats/f0f86186-0a5a-45b2-aa33-502777496347
import { MittwaldAPIV2Client } from "@mittwald/api-client";
import { assertStatus } from "@mittwald/api-client-commons";

const client = MittwaldAPIClient.newWithToken(process.env.MITTWALD_API_TOKEN);
const response = await client.aissistant.saveChat({
"chatId": "f0f86186-0a5a-45b2-aa33-502777496347",
"data": {
"messages": [
{
"content": "How do I add a domain to project p-XXXXXX?",
"id": "msg-user-1",
"role": "user"
}
],
"revision": 0,
"title": "Set up a domain for my project"
}
});

assertStatus(response, 200);

use \Mittwald\ApiClient\Generated\V2\Clients\AIssistant\SaveChat\SaveChatRequest;
use \Mittwald\ApiClient\Generated\V2\Clients\AIssistant\SaveChat\SaveChatRequestBody;

$client = MittwaldAPIClient::newWithToken(getenv('MITTWALD_API_TOKEN'));

// TODO: Please consult the properties and constructor signature of
// SaveChatRequestBody to learn how to construct a valid instance
$body = new SaveChatRequestBody(/* TODO: ... */);

$request = (new SaveChatRequest(
chatId: "f0f86186-0a5a-45b2-aa33-502777496347",
body: $body
));
$response = $client->aissistant()->saveChat($request);

var_dump($response->getBody();

On this page