---
title: "IdentityHound API: Connected accounts"
description: "List connected accounts, remove a connected account, or get a provider access token, with the IdentityHound API."
url: "https://agentpost.tools/docs/identityhound/reference/connections"
kind: reference
---

# Connected accounts

A principal’s accounts at OAuth providers, such as Twitch, held so a trusted caller or a delegate can act for it there. Connect one with `auth.oauthStart` and `purpose: connect`.

[Delegations](/docs/identityhound/concepts/delegations.md) explains how a delegate acting for a principal may use the principal’s connected accounts.

Paths are relative to `https://api.agentpost.tools/v1/identity`, and every request follows the [API basics](/docs/platform/api-basics.md). [Who may call](/docs/identityhound/reference.md#who-may-call) explains each kind of caller.

## List connected accounts

`GET /principals/:id/connections`

A principal’s connected accounts, without their tokens.

-   **Who may call:** Your server or a signed-in principal.
-   **Access:** A principal may list only its own.
-   **Credential:** the examples send your project’s `dev` secret key, `sk_test_…`, as `Authorization: Bearer <token>`.
-   **SDK:** `client.connections.list(principalId)`

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | A principal ID, `prn_…`. The `id` of a [`Principal`](/docs/identityhound/reference/principals.md#the-principal-object). |

### Response

`200 OK`, with:

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `connections` | [`Connection`](/docs/identityhound/reference/connections.md#the-connection-object) array | Always |  |

### Errors

-   [`forbidden`](/docs/identityhound/errors.md#forbidden) (403)

Any operation can also answer with the codes [Conventions](/docs/identityhound/reference.md#conventions) lists.

```bash tab="curl"
curl https://api.agentpost.tools/v1/identity/principals/prn_01JDG9X6KH1ZEF2ZWP185VMW9D/connections \
  -H "Authorization: Bearer sk_test_…"
```

```ts tab="SDK"
import { createClient } from '@agentpost-tools/identityhound-sdk';

const client = createClient({ token: 'sk_test_…' });
const { connections } = await client.connections.list(
  'prn_01JDG9X6KH1ZEF2ZWP185VMW9D',
);
```

```json title="Response"
{
  "connections": [
    {
      "id": "con_01JDJGPK8BY9CQ8J097GQDBK74",
      "principalId": "prn_01JDG9X6KH1ZEF2ZWP185VMW9D",
      "providerKey": "twitch",
      "subject": "91234567",
      "identityId": "idn_01JDG344JJGW867DQ6EJ5WGCY2",
      "scopes": ["user:read:email", "channel:read:subscriptions"],
      "accessTokenExpiresAt": "2026-11-13T13:30:00.000Z",
      "status": "active",
      "createdAt": "2026-11-03T08:20:00.000Z",
      "lastRefreshedAt": "2026-11-13T09:30:00.000Z"
    }
  ]
}
```

## Remove a connected account

`DELETE /connections/:id`

Removes a connected account and revokes its tokens at the provider, such as Twitch, so they stop working there too. If the provider doesn’t revoke them, the account is still removed.

-   **Who may call:** Your server or a signed-in principal.
-   **Access:** A principal may remove only its own.
-   **Credential:** the examples send your project’s `dev` secret key, `sk_test_…`, as `Authorization: Bearer <token>`.
-   **SDK:** `client.connections.remove(id)`
-   **Idempotency-Key:** optional. [Retrying a write](/docs/platform/api-basics.md#retrying-a-write) has the rule.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | A connection ID, `con_…`. The `id` of a [`Connection`](/docs/identityhound/reference/connections.md#the-connection-object). |

### Response

`204 No Content`, with no body.

### Errors

-   [`forbidden`](/docs/identityhound/errors.md#forbidden) (403)
-   [`not_found`](/docs/identityhound/errors.md#not_found) (404)

Any operation can also answer with the codes [Conventions](/docs/identityhound/reference.md#conventions) lists.

```bash tab="curl"
curl -X DELETE https://api.agentpost.tools/v1/identity/connections/con_01JDJGPK8BY9CQ8J097GQDBK74 \
  -H "Authorization: Bearer sk_test_…"
```

```ts tab="SDK"
import { createClient } from '@agentpost-tools/identityhound-sdk';

const client = createClient({ token: 'sk_test_…' });
await client.connections.remove('con_01JDJGPK8BY9CQ8J097GQDBK74');
```

```text title="Response"
204 No Content
```

## Get a provider access token

`POST /connections/:id/token`

A short-lived access token for the provider, refreshed first when it’s about to expire. Each active connection’s token is also checked with the provider hourly, and a token the provider rejects is refreshed. A connection becomes `needs_reauth`, with a `connection.needs_reauth` event, only when the provider refuses its refresh token. A timeout, a 5xx, or a 429 from the provider never changes a connection; this call then answers `provider_error`, and a retry may succeed.

-   **Who may call:** Your server or a signed-in principal.
-   **Access:** Trusted callers, or a principal with a delegated token whose delegation holds `identity.connection:use` for the provider. Not the principal’s own session.
-   **Credential:** the examples send your project’s `dev` secret key, `sk_test_…`, as `Authorization: Bearer <token>`.
-   **SDK:** `client.connections.token(id)`
-   **Idempotency-Key:** optional. [Retrying a write](/docs/platform/api-basics.md#retrying-a-write) has the rule.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | A connection ID, `con_…`. The `id` of a [`Connection`](/docs/identityhound/reference/connections.md#the-connection-object). |

### Response

`200 OK`, with [`ConnectionTokenResponse`](/docs/identityhound/reference/connections.md#the-connectiontokenresponse-object).

### Errors

-   [`connection_needs_reauth`](/docs/identityhound/errors.md#connection_needs_reauth) (409)
-   [`forbidden`](/docs/identityhound/errors.md#forbidden) (403)
-   [`not_found`](/docs/identityhound/errors.md#not_found) (404)
-   [`provider_error`](/docs/identityhound/errors.md#provider_error) (502)
-   [`trusted_caller_required`](/docs/identityhound/errors.md#trusted_caller_required) (403)

Any operation can also answer with the codes [Conventions](/docs/identityhound/reference.md#conventions) lists.

```bash tab="curl"
curl -X POST https://api.agentpost.tools/v1/identity/connections/con_01JDJGPK8BY9CQ8J097GQDBK74/token \
  -H "Authorization: Bearer sk_test_…"
```

```ts tab="SDK"
import { createClient } from '@agentpost-tools/identityhound-sdk';

const client = createClient({ token: 'sk_test_…' });
const { accessToken, expiresAt, scopes } = await client.connections.token(
  'con_01JDJGPK8BY9CQ8J097GQDBK74',
);
```

```json title="Response"
{
  "accessToken": "provider_access_token_…",
  "expiresAt": "2026-11-13T13:30:00.000Z",
  "scopes": ["user:read:email", "channel:read:subscriptions"]
}
```

## The Connection object

A connected account as the API shows it: never with its tokens.

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `id` | `string` | Always | A connection ID, `con_…`. |
| `principalId` | `string` | Always | A principal ID, `prn_…`. |
| `providerKey` | `string` | Always |  |
| `subject` | `string` | Always |  |
| `identityId` | `string` | When set | An identity ID, `idn_…`. |
| `scopes` | `string[]` | Always |  |
| `accessTokenExpiresAt` | `string` | When set | An ISO 8601 date and time. |
| `status` | `string` | Always | One of `"active"` or `"needs_reauth"`. |
| `createdAt` | `string` | Always | An ISO 8601 date and time. |
| `lastRefreshedAt` | `string` | When set | An ISO 8601 date and time. |
| `lastUsedAt` | `string` | When set | An ISO 8601 date and time. |

```json title="The Connection object"
{
  "id": "con_01JDJGPK8BY9CQ8J097GQDBK74",
  "principalId": "prn_01JDG9X6KH1ZEF2ZWP185VMW9D",
  "providerKey": "twitch",
  "subject": "91234567",
  "identityId": "idn_01JDG344JJGW867DQ6EJ5WGCY2",
  "scopes": ["user:read:email", "channel:read:subscriptions"],
  "accessTokenExpiresAt": "2026-11-13T13:30:00.000Z",
  "status": "active",
  "createdAt": "2026-11-03T08:20:00.000Z",
  "lastRefreshedAt": "2026-11-13T09:30:00.000Z"
}
```

## The ConnectionTokenResponse object

| Name | Type | Present | Description |
| --- | --- | --- | --- |
| `accessToken` | `string` | Always |  |
| `expiresAt` | `string` | When set |  |
| `scopes` | `string[]` | Always |  |

```json title="The ConnectionTokenResponse object"
{
  "accessToken": "provider_access_token_…",
  "expiresAt": "2026-11-13T13:30:00.000Z",
  "scopes": ["user:read:email", "channel:read:subscriptions"]
}
```
