---
title: "$client->chats"
description: "Every method in this namespace: its signature, its parameters, what it returns and an example."
url: "https://openemail.uk/docs/php/reference/chats"
area: "PHP"
category: "Reference"
---

# $client->chats

Every method in this namespace: its signature, its parameters, what it returns and an example.

## Methods

The conversations held with the assistant in the app: list and search them, read one, rename it and delete it. Only the workspace owner reaches them.

### `chats->list`

List the assistant chats

```php
list(
    ?string $q = null,
    ?string $sort = null,
    ?int $limit = null,
    ?string $cursor = null,
    ?string $apiKey = null,
): Page
```

Returns one page of the conversations held with the assistant in the app, newest first, as its Chats page lists them, each with its title, how many messages it holds and when it last changed.

Only the workspace owner reaches the chats: an API key, or an access token the owner connected with every address. A token acting for a member is 403 `owner_only`, and a key or token limited to particular addresses or domains is 422 `capability_unsupported`.

Scopes: `threads:read`.

**Parameters**

- `q` (`string`): Searches the titles.
- `sort` (`string`): `newest` (the default) or `oldest` by the last change, or `title`, as in `OpenEmail\Constants\ChatSorts`. A cursor carries on in the order it was handed out in.
- `limit` (`int`): Page size, from 1 to 100. The server defaults to 25.
- `cursor` (`string`): The `nextCursor` of the previous page. Leave it out for the first page.
- `apiKey` (`string`): Overrides the client's API key for this call only.

**Returns**

A `Page` of arrays with `items`, `hasMore` and `nextCursor`. Each item has `id`, `title`, `kind`, `messageCount` and `updatedAt`.

**Example**

```php
use OpenEmail\Constants\ChatSorts;

$page = $client->chats->list(q: 'invoices', sort: ChatSorts::NEWEST, limit: 20);

foreach ($page as $chat) {
    echo $chat['title'], ' (', $chat['messageCount'], ' messages)', PHP_EOL;
}

if ($page->hasMore) {
    $next = $client->chats->list(q: 'invoices', cursor: $page->nextCursor);

    echo $next->items[0]['title'] ?? 'nothing more', PHP_EOL;
}
```

**Notes**

- A cursor that names nothing in this list is 400 `invalid_cursor`.

