# Agent links

> Agent links: the credential of an agent that acts for one person. A person links an agent and names what it may do (`models.use`, `spend.read_own`, `connectors.use`, `chat.ask`, `chat.web`, `agents.memory`). Its token (`nxo_…`) is stored as a hash and shown once. The agent holds that grant cut down to the person's role now, and never the routes that are the person's alone. The person, or an owner or admin, unlinks it, and the person's own tokens do not change.

## List agent links

`GET /v1/agent-links`

Your live agent links in this organization; `?all=1` for everyone's (owners and admins). Never a token or what it hashes to. Newest first; `limit` and `cursor` page it.

Permission: `agent_links.manage_own` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `all` | query | "1" | no | `1` lists everyone's links. Only owners and admins may: anyone else answers 403 `role_required`. |
| `limit` | query | integer | no | Items per page, 1 to 500 (default 100). Without limit or cursor the answer holds the whole list. |
| `cursor` | query | string | no | NextCursor from the previous page. A cursor whose item left the list answers 400 `invalid_cursor`. |

### Responses

- `200` OK (application/json, AgentLinkList)
  - `agentLinks` (array of AgentLink, required)
    - `id` (string, required): `agl_…`
    - `userId` (string, required): The person the agent acts for.
    - `agent` (string, required): What the agent is, as a slug (`slack`).
    - `label` (string, required)
    - `grant` (array of string, required): The grant the agent holds: what the person granted, cut to what a link may hold now (`models.use`). The person's role limits it again at each call.
    - `prefix` (string, required): The first characters of the token, to recognise it in a list.
    - `createdAt` (string (date-time), required)
    - `expiresAt` (string (date-time), required)
    - `revokedAt` (string (date-time))
    - `lastUsedAt` (string (date-time)): When the link last authenticated, written at most once an hour.
  - `nextCursor` (string): The next page's cursor, while more items follow. Only when limit or cursor was sent.
- `403` `?all=1` without the organization rung of the keys ladder (`role_required`) (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl "$NEXUS_URL/v1/agent-links" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fagent-links)

## Link agent

`POST /v1/agent-links`

Link an agent that acts for you (people only: a service account, a module key or another agent answers 403). `grant` names what it may do: `models.use` (the default), `spend.read_own`, `connectors.use`, `chat.ask` (Ask your code alone, askCode), `chat.web` (web search alone, askWeb) and `agents.memory` (your agent memory alone). The token (`nxo_…`) is in this answer, and again in a repeat with the same `Idempotency-Key` within 24 hours: Gateway keeps only its hash. The agent holds that grant cut down to your role now, and none of the routes that are yours alone. The link lives 90 days unless `expiresAt` says otherwise, at most 365. A person holds at most 20 live links in an organization: the next is 409 `agent_link_limit`. Audited as `agent.linked`, never with the token. With `dryRun: true` everything is checked and nothing is written: the answer is a 200 with no token.

Permission: `agent_links.manage_own` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Request body (application/json, required)

- `agent` (string, required): What the agent is, as a slug (`slack`). [min length 1; max length 40; pattern ^[a-z0-9][a-z0-9-]*$]
- `label` (string, required) [min length 1; max length 80]
- `grant` (array of "models.use" | "spend.read_own"): What the agent may do. `models.use` by default.
- `expiresAt` (string (date-time)): In the future, at most 365 days from now. 90 days from now by default.
- `session` (boolean): A link for one agent session: deleted, not kept, when it ends (`DELETE /v1/agent-links/{id}`), so a second end answers 404. It also ends after 15 to 30 minutes without use, so the link of a client that stopped without ending it does not stay live; the client makes a new one. Making one also deletes up to 20 of your ended session links. The audit keeps their history. [default false]
- `dryRun` (boolean): Check everything and write nothing. [default false]

### Responses

