Replace a chat's messages

post/v1/chat/update

Retired. This endpoint answers 410 Gone and no longer works. It is documented for reference only; use the v2 agent API's Chat instead.

Overwrite the entire message history of a chat with the array you send. Use it to prune, correct or restructure a conversation; sending [] empties the chat.

Unlike Send a message, no normalization is applied here: every message must already be in a valid shape. In particular an output_status part must be resolved or needs_clarification, and every slot in an output_slots part needs a string id. Slots are also checked against the stored slot rules on save (a search slot's query must be 6–120 characters, slot and fit values must be from their enums); a violation there is rejected with 422 and a details array naming each offending path.

Private keyapi.v1.chat.updateNo demoDeprecated

Request body

application/jsonrequired
chatIdstring (uuid)required

Id of the chat to overwrite.

e.g. "3f0c2a4e-8b1d-4c6a-9e2f-7a5b1c0d9e88"
array<ChatMessage>required

The complete new thread. May be empty. Not normalized — every message must already be valid.

rolestringrequired

Who wrote the message. system messages are passed to the model verbatim.

One ofuserassistantsystem
e.g. "user"
string | array<ChatMessageContentPart>required

Plain text, or an array of content parts.

Response

200The messages were replaced.
chatIdstring (uuid)required

Id of the chat that was updated.

e.g. "3f0c2a4e-8b1d-4c6a-9e2f-7a5b1c0d9e88"
messagesCountintegerrequired

Number of messages now stored.

e.g. 2

Errors

42

Every error is JSON with a single error string unless noted. Match on the status code; the message is for humans.

400
Request body must be valid JSON.

The request body could not be parsed as JSON.

400
Request body must be a JSON object.

The request body is empty, or parsed to something other than a JSON object (for example an array or a string).

404
Chat not found or you do not have permission to access it.

No chat with that id belongs to the organization.

410
This endpoint has been retired (v1/chat/update).

Always, for API callers. This check runs before authentication and consumes no quota.

422
The 'chatId' field must be provided as a non-empty string.

chatId is missing, empty, or not a string.

422
A valid chatId is required.

chatId is only whitespace.

422
The 'messages' field must be provided as an array.

messages is missing or not an array.

422
Message at index <n> must be an object.

An entry of messages is not an object.

422
Message at index <n> must have a 'role' field.

A message has no string role.

422
Message at index <n> has invalid role '<role>'. Must be one of: user, assistant, system.

role is anything other than user, assistant or system.

422
Message at index <n> must have a 'content' field.

content is missing or null.

422
Message at index <n> has empty content array. Must have at least one content part.

content is an empty array.

422
Message at index <n> has invalid content. Must be either a string or an array of content parts.

content is neither a string nor an array.

422
Message at index <n>: Content part at index <i> must be an object.

A content part is not an object.

422
Message at index <n>: Content part at index <i> must have a 'type' field.

A content part has no string type.

422
Message at index <n>: Content part at index <i> has invalid type '<type>'. Must be one of: input_text, output_text, input_image, output_slots, output_status.

type is not one of the five content part types.

422
Message at index <n>: Content part at index <i> with type '<type>' must have a 'text' property.

An input_text or output_text part has no string text.

422
Message at index <n>: Content part at index <i> with type '<type>' should not have '<field>' property.

A part carries a field that belongs to another type (for example image_url on an input_text part, or text on an output_slots part).

422
Message at index <n>: Content part at index <i> with type 'input_image' must have an 'image_url' string property.

An input_image part has no string image_url.

422
Message at index <n>: Content part at index <i> with type 'output_slots' must have a 'slots' array property.

An output_slots part has no slots array.

422
Message at index <n>: Content part at index <i>: slot at index <j> must be an object.

An entry of slots is not an object.

422
Message at index <n>: Content part at index <i>: slot at index <j> must have an 'id' string property.

A slot has no string id.

422
Message at index <n>: Content part at index <i> with type 'output_status' must have a 'status' string property.

An output_status part has no string status.

422
Message at index <n>: Content part at index <i> with type 'output_status' has invalid status '<status>'. Must be one of: resolved, needs_clarification.

status is any other value, including transient markers such as streaming.

422
Validation failed.

The messages passed the checks above but the stored slot rules rejected them on save (for example a search slot whose query is shorter than 6 characters). details lists each offending path with its message.

{
  "error": "Validation failed.",
  "details": [
    {
      "path": "messages.1.content.1.slots.0.query",
      "message": "Path `query` (`tee`) is shorter than the minimum allowed length (6)."
    }
  ]
}
curl -X POST "https://stylor.ai/api/v1/chat/update" \
  -H "Authorization: Bearer $STYLOR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "chatId": "3f0c2a4e-8b1d-4c6a-9e2f-7a5b1c0d9e88",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "input_text",
          "text": "I need a smart-casual outfit for a rooftop dinner."
        }
      ]
    },
    {
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "For a rooftop dinner I'\''d pair a silk slip dress with a cropped leather jacket."
        },
        {
          "type": "output_slots",
          "slots": [
            {
              "id": "8066a68a-a39e-4d3e-993a-3887f6245032",
              "type": "search",
              "slot": "dress",
              "query": "black silk slip dress",
              "filters": {
                "color_family": [
                  "black"
                ],
                "family": [
                  "dress"
                ],
                "exclude_terms": [],
                "boost_terms": [
                  "silk"
                ]
              },
              "results": []
            }
          ]
        },
        {
          "type": "output_status",
          "status": "resolved"
        }
      ]
    }
  ]
}'
Response · 200
{
  "chatId": "3f0c2a4e-8b1d-4c6a-9e2f-7a5b1c0d9e88",
  "messagesCount": 2
}