Also available in: API [`GET /chats`](https://openemail.uk/docs/api/reference/chats#get-chats); TypeScript [`chats.list()`](https://openemail.uk/docs/sdk/reference/chats#list); Python [`chats.list()`](https://openemail.uk/docs/python/reference/chats#list); Ruby [`chats.list`](https://openemail.uk/docs/ruby/reference/chats#list); CLI [`openemail chats list`](https://openemail.uk/docs/cli/reference/chats#chats-list).

### `chats->listAll`

Collect every chat into one array

```php
listAll(
    ?string $q = null,
    ?string $sort = null,
    ?int $limit = null,
    ?string $cursor = null,
    ?string $apiKey = null,
): array
```

Walks every page of `list` and returns every chat, in the order `sort:` names. One request per page, with the same filters on each.

Scopes: `threads:read`.

**Parameters**

- `q` (`string`): Searches the titles.
- `sort` (`string`): `newest` (the default) or `oldest` by the last change, or `title`, as in `OpenEmail\Constants\ChatSorts`. A cursor carries on in the order it was handed out in.
- `limit` (`int`): Page size for each request, from 1 to 100. The server defaults to 25.
- `cursor` (`string`): Starts the walk after this cursor instead of the first page.
- `apiKey` (`string`): Overrides the client API key for every page of this walk.

**Returns**

A list of arrays holding every chat.

**Example**

```php
$chats = $client->chats->listAll(q: 'invoices');

echo implode(PHP_EOL, array_column($chats, 'title')), PHP_EOL;
```

**Notes**

- If any page fails the call throws and the rows already fetched are discarded.

Also available in: API [`GET /chats`](https://openemail.uk/docs/api/reference/chats#get-chats); TypeScript [`chats.listAll()`](https://openemail.uk/docs/sdk/reference/chats#listAll); Python [`chats.list_all()`](https://openemail.uk/docs/python/reference/chats#listAll); Ruby [`chats.list_all`](https://openemail.uk/docs/ruby/reference/chats#listAll).

### `chats->iterate`

Stream the chats one at a time

```php
iterate(
    ?string $q = null,
    ?string $sort = null,
    ?int $limit = null,
    ?string $cursor = null,
    ?string $apiKey = null,
): Generator
```

Returns a `Generator` that yields one chat at a time, in the order `sort:` names, and requests the next page only once the current one is drained. Nothing is fetched until you consume it, and breaking out of the loop stops the requests.

Scopes: `threads:read`.

**Parameters**

- `q` (`string`): Searches the titles.
- `sort` (`string`): `newest` (the default) or `oldest` by the last change, or `title`, as in `OpenEmail\Constants\ChatSorts`. A cursor carries on in the order it was handed out in.
- `limit` (`int`): Page size for each request, from 1 to 100. The server defaults to 25.
- `cursor` (`string`): Starts the walk after this cursor instead of the first page.
- `apiKey` (`string`): Overrides the client API key for every page of this walk.

**Returns**

A `Generator` that yields one chat array per step.

**Example**

```php
use OpenEmail\Constants\ChatSorts;

foreach ($client->chats->iterate(sort: ChatSorts::TITLE) as $chat) {
    echo $chat['title'], ' ', $chat['updatedAt'], PHP_EOL;
}
```

**Notes**

- Each page is one request, so a long walk makes many.

Also available in: API [`GET /chats`](https://openemail.uk/docs/api/reference/chats#get-chats); TypeScript [`chats.iterate()`](https://openemail.uk/docs/sdk/reference/chats#iterate); Python [`chats.iterate()`](https://openemail.uk/docs/python/reference/chats#iterate); Ruby [`chats.iterate`](https://openemail.uk/docs/ruby/reference/chats#iterate).

### `chats->get`

Retrieve a chat

```php
get(string $id, ?string $apiKey = null): array
```

Returns one chat with the assistant by its id: its title, how many messages it holds and when it last changed.

Only the workspace owner reaches the chats: an API key, or an access token the owner connected with every address. A token acting for a member is 403 `owner_only`, and a key or token limited to particular addresses or domains is 422 `capability_unsupported`.

Scopes: `threads:read`.

**Parameters**

- `id` (`string`, required): The chat id from `list`.
- `apiKey` (`string`): Overrides the client's API key for this call only.

**Returns**

An array with `id`, `title`, `kind`, `messageCount` and `updatedAt`.

**Example**

```php
$chat = $client->chats->get('8f3c2a71-5e9d-4b06-a1c4-7d2e9f0b3a65');

echo $chat['title'], ', last changed ', $chat['updatedAt'], PHP_EOL;
```

**Notes**

- An unknown id is a 404.

Also available in: API [`GET /chats/{id}`](https://openemail.uk/docs/api/reference/chats#get-chats-id); TypeScript [`chats.get()`](https://openemail.uk/docs/sdk/reference/chats#get); Python [`chats.get()`](https://openemail.uk/docs/python/reference/chats#get); Ruby [`chats.get`](https://openemail.uk/docs/ruby/reference/chats#get); CLI [`openemail chats get`](https://openemail.uk/docs/cli/reference/chats#chats-get).

### `chats->rename`

Rename a chat

```php
rename(string $id, string $title, ?string $apiKey = null): array
```

Gives a chat with the assistant a new title, up to 120 characters, and returns the chat as it is now.

Only the workspace owner reaches the chats: an API key, or an access token the owner connected with every address. A token acting for a member is 403 `owner_only`, and a key or token limited to particular addresses or domains is 422 `capability_unsupported`.

Scopes: `threads:write`.

**Parameters**

- `id` (`string`, required): The chat id from `list`.
- `title` (`string`, required): The new title, from 1 to 120 characters.
- `apiKey` (`string`): Overrides the client's API key for this call only.

**Returns**

The same array as `chats->get`, with the new `title`.

**Example**

```php
$chat = $client->chats->rename('8f3c2a71-5e9d-4b06-a1c4-7d2e9f0b3a65', 'Quarterly invoices');

echo $chat['title'], PHP_EOL;
```

**Notes**

- An unknown id is a 404.

Also available in: API [`PATCH /chats/{id}`](https://openemail.uk/docs/api/reference/chats#patch-chats-id); TypeScript [`chats.rename()`](https://openemail.uk/docs/sdk/reference/chats#rename); Python [`chats.rename()`](https://openemail.uk/docs/python/reference/chats#rename); Ruby [`chats.rename`](https://openemail.uk/docs/ruby/reference/chats#rename); CLI [`openemail chats rename`](https://openemail.uk/docs/cli/reference/chats#chats-rename).

### `chats->delete`

Delete a chat

```php
delete(string $id, ?string $apiKey = null): array
```

Deletes a chat with the assistant and every message in it, for good. Nothing the assistant did in the mailbox is undone.

Only the workspace owner reaches the chats: an API key, or an access token the owner connected with every address. A token acting for a member is 403 `owner_only`, and a key or token limited to particular addresses or domains is 422 `capability_unsupported`.

Scopes: `threads:write`.

**Parameters**

- `id` (`string`, required): The chat id from `list`.
- `apiKey` (`string`): Overrides the client's API key for this call only.

**Returns**

An array with `object` set to `chat`, the `id` and `deleted` set to true.

**Example**

```php
use OpenEmail\Exception\NotFoundException;

try {
    $client->chats->delete('8f3c2a71-5e9d-4b06-a1c4-7d2e9f0b3a65');
} catch (NotFoundException) {
    echo 'Already gone', PHP_EOL;
}
```

**Notes**

- An unknown id is a 404, and so is a second call for the same chat.
- The SDK does not retry it.

Also available in: API [`DELETE /chats/{id}`](https://openemail.uk/docs/api/reference/chats#delete-chats-id); TypeScript [`chats.delete()`](https://openemail.uk/docs/sdk/reference/chats#delete); Python [`chats.delete()`](https://openemail.uk/docs/python/reference/chats#delete); Ruby [`chats.delete`](https://openemail.uk/docs/ruby/reference/chats#delete); CLI [`openemail chats delete`](https://openemail.uk/docs/cli/reference/chats#chats-delete).
