---
title: "Compact a chat message history"
method: POST
path: "/api/chat/compact"
tags: ["Chat"]
---

# Compact a chat message history

`POST /api/chat/compact`

Compacts a conversation's message history by removing or summarizing older messages while preserving important context such as anchors and tool results.

## Request body

- CompactRequest — Request to compact a chat message history.
  - `keep_anchors` boolean — Whether to preserve anchor messages during compaction.
  - `max_tokens` integer — The maximum token budget for the compacted output.
  - `messages` ChatMessage[], required — The messages to compact.
    - `content` string, required — The text content of the message.
    - `role` string, required — The role of the message author (e.g., user, assistant, system).
  - `options` object — Advanced compaction options.
    - `enable_analytics` boolean — Enable analytics collection for compaction.
    - `enable_caching` boolean — Enable caching of compaction results.
    - `enable_llm_summarization` boolean — Enable LLM-based summarisation of dropped messages.
    - `enable_summarization` boolean — Enable rule-based summarisation of dropped messages.
    - `min_important_messages` integer — Minimum number of important messages to retain.
    - `preserve_schema_info` boolean — Keep messages containing schema information.
    - `preserve_tool_results` boolean — Keep messages containing tool results.
    - `token_counter_type` string — The token counting strategy to use.
  - `recent_window` integer — The number of recent messages to always preserve.

## Response `200`

Compacted message history.

- CompactResponse — Result of a chat compaction operation.
  - `compaction_info` object, required — Statistics about the compaction operation.
    - `anchor_count` integer — Number of anchor messages preserved.
    - `compacted_count` integer — Number of messages after compaction.
    - `compression_ratio` number — Ratio of output size to input size.
    - `dropped_count` integer — Number of messages dropped during compaction.
    - `original_count` integer — Number of messages before compaction.
    - `tokens_saved` integer — Estimated tokens saved by compaction.
  - `messages` ChatMessage[], required — The compacted messages.
    - `content` string, required — The text content of the message.
    - `role` string, required — The role of the message author (e.g., user, assistant, system).
  - `summary` object, required — A summary of the topics discussed in dropped messages.
    - `description` string — A prose description of the conversation context.
    - `tables` string[] — Database tables referenced in the conversation.
    - `tools` string[] — Tools used during the conversation.
    - `topics` string[] — Topic keywords extracted from the conversation.
  - `token_estimate` integer, required — Estimated token count of the compacted output.

## Other responses

- `401` — Missing or invalid authentication token.
- `403` — Insufficient permissions.

---

[API](https://skmtc.dev/pgedge/apis/pgedge-postgres-mcp-server-api.md) · [All operations](https://skmtc.dev/pgedge/apis/pgedge-postgres-mcp-server-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/pgedge/pgedge-postgres-mcp-server-api/revisions/6084bab46b1e/schema)
