# Your AI clients

The calling user’s own AI-client connections in the key’s organisation: status, access and today’s calls.

Its operations need the scope `ai_access.view`.

**Endpoints**

- `GET/v1/user/ai-clients`

## List your AI clients

GET/v1/user/ai-clients

Lists the AI clients the calling user connected in the key’s organisation, with their access, status and today’s calls; never another user’s connections and never another organisation’s. Filter by status and search text; sorts by one column. Pages by `page` and `per_page` (`limit` is the same as `per_page`); every page carries `current_page`, `per_page`, `last_page` and `total`.

Needs the scope `ai_access.view`.

### Query parameters

- `status` (array of strings or null): Only connections in one of these statuses: `active` (live now), `expired` (not revoked, past its expiry) or `revoked`. Absent lists every status. A list: repeat the parameter (`status=active&status=expired`) or send one value (`status=active`); `status[]=active` is accepted too. Values:`active``expired``revoked`(an open set: new values may be added)
- `search` (string or null): Only connections whose client name contains this text.
- `sort` (string or null): The column to sort by: `client_name`, `created_at` or `last_used_at`; a connection never used sorts last in both directions. Without one the newest comes first. Values:`client_name``created_at``last_used_at`(an open set: new values may be added)
- `direction` (string or null): The sort direction, `asc` (the default) or `desc`. Values:`asc``desc`(an open set: new values may be added)
- `limit` (integer or null): The same as `per_page`, kept for existing clients.
- `include_total` (string or null): Ignored: `total` is always present. Values:`true``false``1``0`(an open set: new values may be added)
- `per_page` (integer or null): How many items one page holds, from 1 to 100; 25 when omitted.
- `page` (integer or null): The page to read, from 1; 1 when omitted. A page past the last answers no rows.

### Returns

`200 OK`:

One page of the calling user’s own AI-client connections in the key’s organisation.

Each item of the page:

- `uuid` (string): The UUID of the connection.
- `client_name` (string): The name the AI client gave itself when it connected.
- `access` (string): What the client may do: `read` or `read_and_act`.
- `status` (string): One of `active` (live now), `expired` (not revoked, past its expiry) or `revoked`. Values:`active``expired``revoked`(an open set: new values may be added)
- `created_at` (integer): Epoch milliseconds. When the client was connected. An instant: epoch milliseconds, UTC.
- `expires_at` (integer or null): Epoch milliseconds. When the connection expires; null for one that never expires. An instant: epoch milliseconds, UTC.
- `last_used_at` (integer or null): Epoch milliseconds. When the client last made a call; null when it never did. An instant: epoch milliseconds, UTC.
- `revoked_at` (integer or null): Epoch milliseconds. When the connection was revoked; null for one that was not. An instant: epoch milliseconds, UTC.
- `calls_today` (integer): How many calls the client made today (UTC); 0 for a connection that is not active.

Each failure is a problem document with a stable `code`; the response panel's status selector shows each one this operation can answer, and [errors](https://developer.watchtower15.com/api/errors/) lists them all.

**GET /v1/user/ai-clients**

curl:

```bash
curl https://rest.watchtower15.com/v1/user/ai-clients \
  -H "Authorization: Bearer $WT15_API_KEY"
```

PHP:

```php
$wt15 = WatchTower15\Client::fromEnvironment();

foreach ($wt15->userAiClients->list()->autoPaging() as $item) { echo $item->uuid, "\n"; }
```

Node.js:

```ts
const wt15 = WatchTower15.fromEnvironment();

for await (const item of wt15.userAiClients.list()) {
  console.log(item.uuid);
}
```

Python:

```python
client = Client.from_environment()

for item in client.user_ai_clients.list():
    print(item.uuid)
```

**Response (200 OK)**

```json
{
  "data": [
    {
      "uuid": "75666699-b77d-4631-b576-041e8102a55b",
      "client_name": "example",
      "access": "example",
      "status": "active",
      "created_at": 1794214800000,
      "expires_at": 1794214800000,
      "last_used_at": 1794214800000,
      "revoked_at": 1794214800000,
      "calls_today": 1
    }
  ],
  "current_page": 1,
  "per_page": 1,
  "last_page": 1,
  "total": 1
}
```

**Response (401 Unauthorized)**

The API key is missing, malformed, expired or revoked.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/unauthorized/",
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The API key is missing, malformed, expired or revoked",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (403 Forbidden)**

The key or its owner does not hold what the operation needs.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/forbidden/",
  "title": "Forbidden",
  "status": 403,
  "code": "forbidden",
  "detail": "This key does not have the ai_access.view scope",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (404 Not Found)**

No such record in this organisation (an absent id and another organisation's answer alike).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/not_found/",
  "title": "Not found",
  "status": 404,
  "code": "not_found",
  "detail": "No record with that id exists in this organisation.",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (422 Unprocessable Content)**

The request is invalid (`invalid_request`; `errors` names the parameters).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/invalid_request/",
  "title": "Invalid request",
  "status": 422,
  "code": "invalid_request",
  "detail": "The request is invalid",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "errors": {
    "name": [
      "The name field is required."
    ]
  }
}
```

**Response (429 Too Many Requests)**

A rate limit or the organisation's daily limit is reached; `Retry-After` says when to retry.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/rate_limited/",
  "title": "Rate limited",
  "status": 429,
  "code": "rate_limited",
  "detail": "Too many requests: the limit is 240 a minute",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "limit": 60
}
```

**Response (500 Internal Server Error)**

An unexpected error.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/internal_error/",
  "title": "Internal error",
  "status": 500,
  "code": "internal_error",
  "detail": "An unexpected error has happened",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

Source: https://developer.watchtower15.com/api/reference/user-ai-clients/
