> For the complete documentation index, see [llms.txt](https://docs.gitloom.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gitloom.cloud/api-reference/conversations.md). Agents can also search and read this documentation through its [MCP server](https://docs.gitloom.cloud/~gitbook/mcp).

# Conversations

Durable chat history with a context window that provably fits, and compaction that hands its turns to memory.

Every message is kept forever; these routes decide what a client is given back. The default read is cheap — the last compaction's summary plus everything since — not the whole transcript. This is what the [TypeScript SDK](https://docs.gitloom.cloud/documentation/content/sdk#conversations-that-cannot-overflow)'s conversation object wraps.

#### POST /v1/conversations

| field            | required | notes                                                                                      |
| ---------------- | -------- | ------------------------------------------------------------------------------------------ |
| `id`             | yes      | yours to choose — so a conversation can be found again without storing our id alongside it |
| `namespace`      | no       | defaults to `default`; must exist first                                                    |
| `title`, `model` | no       |                                                                                            |

```json
{"id": "chat-123", "namespace": "user-8213", "branch": "main", "next_seq": 0}
```

`409 exists` if the id is taken; `400 no_namespace` if the namespace doesn't exist yet.

#### GET /v1/conversations

Lists up to 100 conversations for the account.

#### GET /v1/conversations/{id}

| param    | notes                                                                                                            |
| -------- | ---------------------------------------------------------------------------------------------------------------- |
| `branch` | defaults to the conversation's active branch                                                                     |
| `full`   | `1`/`true` returns every message, ignoring compactions                                                           |
| `at`     | a sequence number — previews the conversation as it stood there, for reviewing a rewind before committing to one |

```json
{
  "id": "chat-123", "branch": "main", "next_seq": 42, "model": "gpt-5",
  "namespace": "user-8213", "truncated": true,
  "compaction": {"seq": 30, "summary": "...", "from_seq": 0, "to_seq": 30},
  "messages": [{"role": "user", "content": "...", "tokens": 12}]
}
```

#### POST /v1/conversations/{id}/messages

Appends up to 500 messages at once.

| field      | required                                                            |
| ---------- | ------------------------------------------------------------------- |
| `messages` | yes — `{role, content, name?, tool_calls?, tool_call_id?, tokens?}` |
| `branch`   | no — defaults to the active branch                                  |

```json
{"branch": "main", "written": 2, "next_seq": 44}
```

`409 sequence_conflict` if another writer appended first — reload and retry rather than overwrite silently.

#### POST /v1/conversations/{id}/compact

Records a locally-produced summary and hands the turns it replaced to ingestion — the join that makes GitLoom a context handler, not just a store: the moment turns leave the model's window is the moment they become memory.

| field                | required | notes                                                                          |
| -------------------- | -------- | ------------------------------------------------------------------------------ |
| `summary`            | yes      | produced by your own model — GitLoom never sees the conversation to compact it |
| `from_seq`, `to_seq` | yes      | the range this summary covers                                                  |
| `ingest`             | no       | defaults to `true`; set `false` to compact without queuing extraction          |

```json
{"branch": "main", "compacted": true, "queued": 12}
```

If ingestion fails to queue, the compaction is still recorded (`"queued": 0, "ingest_error": "..."`) — a scheduled sweep picks the turns up later rather than losing the compaction over a transient queue error.

#### POST /v1/conversations/{id}/rewind

Forks a branch at a point in the conversation; nothing already stored is destroyed.

| field            | required                             |
| ---------------- | ------------------------------------ |
| `to`             | yes — the sequence number to fork at |
| `branch`, `name` | no                                   |

```json
{"branch": "main-44", "forked_from": "main", "next_seq": 30}
```

`409 branch_exists` if a branch already forks at that exact point — pass `name` to make a second one.

#### POST /v1/conversations/{id}/ingest

Queues a range for extraction on demand, independent of compaction.

```json
{"queued": 8, "branch": "main"}
```

#### GET /v1/conversations/{id}/branches

```json
{"branches": [{"name": "main", "next_seq": 44}, {"name": "main-30", "next_seq": 12}]}
```


---

# 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.gitloom.cloud/api-reference/conversations.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.
