# Conversations

> Create and continue API conversations, page through their history and delete them.

Source: https://docs.corfedo.ai/connect/api/ai/conversations/

A conversation stores messages and their runs in Corfedo. Start one by omitting `conversationId` from a message. Continue by sending a new message with the returned ID and a new `clientMessageId`.

```ts
const first = await client.ai.send({
  clientMessageId: crypto.randomUUID(),
  text: 'Where are search queries parsed?',
});
if (first.status !== 'ended') throw new Error('Follow the first run before continuing');

const next = await client.ai.send({
  conversationId: first.conversationId,
  clientMessageId: crypto.randomUUID(),
  text: 'Which modules call that parser?',
});
```

Only one run can be active in a conversation. Sending another message while it is active returns `conversation_busy`. A run waiting for client tools still occupies the conversation. Return its tool results or cancel it before starting another message.

## Read history

```ts
const page = await client.ai.listConversations({ limit: 20 });
for (const item of page.conversations) console.log(item);
if (page.nextCursor) {
  const nextPage = await client.ai.listConversations({ limit: 20, cursor: page.nextCursor });
}

const history = await client.ai.getConversation(first.conversationId, { limit: 20 });
console.log(history);
```

The list is ordered by most recent activity. Pass the opaque `nextCursor` back as `cursor`. Conversation reads return messages with their runs, outcomes, final answers and citation maps. To read earlier messages, pass `earlierBeforeOrdinal` back as `beforeOrdinal`. See the [list](https://docs.corfedo.ai/reference/api/ai/listAiConversations/) and [read](https://docs.corfedo.ai/reference/api/ai/getAiConversation/) schemas for bounds.

## Source boundaries

The API lists, reads and deletes only API conversations available to the caller. Web and Slack conversations continue in their own channels. Sending a message to another source returns `other_source`. Reading, deleting, reattaching to or cancelling a Web or Slack conversation's run through this API returns `not_found`.

## Delete

```ts
await client.ai.deleteConversation(first.conversationId);
```

The [delete endpoint](https://docs.corfedo.ai/reference/api/ai/deleteAiConversation/) returns HTTP 204 on success. Use the [CLI conversation commands](https://docs.corfedo.ai/connect/cli/conversations/) for terminal access.