- `200` A dry run: the link as it would be made, with no token (application/json, CreatedAgentLink)
  - `id` (string, required): `agl_…`
  - `userId` (string, required): The person the agent acts for.
  - `agent` (string, required): What the agent is, as a slug (`slack`).
  - `label` (string, required)
  - `grant` (array of string, required): The grant the agent holds: what the person granted, cut to what a link may hold now (`models.use`). The person's role limits it again at each call.
  - `prefix` (string, required): The first characters of the token, to recognise it in a list.
  - `createdAt` (string (date-time), required)
  - `expiresAt` (string (date-time), required)
  - `revokedAt` (string (date-time))
  - `lastUsedAt` (string (date-time)): When the link last authenticated, written at most once an hour.
  - `token` (string): `nxo_…`. In this answer, and again in a repeat with the same `Idempotency-Key` within 24 hours. None with `dryRun`.
  - `dryRun` (boolean, required): The link was not written. Its id is never used.
- `201` Created (application/json, CreatedAgentLink)
  - `id` (string, required): `agl_…`
  - `userId` (string, required): The person the agent acts for.
  - `agent` (string, required): What the agent is, as a slug (`slack`).
  - `label` (string, required)
  - `grant` (array of string, required): The grant the agent holds: what the person granted, cut to what a link may hold now (`models.use`). The person's role limits it again at each call.
  - `prefix` (string, required): The first characters of the token, to recognise it in a list.
  - `createdAt` (string (date-time), required)
  - `expiresAt` (string (date-time), required)
  - `revokedAt` (string (date-time))
  - `lastUsedAt` (string (date-time)): When the link last authenticated, written at most once an hour.
  - `token` (string): `nxo_…`. In this answer, and again in a repeat with the same `Idempotency-Key` within 24 hours. None with `dryRun`.
  - `dryRun` (boolean, required): The link was not written. Its id is never used.
- `400` Not valid: an `agent` that is no slug (`invalid_agent`), no label (1 to 80 characters), an empty `grant` (`invalid_grant`), an action that cannot be granted (`grant_not_allowed`) an `expiresAt` that is not a future time within 365 days (`invalid_expiry`), or a field that the body does not define (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `403` The caller may not link: a module key (`module_key`), a service account or another agent (`role_required`), a caller that is no person (`person_required`), a person who is no longer a member (`not_a_member`), or a `grant` that the caller's role does not allow (`role_required`) (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `409` The person already holds 20 live links (`agent_link_limit`) (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 |  | Not valid: an `agent` that is no slug (`invalid_agent`), no label (1 to 80 characters), an empty `grant` (`invalid_grant`), an action that cannot be granted (`grant_not_allowed`) an `expiresAt` that is not a future time within 365 days (`invalid_expiry`), or a field that the body does not define |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 409 |  | The person already holds 20 live links (`agent_link_limit`) |
| 409 | `agent_link_limit` | The next is 409 `agent_link_limit` |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/agent-links" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "agent": "claude",
    "label": "CI"
  }'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fagent-links)

## Unlink agent

`DELETE /v1/agent-links/{id}`

Unlink an agent: your own link, or anyone's for owners and admins (the keys ladder's organization rung). Its token answers as an unknown token from then on. Your own tokens and your other links do not change. Unlinking an ended link answers as it was and writes nothing. A session link is deleted when it ends, so unlinking it again answers 404. Audited as `agent.unlinked`.

Permission: `agent_links.manage_own` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The link's id (`agl_…`) |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Responses

- `200` OK: the link, with `revokedAt` (application/json, AgentLink)
  - `id` (string, required): `agl_…`
  - `userId` (string, required): The person the agent acts for.
  - `agent` (string, required): What the agent is, as a slug (`slack`).
  - `label` (string, required)
  - `grant` (array of string, required): The grant the agent holds: what the person granted, cut to what a link may hold now (`models.use`). The person's role limits it again at each call.
  - `prefix` (string, required): The first characters of the token, to recognise it in a list.
  - `createdAt` (string (date-time), required)
  - `expiresAt` (string (date-time), required)
  - `revokedAt` (string (date-time))
  - `lastUsedAt` (string (date-time)): When the link last authenticated, written at most once an hour.
- `403` Another person's link, and the caller is no owner or admin (`role_required`) (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `404` No such link in this organization (`unknown_agent_link`) (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such link in this organization (`unknown_agent_link`) |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl -X DELETE "$NEXUS_URL/v1/agent-links/<id>" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#delete%3A%2Fv1%2Fagent-links%2F%7Bid%7D)
