# Agents

> `nexus claude` and `nexus codex`: model policy and sessions. The agents' model calls go through the agent gateway, where each is reserved, metered, checked against the organization's policy and attributed to the person and their session.

## Agent policy (deprecated)

`GET /v1/agents/policy`

Deprecated: an alias of `GET /v1/policies/agents/{agent}`. Allowed and default models for each coding agent (`provider/model` ids), as the model policy resolves them. An agent without a Gateway route (`antigravity`, `cursor`) allows none, and its `defaultModel` is empty.

Permission: `org.read` (Every member).

### Responses

- `200` OK (application/json, AgentPolicy)
  - `agents` (object)
    - `claude` (object)
      - `allowedModels` (array of string)
      - `defaultModel` (string)
    - `codex` (object)
      - `allowedModels` (array of string)
      - `defaultModel` (string)
    - `antigravity` (object)
      - `allowedModels` (array of string)
      - `defaultModel` (string)
    - `cursor` (object)
      - `allowedModels` (array of string)
      - `defaultModel` (string)
    - `opencode` (object)
      - `allowedModels` (array of string)
      - `defaultModel` (string)
- `403` The credential does not hold `org.read`: a service account or sandbox key (`role_required`), or a scoped module key (`module_key`). Also `not_in_team` when `x-nexus-team` names a team the caller is not in. (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` `x-nexus-team` names a team that does not exist in this organization (`unknown_team`). (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 |  | `x-nexus-team` names a team that does not exist in this organization (`unknown_team`). |
| 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/agents/policy" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Set agent policy alias (deprecated)

`POST /v1/agents/policy`

Deprecated: an alias that writes the agent's model policy: `allowedModels` becomes its allow list and `defaultModel` its default (a deny list already set stays).

Permission: `policy.manage` (Owner, Admin).

### 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` ("claude" | "codex" | "antigravity" | "cursor" | "opencode", required): A coding agent's id. It names the agent in sessions, policies and routes. Its command may differ: `antigravity` runs as `nexus agy`.
- `allowedModels` (array of string, required)
- `defaultModel` (string, required)

### Responses

- `200` OK (application/json, object)
  - `agent` ("claude" | "codex" | "antigravity" | "cursor" | "opencode"): A coding agent's id. It names the agent in sessions, policies and routes. Its command may differ: `antigravity` runs as `nexus agy`.
  - `allowedModels` (array of string)
  - `defaultModel` (string)
- `400` `agent` is not `claude`, `codex`, `antigravity` or `cursor`, or `allowedModels` (a non-empty list) or `defaultModel` is missing (`invalid_request`); `agent` runs only on the person's own plan (`route_unsupported`); or the rule it makes is not valid (`invalid_policy`). (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 does not hold `policy.manage`: only owners and admins set the agent policy (`role_required`). A scoped module key gets `module_key`. (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 |  | `agent` is not `claude`, `codex`, `antigravity` or `cursor`, or `allowedModels` (a non-empty list) or `defaultModel` is missing (`invalid_request`); `agent` runs only on the person's own plan (`route_unsupported`); or the rule it makes is not valid (`invalid_policy`). |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 403 | `model_not_allowed` | The caller does not hold `policy.manage`: only owners and admins set the agent policy (`role_required`). A scoped module key gets `module_key`. |
| 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/agents/policy" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "agent": "claude",
    "allowedModels": [
      "anthropic/claude-fable-5.1"
    ],
    "defaultModel": "anthropic/claude-fable-5.1"
  }'
```

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

## Check agent

`POST /v1/agents/check`

May the agent launch on this model (no model: what `nexus/default` resolves to)? The model policy's decision, the same the gateway makes on every call. An agent without a Gateway route (`antigravity`, `cursor`) is a 400 `route_unsupported`.

Permission: `products.use` (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` ("claude" | "codex" | "antigravity" | "cursor" | "opencode", required): A coding agent's id. It names the agent in sessions, policies and routes. Its command may differ: `antigravity` runs as `nexus agy`.
- `model` (string): Model id (`provider/model`, the provider's own id, or nexus/auto); omit for the default

### Responses

- `200` OK (application/json, AgentCheck)
  - `allowed` (boolean)
  - `agent` ("claude" | "codex" | "antigravity" | "cursor" | "opencode"): A coding agent's id. It names the agent in sessions, policies and routes. Its command may differ: `antigravity` runs as `nexus agy`.
  - `model` (string | null)
  - `reason` (string)
  - `allowedModels` (array of string)
  - `defaultModel` (string)
- `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 | `route_unsupported` | An agent without a Gateway route (`antigravity`, `cursor`) is a 400 `route_unsupported` |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 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/agents/check" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "agent": "claude"
  }'
```

```ts
import { createCoreClient } from "@nexus/kit";

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.checkAgent("claude");
```

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

## Route agent

`POST /v1/agents/route`

Auto for a coding agent's session before it starts: the model, who pays and why. A signed-in plan with room comes first; a paid model is only returned as `ask_for_paid_fallback`, for the client to confirm. A dry run: it opens no session and holds no money. A model the policy refuses is never returned.

Permission: `products.use` (Every member).

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

- `agent` ("claude" | "codex" | "antigravity" | "cursor" | "opencode" | "auto", required): The agent to start, or auto for Auto to pick among agents
- `agents` (array of "claude" | "codex" | "antigravity" | "cursor" | "opencode"): With agent auto: the person's agents Auto may pick from. Ignored otherwise [at most 8 items]
- `team` (string): Team slug or id; omit for the caller's default
- `model` (string): A pinned model: Auto then picks only who pays
- `plans` (array of object): The plan accounts the agent is signed in to on this machine [at most 8 items]
  - `agent` ("claude" | "codex" | "antigravity" | "cursor" | "opencode"): The agent the account is signed in to; required with agent auto
  - `account` (integer, required): The client's handle for the account, never an email [min 0]
  - `models` (array of object, required) [at most 64 items]
    - `id` (string, required): The agent's own id or the catalog id
    - `room` ("left" | "usedUp" | "unknown", required): Every limit window that applies to the model, folded: usedUp when any is used up, unknown when a reading is missing or old
- `counts` (object): The first prompt as counts, never its text; omit before the first prompt
  - `inputTokens` (integer) [min 0]
  - `codeBlocks` (integer) [min 0]
  - `images` (boolean)

### Responses

- `200` OK (application/json, AgentLaunchRoute)
  - `result` ("use_plan" | "ask_for_paid_fallback" | "stop", required)
  - `agent` ("claude" | "codex" | "antigravity" | "cursor" | "opencode" | "auto", required): The agent to start; auto on a stop of an agent auto request
  - `version` (string, required): The auto router version that chose
  - `reason` (string, required): Plan_at_floor, plan_below_floor, paid_at_floor, paid_below_floor or pinned; for stop: no_classifier, no_offer or pinned_unavailable
  - `class` ("light" | "standard" | "heavy")
  - `model` (string): Canonical model id
  - `providerModel` (string | null): The id to start the agent with
  - `effort` (string | null)
  - `payer` ("plan" | "local_key" | "gateway")
  - `account` (integer | null): The plan account handle the request named
  - `access` ("byok" | "nexus" | null): Who pays on Gateway
- `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 -X POST "$NEXUS_URL/v1/agents/route" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agent": "claude"
  }'
```

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

## List agent sessions

`GET /v1/agents/sessions`

This tenant's coding-agent sessions, newest first.

Permission: `spend.read_own` (Every member).

### Responses

- `200` OK (application/json, object)
  - `sessions` (array of AgentSession)
    - `id` (string)
    - `agent` ("claude" | "codex" | "antigravity" | "cursor" | "opencode"): A coding agent's id. It names the agent in sessions, policies and routes. Its command may differ: `antigravity` runs as `nexus agy`.
    - `model` (string)
    - `via` ("nexus" | "subscription" | "ori"): Nexus: every model call through Gateway's agent gateway; subscription: the person's own plan (Claude Code on their Claude login, Codex on their ChatGPT login), calls straight to the vendor, usage as the agent reported it; ori: sessions from before the agent gateway
    - `access` ("subscription" | "byok" | "nexus"): Who pays its model calls, as Gateway classified the session when it opened: subscription (the person's own plan), byok (the organization's own provider key, through Gateway) or nexus (Nexus's own key, for Nexus's own organizations; Nexus credit no longer pays an agent). Absent for ori, for sessions from before, and when no key would pay (Gateway refuses those calls).
    - `person` (string)
    - `cwd` (string)
    - `startedAt` (string (date-time))
    - `endedAt` (string (date-time))
    - `durationMs` (number)
    - `exitCode` (integer)
    - `signal` (string)
    - `agentSessionId` (string): The agent's own conversation id: `nexus claude --resume <id>` or `nexus codex resume <id>` picks it up again. [pattern ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$]
    - `status` ("running" | "succeeded" | "failed" | "interrupted" | "lost")
    - `usage` (object): Subscription sessions, once the agent has reported: its calls summed. estimatedCostUsd is the list-price estimate of the priced calls (Claude Code's own, the catalog's for Codex), never charged; unpricedCalls counts the calls with no estimate
      - `calls` (integer)
      - `inputTokens` (integer)
      - `outputTokens` (integer)
      - `cacheReadTokens` (integer)
      - `cacheCreationTokens` (integer)
      - `estimatedCostUsd` (number)
      - `unpricedCalls` (integer): Calls with no estimate, because the agent stated no cost or the call names no model the catalog lists
      - `models` (array of string)
- `401` No credential (`missing_credential`), or a credential Gateway does not accept (`invalid_credential`). (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 key does not hold `spend.read_own` (`role_required`: a service account, a sandbox, or an agent not granted it). (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 |
| 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/agents/sessions" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

```ts
import { createCoreClient } from "@nexus/kit";

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.agentSessions();
```

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

## Open agent session

`POST /v1/agents/sessions`

Open a session before launching an agent. Through the gateway (via nexus, the default) the model is checked on every call; via ori (sessions from before the agent gateway) it is checked here (403 if not allowed).

Permission: `products.use` (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` ("claude" | "codex" | "antigravity" | "cursor" | "opencode", required): A coding agent's id. It names the agent in sessions, policies and routes. Its command may differ: `antigravity` runs as `nexus agy`.
- `via` ("nexus" | "subscription" | "ori"): Nexus (default): the agent runs through the agent gateway; subscription: on the person's own Claude login, usage reported by Claude Code; ori: sessions from before the agent gateway
- `model` (string): The model the agent was started on, as the agent names it; omit for the agent's default
- `person` (string): Who runs it, e.g. the OS user [max length 80]
- `cwd` (string): Working directory; only its basename is kept
- `team` (string): A team slug you are in; default: your default team
- `plan` (string): The plan tier of the person's own account, as the app read it on the device. claude: free, pro, max, team, enterprise or unknown; codex (ChatGPT): free, plus, pro, team, enterprise or unknown. Any other string is kept as unknown: a plan never refuses a session. Kept only where plan collection is on, and never shown on GET /v1/agents/sessions. Never send the raw string, an account id or an email.

### Responses

- `201` Created (application/json, AgentSession)
  - `id` (string)
  - `agent` ("claude" | "codex" | "antigravity" | "cursor" | "opencode"): A coding agent's id. It names the agent in sessions, policies and routes. Its command may differ: `antigravity` runs as `nexus agy`.
  - `model` (string)
  - `via` ("nexus" | "subscription" | "ori"): Nexus: every model call through Gateway's agent gateway; subscription: the person's own plan (Claude Code on their Claude login, Codex on their ChatGPT login), calls straight to the vendor, usage as the agent reported it; ori: sessions from before the agent gateway
  - `access` ("subscription" | "byok" | "nexus"): Who pays its model calls, as Gateway classified the session when it opened: subscription (the person's own plan), byok (the organization's own provider key, through Gateway) or nexus (Nexus's own key, for Nexus's own organizations; Nexus credit no longer pays an agent). Absent for ori, for sessions from before, and when no key would pay (Gateway refuses those calls).
  - `person` (string)
  - `cwd` (string)
  - `startedAt` (string (date-time))
  - `endedAt` (string (date-time))
  - `durationMs` (number)
  - `exitCode` (integer)
  - `signal` (string)
  - `agentSessionId` (string): The agent's own conversation id: `nexus claude --resume <id>` or `nexus codex resume <id>` picks it up again. [pattern ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$]
  - `status` ("running" | "succeeded" | "failed" | "interrupted" | "lost")
  - `usage` (object): Subscription sessions, once the agent has reported: its calls summed. estimatedCostUsd is the list-price estimate of the priced calls (Claude Code's own, the catalog's for Codex), never charged; unpricedCalls counts the calls with no estimate
    - `calls` (integer)
    - `inputTokens` (integer)
    - `outputTokens` (integer)
    - `cacheReadTokens` (integer)
    - `cacheCreationTokens` (integer)
    - `estimatedCostUsd` (number)
    - `unpricedCalls` (integer): Calls with no estimate, because the agent stated no cost or the call names no model the catalog lists
    - `models` (array of string)
- `400` The body is not valid: `agent` not claude, codex, antigravity or cursor, `via` not nexus, subscription or ori, `model`, `person` or `cwd` not a string, `team` not a slug, or a bad `Idempotency-Key`; or `via` nexus or ori for an agent that runs only on the person's own plan (`route_unsupported`). (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.
- `401` No credential (`missing_credential`), or a credential Gateway does not accept (`invalid_credential`). (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 key does not hold `products.use` (`role_required`: a service account, a sandbox, or an agent not granted it), the team named is not the caller's (`not_in_team`), or the organization turned subscription sessions off (`subscriptions_disabled`). (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` The team named does not exist in this organization (`unknown_team`). (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 `Idempotency-Key`'s first request still runs (`idempotency_in_progress`) or was interrupted (`idempotency_interrupted`). The request does not run again. (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.
- `422` The `Idempotency-Key` was used for a different request (`idempotency_key_reused`). (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 |  | The body is not valid: `agent` not claude, codex, antigravity or cursor, `via` not nexus, subscription or ori, `model`, `person` or `cwd` not a string, `team` not a slug, or a bad `Idempotency-Key`; or `via` nexus or ori for an agent that runs only on the person's own plan (`route_unsupported`). |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 |  | The team named does not exist in this organization (`unknown_team`). |
| 409 |  | The `Idempotency-Key`'s first request still runs (`idempotency_in_progress`) or was interrupted (`idempotency_interrupted`). The request does not run again. |
| 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 |  | The `Idempotency-Key` was used for a different request (`idempotency_key_reused`). |
| 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/agents/sessions" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "agent": "claude"
  }'
```

```ts
import { createCoreClient } from "@nexus/kit";

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.openAgentSession({ agent: "claude", via: "nexus", team: "platform" });
```

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

## Get agent session

`GET /v1/agents/sessions/{id}`

One coding-agent session with what its metered calls cost: yours, or any of the organization's for an owner or admin. Anyone else gets 404, as for an unknown id.

Permission: `spend.read_own` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The session's id |

### Responses

- `200` OK (application/json, AgentSessionWithSpend)
  - `id` (string)
  - `agent` ("claude" | "codex" | "antigravity" | "cursor" | "opencode"): A coding agent's id. It names the agent in sessions, policies and routes. Its command may differ: `antigravity` runs as `nexus agy`.
  - `model` (string)
  - `via` ("nexus" | "subscription" | "ori"): Nexus: every model call through Gateway's agent gateway; subscription: the person's own plan (Claude Code on their Claude login, Codex on their ChatGPT login), calls straight to the vendor, usage as the agent reported it; ori: sessions from before the agent gateway
  - `access` ("subscription" | "byok" | "nexus"): Who pays its model calls, as Gateway classified the session when it opened: subscription (the person's own plan), byok (the organization's own provider key, through Gateway) or nexus (Nexus's own key, for Nexus's own organizations; Nexus credit no longer pays an agent). Absent for ori, for sessions from before, and when no key would pay (Gateway refuses those calls).
  - `person` (string)
  - `cwd` (string)
  - `startedAt` (string (date-time))
  - `endedAt` (string (date-time))
  - `durationMs` (number)
  - `exitCode` (integer)
  - `signal` (string)
  - `agentSessionId` (string): The agent's own conversation id: `nexus claude --resume <id>` or `nexus codex resume <id>` picks it up again. [pattern ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$]
  - `status` ("running" | "succeeded" | "failed" | "interrupted" | "lost")
  - `usage` (object): Subscription sessions, once the agent has reported: its calls summed. estimatedCostUsd is the list-price estimate of the priced calls (Claude Code's own, the catalog's for Codex), never charged; unpricedCalls counts the calls with no estimate
    - `calls` (integer)
    - `inputTokens` (integer)
    - `outputTokens` (integer)
    - `cacheReadTokens` (integer)
    - `cacheCreationTokens` (integer)
    - `estimatedCostUsd` (number)
    - `unpricedCalls` (integer): Calls with no estimate, because the agent stated no cost or the call names no model the catalog lists
    - `models` (array of string)
  - `spend` (object, required): What the calls metered to this session cost (refused calls left out); zero without calls.
    - `usd` (number, required) [min 0]
    - `calls` (integer, required) [min 0]
- `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 |
| 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/agents/sessions/<id>" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Export agent sessions CSV

`GET /v1/agents/sessions/export.csv`

Every coding-agent session of the organization that matches the filters, as CSV (owners and admins). Nexus Gateway keeps an organization's newest 500 sessions, so an older one is in no file. At most 100,000 rows a file: past that the file stops, and its manifest says `complete: false` and gives `nextCursor`. Each export is an audit event (`observability.exported`) with the file's manifest, never its rows. An organization runs at most 60 exports an hour: the 61st is a 429 `export_rate_limited`, whose `Retry-After` is the seconds until the hour frees one (the `RateLimit-*` headers stay the per-minute limit's). A bad filter is a 400 before any row.

Permission: `spend.export` (Owner, Admin).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `from` | query | string (date) | no | The first UTC day a session started, YYYY-MM-DD; default 29 days before `to` |
| `to` | query | string (date) | no | The last UTC day a session started, YYYY-MM-DD, included; default today. A range covers at most 366 days |
| `team` | query | string | no | A team slug or id: that team and every team under it; `unassigned` for sessions with no team |
| `person` | query | string | no | A person's user id |
| `agent` | query | "claude" \| "codex" \| "antigravity" \| "cursor" \| "opencode" | no | `claude`, `codex`, `antigravity` or `cursor` |
| `via` | query | "nexus" \| "subscription" \| "ori" | no | `nexus`, `subscription` or `ori` |
| `status` | query | string | no | A comma-separated set of `running`, `succeeded`, `failed` and `interrupted`; default all four |
| `cursor` | query | string | no | A cut file's `manifest.nextCursor`: the next file of the same query. A manifest's `watermark` also works: it starts the same series again. It is bound to the organization, the caller and the query: anywhere else it is a 400 `invalid_cursor` |

### Responses

- `200` CSV with a header row: one column per field of `AgentSessionRow`, in its order. (text/csv, string)
- `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 | `export_rate_limited` | The 61st is a 429 `export_rate_limited`, whose `Retry-After` is the seconds until the hour frees one (the `RateLimit-*` headers stay the per-minute limit's) |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl "$NEXUS_URL/v1/agents/sessions/export.csv" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

```ts
import { createCoreClient } from "@nexus/kit";

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.agentSessionsExport("csv", { agent: "claude" });
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fagents%2Fsessions%2Fexport.csv)

## Export agent sessions JSON Lines

`GET /v1/agents/sessions/export.jsonl`

Every coding-agent session of the organization that matches the filters, as JSON Lines (owners and admins). Nexus Gateway keeps an organization's newest 500 sessions, so an older one is in no file. At most 100,000 rows a file: past that the file stops, and its manifest says `complete: false` and gives `nextCursor`. Each export is an audit event (`observability.exported`) with the file's manifest, never its rows. An organization runs at most 60 exports an hour: the 61st is a 429 `export_rate_limited`, whose `Retry-After` is the seconds until the hour frees one (the `RateLimit-*` headers stay the per-minute limit's). A bad filter is a 400 before any row.

Permission: `spend.export` (Owner, Admin).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `from` | query | string (date) | no | The first UTC day a session started, YYYY-MM-DD; default 29 days before `to` |
| `to` | query | string (date) | no | The last UTC day a session started, YYYY-MM-DD, included; default today. A range covers at most 366 days |
| `team` | query | string | no | A team slug or id: that team and every team under it; `unassigned` for sessions with no team |
| `person` | query | string | no | A person's user id |
| `agent` | query | "claude" \| "codex" \| "antigravity" \| "cursor" \| "opencode" | no | `claude`, `codex`, `antigravity` or `cursor` |
| `via` | query | "nexus" \| "subscription" \| "ori" | no | `nexus`, `subscription` or `ori` |
| `status` | query | string | no | A comma-separated set of `running`, `succeeded`, `failed` and `interrupted`; default all four |
| `cursor` | query | string | no | A cut file's `manifest.nextCursor`: the next file of the same query. A manifest's `watermark` also works: it starts the same series again. It is bound to the organization, the caller and the query: anywhere else it is a 400 `invalid_cursor` |

### Responses

- `200` JSON Lines: one `AgentSessionRow` per line, then one line `{"manifest": ExportManifest}`. (application/jsonl, string)
- `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 | `export_rate_limited` | The 61st is a 429 `export_rate_limited`, whose `Retry-After` is the seconds until the hour frees one (the `RateLimit-*` headers stay the per-minute limit's) |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl "$NEXUS_URL/v1/agents/sessions/export.jsonl" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

```ts
import { createCoreClient } from "@nexus/kit";

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.agentSessionsExport("jsonl", { agent: "claude" });
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fagents%2Fsessions%2Fexport.jsonl)

## End agent session

`POST /v1/agents/sessions/{id}/end`

Close a session with the agent's exit code and duration.

Permission: `products.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes |  |
| `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)

- `exitCode` (integer, required) [min 0; max 255]
- `durationMs` (number) [min 0]
- `signal` (string)
- `agentSessionId` (string): The agent's own conversation id (Claude Code's session id, Codex's rollout id), so the session can be resumed. [pattern ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$]

### Responses

- `200` OK (application/json, AgentSession)
  - `id` (string)
  - `agent` ("claude" | "codex" | "antigravity" | "cursor" | "opencode"): A coding agent's id. It names the agent in sessions, policies and routes. Its command may differ: `antigravity` runs as `nexus agy`.
  - `model` (string)
  - `via` ("nexus" | "subscription" | "ori"): Nexus: every model call through Gateway's agent gateway; subscription: the person's own plan (Claude Code on their Claude login, Codex on their ChatGPT login), calls straight to the vendor, usage as the agent reported it; ori: sessions from before the agent gateway
  - `access` ("subscription" | "byok" | "nexus"): Who pays its model calls, as Gateway classified the session when it opened: subscription (the person's own plan), byok (the organization's own provider key, through Gateway) or nexus (Nexus's own key, for Nexus's own organizations; Nexus credit no longer pays an agent). Absent for ori, for sessions from before, and when no key would pay (Gateway refuses those calls).
  - `person` (string)
  - `cwd` (string)
  - `startedAt` (string (date-time))
  - `endedAt` (string (date-time))
  - `durationMs` (number)
  - `exitCode` (integer)
  - `signal` (string)
  - `agentSessionId` (string): The agent's own conversation id: `nexus claude --resume <id>` or `nexus codex resume <id>` picks it up again. [pattern ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$]
  - `status` ("running" | "succeeded" | "failed" | "interrupted" | "lost")
  - `usage` (object): Subscription sessions, once the agent has reported: its calls summed. estimatedCostUsd is the list-price estimate of the priced calls (Claude Code's own, the catalog's for Codex), never charged; unpricedCalls counts the calls with no estimate
    - `calls` (integer)
    - `inputTokens` (integer)
    - `outputTokens` (integer)
    - `cacheReadTokens` (integer)
    - `cacheCreationTokens` (integer)
    - `estimatedCostUsd` (number)
    - `unpricedCalls` (integer): Calls with no estimate, because the agent stated no cost or the call names no model the catalog lists
    - `models` (array of string)
- `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 |
| 404 | `not_found` | Nothing matches the path in your organization |
| 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/agents/sessions/<id>/end" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "exitCode": 0,
    "signal": "SIGINT"
  }'
```

```ts
import { createCoreClient } from "@nexus/kit";

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.endAgentSession("<session id>", { exitCode: 0, durationMs: 42_000 });
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fagents%2Fsessions%2F%7Bid%7D%2Fend)

## Heartbeat agent session

`POST /v1/agents/sessions/{id}/heartbeat`

Say the agent still runs. The CLI sends one every 5 minutes; a running session with none for 15 minutes reads as lost until the next one or its end.

Permission: `products.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes |  |
| `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 (application/json, AgentSession)
  - `id` (string)
  - `agent` ("claude" | "codex" | "antigravity" | "cursor" | "opencode"): A coding agent's id. It names the agent in sessions, policies and routes. Its command may differ: `antigravity` runs as `nexus agy`.
  - `model` (string)
  - `via` ("nexus" | "subscription" | "ori"): Nexus: every model call through Gateway's agent gateway; subscription: the person's own plan (Claude Code on their Claude login, Codex on their ChatGPT login), calls straight to the vendor, usage as the agent reported it; ori: sessions from before the agent gateway
  - `access` ("subscription" | "byok" | "nexus"): Who pays its model calls, as Gateway classified the session when it opened: subscription (the person's own plan), byok (the organization's own provider key, through Gateway) or nexus (Nexus's own key, for Nexus's own organizations; Nexus credit no longer pays an agent). Absent for ori, for sessions from before, and when no key would pay (Gateway refuses those calls).
  - `person` (string)
  - `cwd` (string)
  - `startedAt` (string (date-time))
  - `endedAt` (string (date-time))
  - `durationMs` (number)
  - `exitCode` (integer)
  - `signal` (string)
  - `agentSessionId` (string): The agent's own conversation id: `nexus claude --resume <id>` or `nexus codex resume <id>` picks it up again. [pattern ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$]
  - `status` ("running" | "succeeded" | "failed" | "interrupted" | "lost")
  - `usage` (object): Subscription sessions, once the agent has reported: its calls summed. estimatedCostUsd is the list-price estimate of the priced calls (Claude Code's own, the catalog's for Codex), never charged; unpricedCalls counts the calls with no estimate
    - `calls` (integer)
    - `inputTokens` (integer)
    - `outputTokens` (integer)
    - `cacheReadTokens` (integer)
    - `cacheCreationTokens` (integer)
    - `estimatedCostUsd` (number)
    - `unpricedCalls` (integer): Calls with no estimate, because the agent stated no cost or the call names no model the catalog lists
    - `models` (array of string)
- `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 |
| 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/agents/sessions/<id>/heartbeat" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fagents%2Fsessions%2F%7Bid%7D%2Fheartbeat)

## Report agent session usage

`POST /v1/agents/sessions/{id}/usage`

Usage from a subscription session as an OpenTelemetry logs export (OTLP/HTTP JSON). Cursor sessions return 409 `usage_unsupported`. A record whose event.name (else its body) is api_request or claude_code.api_request counts as one model call. A request_id seen among the session's last 512 does not count again. Codex's codex.sse_event for response.completed counts too, once per conversation.id and event.timestamp. Other records are dropped unread. A body without resourceLogs is a 400.

Permission: `products.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes |  |
| `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)

- `resourceLogs` (array of object)

### Responses

- `200` OK: an OTLP ExportLogsServiceResponse, empty, or with partialSuccess counting the entries that were not log objects (application/json, object)
  - `partialSuccess` (object)
    - `rejectedLogRecords` (integer)
    - `errorMessage` (string)
- `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 |
| 404 | `not_found` | Nothing matches the path in your organization |
| 409 | `usage_unsupported` | Cursor sessions return 409 `usage_unsupported` |
| 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/agents/sessions/<id>/usage" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "resourceLogs": [
      {}
    ]
  }'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fagents%2Fsessions%2F%7Bid%7D%2Fusage)

## Get agent access

`GET /v1/agents/access`

Routes for coding agents with a released Nexus launcher: for each agent, the route it takes when you name none (`from`: your preference, the default, or the organization when it turned subscriptions off), each route with who pays (the organization's own key, Nexus, or your plan), whether it can run, and the commands that install and sign in the agent.

Permission: `products.use` (Every member).

### Responses

- `200` OK (application/json, AgentAccess)
  - `agentSubscriptions` (boolean, required): Whether the organization allows subscription routes (GET/PUT /v1/orgs/settings)
  - `agents` (array of AgentAccessEntry, required)
    - `agent` ("claude" | "codex" | "antigravity" | "cursor" | "opencode", required): A coding agent's id. It names the agent in sessions, policies and routes. Its command may differ: `antigravity` runs as `nexus agy`.
    - `name` (string, required)
    - `install` (string, required): How to install the agent (the vendor's own package; Nexus never installs it)
    - `route` ("gateway" | "subscription", required): The route it takes when the person names none
    - `from` ("preference" | "default" | "organization", required): Why: the person's preference, the default (gateway), or the organization (subscriptions turned off while the person prefers one)
    - `preference` ("gateway" | "subscription"): The person's saved route; absent when none
    - `routes` (array of AgentRoute, required)
      - `route` ("gateway" | "subscription", required)
      - `access` ("byok" | "nexus" | "subscription" | null, required): Who pays on this route: byok (the organization's own key), nexus (a key Nexus pays for) or subscription (the person's plan); null on gateway when no key would pay
      - `available` (boolean, required): Whether the route can run now; reason says why not
      - `reason` (string): Why it cannot, and the command that fixes it
      - `provider` (string): Gateway: the provider Gateway calls
      - `plan` (string): Subscription: the plan it runs on
      - `vendor` (string)
      - `login` (string): Subscription: how to sign the agent in to the plan, once, on the person's machine
      - `loginStatus` (string): Subscription: how to check that sign-in
- `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 |
| 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/agents/access" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Set agent access

`PUT /v1/agents/access`

Choose the route each of your coding agents takes when you name none (`nexus agents use`), in every client: `gateway` or `subscription`; null forgets it (the default: subscription, or gateway when the organization turned subscription mode off). Yours in every organization, not audited (each session records its route). 403 `subscriptions_disabled` for a subscription the organization turned off; 400 `route_unsupported` for the gateway route of an agent that runs only on the person's own plan; 400 for a key-only organization key (a route belongs to a person).

Permission: `products.use` (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)

- `claude` ("gateway" | "subscription" | null)
- `codex` ("gateway" | "subscription" | null)
- `antigravity` ("subscription" | null): Antigravity runs only on the person's Google AI plan: `gateway` is a 400 `route_unsupported`.
- `cursor` ("subscription" | null): Cursor runs only on the person's Cursor plan: `gateway` is a 400 `route_unsupported`.
- `opencode` ("subscription" | null): OpenCode uses its configured provider. Gateway refuses `gateway` with `route_unsupported`.

### Responses

- `200` OK (application/json, AgentAccess)
  - `agentSubscriptions` (boolean, required): Whether the organization allows subscription routes (GET/PUT /v1/orgs/settings)
  - `agents` (array of AgentAccessEntry, required)
    - `agent` ("claude" | "codex" | "antigravity" | "cursor" | "opencode", required): A coding agent's id. It names the agent in sessions, policies and routes. Its command may differ: `antigravity` runs as `nexus agy`.
    - `name` (string, required)
    - `install` (string, required): How to install the agent (the vendor's own package; Nexus never installs it)
    - `route` ("gateway" | "subscription", required): The route it takes when the person names none
    - `from` ("preference" | "default" | "organization", required): Why: the person's preference, the default (gateway), or the organization (subscriptions turned off while the person prefers one)
    - `preference` ("gateway" | "subscription"): The person's saved route; absent when none
    - `routes` (array of AgentRoute, required)
      - `route` ("gateway" | "subscription", required)
      - `access` ("byok" | "nexus" | "subscription" | null, required): Who pays on this route: byok (the organization's own key), nexus (a key Nexus pays for) or subscription (the person's plan); null on gateway when no key would pay
      - `available` (boolean, required): Whether the route can run now; reason says why not
      - `reason` (string): Why it cannot, and the command that fixes it
      - `provider` (string): Gateway: the provider Gateway calls
      - `plan` (string): Subscription: the plan it runs on
      - `vendor` (string)
      - `login` (string): Subscription: how to sign the agent in to the plan, once, on the person's machine
      - `loginStatus` (string): Subscription: how to check that sign-in
- `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 | `route_unsupported` | 403 `subscriptions_disabled` for a subscription the organization turned off; 400 `route_unsupported` for the gateway route of an agent that runs only on the person's own plan; 400 for a key-only organization key (a route belongs to a person) |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 403 | `subscriptions_disabled` | 403 `subscriptions_disabled` for a subscription the organization turned off; 400 `route_unsupported` for the gateway route of an agent that runs only on the person's own plan; 400 for a key-only organization key (a route belongs to a person) |
| 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 PUT "$NEXUS_URL/v1/agents/access" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "claude": "subscription",
    "codex": null
  }'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#put%3A%2Fv1%2Fagents%2Faccess)

## List assistant conversations

`GET /v1/agents/conversations`

The Nexus assistant's conversations of yours, newest change first, without their messages. `limit` is 1 to 100 (30 when absent); `after` is the last page's `next`; `archived=true` includes archived ones; `externalKey` answers only the live conversation under that key, if any. Your own conversations only: the organization and the person come from the credential, never from the request, and another person's is a 404. The person, or their own agent link that holds `agents.memory` (on the person's opt-in); any other caller answers 403, and no operator grant names it. Off, every call is a 404 `assistant_conversations_off` (NEXUS_ASSISTANT_CONVERSATIONS).

Permission: `agents.memory` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `after` | query | string | no | The `next` of the page before |
| `limit` | query | integer | no |  |
| `archived` | query | boolean | no |  |
| `externalKey` | query | string | no | Only the live conversation under this key, such as `slack:T1:C1:1712.34` |

### Responses

- `200` OK (application/json, AssistantConversationList)
  - `conversations` (array of AssistantConversation, required)
    - `id` (string, required)
    - `title` (string, required)
    - `externalKey` (string | null, required): What the conversation continues, when its creator named it
    - `messageCount` (integer, required)
    - `createdAt` (string, required)
    - `updatedAt` (string, required)
    - `archivedAt` (string | null, required)
  - `next` (string | null, required): The `after` of the next page; null on the last
- `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 |
| 404 | `assistant_conversations_off` | Off, every call is a 404 `assistant_conversations_off` (NEXUS_ASSISTANT_CONVERSATIONS) |
| 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/agents/conversations" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Create assistant conversation

`POST /v1/agents/conversations`

Starts a conversation, or returns your live one under the same `externalKey` (200, `created: false`). 201 for a new one. A person holds at most 1000 live conversations (413 assistant_conversations_full). Your own conversations only: the organization and the person come from the credential, never from the request, and another person's is a 404. The person, or their own agent link that holds `agents.memory` (on the person's opt-in); any other caller answers 403, and no operator grant names it. Off, every call is a 404 `assistant_conversations_off` (NEXUS_ASSISTANT_CONVERSATIONS).

Permission: `agents.memory` (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)

- `title` (string) [max length 200]
- `externalKey` (string) [min length 1; max length 256]

### Responses

- `200` The live conversation under the same externalKey (application/json, AssistantConversationCreated)
  - `id` (string, required)
  - `title` (string, required)
  - `externalKey` (string | null, required): What the conversation continues, when its creator named it
  - `messageCount` (integer, required)
  - `createdAt` (string, required)
  - `updatedAt` (string, required)
  - `archivedAt` (string | null, required)
  - `created` (boolean, required): False when the externalKey already named a live conversation
- `201` Created (application/json, AssistantConversationCreated)
  - `id` (string, required)
  - `title` (string, required)
  - `externalKey` (string | null, required): What the conversation continues, when its creator named it
  - `messageCount` (integer, required)
  - `createdAt` (string, required)
  - `updatedAt` (string, required)
  - `archivedAt` (string | null, required)
  - `created` (boolean, required): False when the externalKey already named a live conversation
- `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 |
| 404 | `assistant_conversations_off` | Off, every call is a 404 `assistant_conversations_off` (NEXUS_ASSISTANT_CONVERSATIONS) |
| 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/agents/conversations" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "<title>",
    "externalKey": "<externalKey>"
  }'
```

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

## Get assistant conversation

`GET /v1/agents/conversations/{id}`

One conversation and a page of its messages, in order. `after` is the number of the last message you read (the first page when absent); `limit` is 1 to 500 (100 when absent); `nextAfter` is the `after` of the next page. Your own conversations only: the organization and the person come from the credential, never from the request, and another person's is a 404. The person, or their own agent link that holds `agents.memory` (on the person's opt-in); any other caller answers 403, and no operator grant names it. Off, every call is a 404 `assistant_conversations_off` (NEXUS_ASSISTANT_CONVERSATIONS).

Permission: `agents.memory` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | A conversation's id, as the list or the create answered it (404 assistant_conversation_not_found) |
| `after` | query | integer | no |  |
| `limit` | query | integer | no |  |

### Responses

- `200` OK (application/json, AssistantConversationPage)
  - `id` (string, required)
  - `title` (string, required)
  - `externalKey` (string | null, required): What the conversation continues, when its creator named it
  - `messageCount` (integer, required)
  - `createdAt` (string, required)
  - `updatedAt` (string, required)
  - `archivedAt` (string | null, required)
  - `messages` (array of AssistantMessage, required)
    - `seq` (integer, required) [min 0]
    - `role` ("user" | "assistant" | "tool", required)
    - `content` (any, required): Any JSON but null, as it was written
    - `createdAt` (string, required)
  - `nextAfter` (integer | null, required): The `after` of the next page of messages; null on the last
- `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 |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 | `assistant_conversations_off` | Off, every call is a 404 `assistant_conversations_off` (NEXUS_ASSISTANT_CONVERSATIONS) |
| 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/agents/conversations/<id>" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Rename assistant conversation

`PATCH /v1/agents/conversations/{id}`

Renames a conversation: a title of at most 200 characters. Your own conversations only: the organization and the person come from the credential, never from the request, and another person's is a 404. The person, or their own agent link that holds `agents.memory` (on the person's opt-in); any other caller answers 403, and no operator grant names it. Off, every call is a 404 `assistant_conversations_off` (NEXUS_ASSISTANT_CONVERSATIONS).

Permission: `agents.memory` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | A conversation's id, as the list or the create answered it (404 assistant_conversation_not_found) |
| `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)

- `title` (string, required) [max length 200]

### Responses

- `200` OK (application/json, AssistantConversation)
  - `id` (string, required)
  - `title` (string, required)
  - `externalKey` (string | null, required): What the conversation continues, when its creator named it
  - `messageCount` (integer, required)
  - `createdAt` (string, required)
  - `updatedAt` (string, required)
  - `archivedAt` (string | null, required)
- `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 |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 | `assistant_conversations_off` | Off, every call is a 404 `assistant_conversations_off` (NEXUS_ASSISTANT_CONVERSATIONS) |
| 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 PATCH "$NEXUS_URL/v1/agents/conversations/<id>" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "<title>"
  }'
```

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

## Append assistant messages

`POST /v1/agents/conversations/{id}/messages`

Appends messages, numbered from 0, each one after the one before. Idempotent by `seq`: a message the conversation already holds with the same role and content changes nothing, so a retried batch is safe; other content at a held `seq` is a 409 assistant_seq_conflict, a `seq` past the next one a 409 assistant_seq_gap (`nextSeq` in the error), and an archived conversation takes no new message (409 assistant_conversation_archived). 1 to 100 messages of at most 256 KiB each; a conversation holds at most 5000 (413). Content is stored readable, not sealed. Your own conversations only: the organization and the person come from the credential, never from the request, and another person's is a 404. The person, or their own agent link that holds `agents.memory` (on the person's opt-in); any other caller answers 403, and no operator grant names it. Off, every call is a 404 `assistant_conversations_off` (NEXUS_ASSISTANT_CONVERSATIONS).

Permission: `agents.memory` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | A conversation's id, as the list or the create answered it (404 assistant_conversation_not_found) |
| `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)

- `messages` (array of NewAssistantMessage, required) [at most 100 items]
  - `seq` (integer, required) [min 0]
  - `role` ("user" | "assistant" | "tool", required)
  - `content` (any, required): Any JSON but null; at most 256 KiB

### Responses

- `200` OK (application/json, AssistantMessagesAppended)
  - `written` (integer, required): How many messages the append wrote; the ones already held do not count
  - `nextSeq` (integer, required): The number the next message takes
- `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 |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 | `assistant_conversations_off` | Off, every call is a 404 `assistant_conversations_off` (NEXUS_ASSISTANT_CONVERSATIONS) |
| 409 | `seq` | A message the conversation already holds with the same role and content changes nothing, so a retried batch is safe; other content at a held `seq` is a 409 assistant_seq_conflict, a `seq` past the next one a 409 assistant_seq_gap (`nextSeq` in the error), and an archived conversation takes no new message (409 assistant_conversation_archived) |
| 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/agents/conversations/<id>/messages" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {
        "seq": 0,
        "role": "user"
      }
    ]
  }'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fagents%2Fconversations%2F%7Bid%7D%2Fmessages)

## Archive assistant conversation

`POST /v1/agents/conversations/{id}/archive`

Archives a conversation: it leaves the default list, keeps its messages, and takes no new ones. Archiving again changes nothing. Nothing is deleted; account deletion and a member's removal delete conversations. Your own conversations only: the organization and the person come from the credential, never from the request, and another person's is a 404. The person, or their own agent link that holds `agents.memory` (on the person's opt-in); any other caller answers 403, and no operator grant names it. Off, every call is a 404 `assistant_conversations_off` (NEXUS_ASSISTANT_CONVERSATIONS).

Permission: `agents.memory` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | A conversation's id, as the list or the create answered it (404 assistant_conversation_not_found) |
| `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 (application/json, AssistantConversation)
  - `id` (string, required)
  - `title` (string, required)
  - `externalKey` (string | null, required): What the conversation continues, when its creator named it
  - `messageCount` (integer, required)
  - `createdAt` (string, required)
  - `updatedAt` (string, required)
  - `archivedAt` (string | null, required)
- `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 | `assistant_conversations_off` | Off, every call is a 404 `assistant_conversations_off` (NEXUS_ASSISTANT_CONVERSATIONS) |
| 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/agents/conversations/<id>/archive" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fagents%2Fconversations%2F%7Bid%7D%2Farchive)

## Clear agent memory

`DELETE /v1/agents/memory`

Delete every row of your agent memory in this organization: forget, unlink and uninstall. Audited as `agent.memory_cleared` when a row went. Your own rows only: the organization and the person come from the credential, never from the request. The person, or their own agent link that holds `agents.memory` (on the person's opt-in); any other caller answers 403, and no operator grant names it.

Permission: `agents.memory` (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). |

### Responses

- `200` OK (application/json, AgentMemoryCleared)
  - `deleted` (integer, required): How many rows went [min 0]
- `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 |
| 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/agents/memory" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#delete%3A%2Fv1%2Fagents%2Fmemory)

## List agent memory

`GET /v1/agents/memory/{collection}`

One page of your agent memory's keys in a collection, in byte order, with their versions and no values. `limit` is 1 to 1000 (100 when absent; 400 agent_memory_limit_invalid); `after` is the last key of the page before (`next`). Your own rows only: the organization and the person come from the credential, never from the request. The person, or their own agent link that holds `agents.memory` (on the person's opt-in); any other caller answers 403, and no operator grant names it.

Permission: `agents.memory` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `collection` | path | string | yes | 1 to 64 characters: a lowercase letter, then lowercase letters, digits, _ or - (400 agent_memory_collection_invalid) |
| `after` | query | string | no | The `next` of the page before |
| `limit` | query | integer | no |  |

### Responses

- `200` OK (application/json, AgentMemoryKeys)
  - `collection` (string, required)
  - `keys` (array of AgentMemoryEntry, required)
    - `key` (string, required)
    - `version` (integer, required): What a later write names in If-Match. It never repeats, also after a delete. [min 1]
    - `updatedAt` (string (date-time), required)
  - `next` (string | null, required): The `after` of the next page; null on the last
- `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 |
| 404 | `not_found` | Nothing matches the path in your organization |
| 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/agents/memory/<collection>" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fagents%2Fmemory%2F%7Bcollection%7D)

## Get agent memory

`GET /v1/agents/memory/{collection}/{key}`

One row of your agent memory: the value as the agent sealed it, and its version (also the `ETag`). 404 agent_memory_not_found when there is none. Your own rows only: the organization and the person come from the credential, never from the request. The person, or their own agent link that holds `agents.memory` (on the person's opt-in); any other caller answers 403, and no operator grant names it.

Permission: `agents.memory` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `collection` | path | string | yes | 1 to 64 characters: a lowercase letter, then lowercase letters, digits, _ or - (400 agent_memory_collection_invalid) |
| `key` | path | string | yes | 1 to 256 characters of A-Z, a-z, 0-9, ., _, ~ and -, and not . or .. (400 agent_memory_key_invalid). Encode any other key, as base64url. |

### Responses

- `200` OK (application/json, AgentMemoryRow)
  - `collection` (string, required)
  - `key` (string, required)
  - `value` (string, required): The agent's sealed text, as it wrote it
  - `version` (integer, required): What a later write names in If-Match. It never repeats, also after a delete. [min 1]
  - `updatedAt` (string (date-time), required)
- `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 |
| 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/agents/memory/<collection>/<key>" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fagents%2Fmemory%2F%7Bcollection%7D%2F%7Bkey%7D)

## Set agent memory

`PUT /v1/agents/memory/{collection}/{key}`

Write one row of your agent memory, if it is as you read it: `If-Match: <version>` replaces the row at that version, and `If-None-Match: *` creates it. With neither, a 428 agent_memory_precondition_required. A write that loses a race, or creates a row that exists, is a 409 agent_memory_version_conflict, and nothing changes. The value is the agent's sealed text, 1 byte to 256 KiB (413 agent_memory_value_too_large); Gateway never opens it. You hold at most 1000 rows and 8 MiB in an organization (413 agent_memory_full). Versions never repeat, also after a delete. Audited as `agent.memory_written`, without the value. Your own rows only: the organization and the person come from the credential, never from the request. The person, or their own agent link that holds `agents.memory` (on the person's opt-in); any other caller answers 403, and no operator grant names it.

Permission: `agents.memory` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `collection` | path | string | yes | 1 to 64 characters: a lowercase letter, then lowercase letters, digits, _ or - (400 agent_memory_collection_invalid) |
| `key` | path | string | yes | 1 to 256 characters of A-Z, a-z, 0-9, ., _, ~ and -, and not . or .. (400 agent_memory_key_invalid). Encode any other key, as base64url. |
| `If-Match` | header | string | no | The version the write read (`"12"` or `12`, the row's `ETag`). The write happens only while the row is at it. |
| `If-None-Match` | header | "*" | no | `*`: create the row, only when none exists. |
| `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)

- `value` (string, required): The agent's sealed text, at most 256 KiB [min length 1]

### Responses

- `200` Written (application/json, AgentMemoryWritten)
  - `collection` (string, required)
  - `key` (string, required)
  - `version` (integer, required): What a later write names in If-Match. It never repeats, also after a delete. [min 1]
  - `created` (boolean, required): True when the write made the row (If-None-Match: *)
  - `updatedAt` (string (date-time), required)
- `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 |
| 404 | `not_found` | Nothing matches the path in your organization |
| 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 PUT "$NEXUS_URL/v1/agents/memory/<collection>/<key>" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "value": "<value>"
  }'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#put%3A%2Fv1%2Fagents%2Fmemory%2F%7Bcollection%7D%2F%7Bkey%7D)

## Delete agent memory

`DELETE /v1/agents/memory/{collection}/{key}`

Delete one row of your agent memory; with `If-Match`, only at that version (409 agent_memory_version_conflict otherwise). Without it, a missing row is a 404 agent_memory_not_found. Audited as `agent.memory_deleted`. Your own rows only: the organization and the person come from the credential, never from the request. The person, or their own agent link that holds `agents.memory` (on the person's opt-in); any other caller answers 403, and no operator grant names it.

Permission: `agents.memory` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `collection` | path | string | yes | 1 to 64 characters: a lowercase letter, then lowercase letters, digits, _ or - (400 agent_memory_collection_invalid) |
| `key` | path | string | yes | 1 to 256 characters of A-Z, a-z, 0-9, ., _, ~ and -, and not . or .. (400 agent_memory_key_invalid). Encode any other key, as base64url. |
| `If-Match` | header | string | no | The version the write read (`"12"` or `12`, the row's `ETag`). The write happens only while the row is at it. |
| `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 (application/json, AgentMemoryDeleted)
  - `collection` (string, required)
  - `key` (string, required)
  - `version` (integer, required): The version the row had
- `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 |
| 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/agents/memory/<collection>/<key>" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#delete%3A%2Fv1%2Fagents%2Fmemory%2F%7Bcollection%7D%2F%7Bkey%7D)

## List agent state

`GET /v1/agents/state/{collection}`

One page of the agents service's keys in a collection, in byte order, with their versions and no values. `limit` is 1 to 1000 (100 when absent; 400 agent_memory_limit_invalid); `after` is the last key of the page before (`next`). The agents service only, with its platform secret in `x-nexus-agents-secret`: no person, key, agent link or operator of an organization reaches these rows, and every other route refuses the secret with a 403. Gateway never opens a value, and writes no audit event: the rows belong to no organization.

Permission: `chat_apps.runtime` ().

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `collection` | path | string | yes | 1 to 64 characters: a lowercase letter, then lowercase letters, digits, _ or - (400 agent_memory_collection_invalid) |
| `after` | query | string | no | The `next` of the page before |
| `limit` | query | integer | no |  |

### Responses

- `200` OK (application/json, AgentMemoryKeys)
  - `collection` (string, required)
  - `keys` (array of AgentMemoryEntry, required)
    - `key` (string, required)
    - `version` (integer, required): What a later write names in If-Match. It never repeats, also after a delete. [min 1]
    - `updatedAt` (string (date-time), required)
  - `next` (string | null, required): The `after` of the next page; null on the last
- `400` The platform secret came with another credential, or twice (`credential_conflict`); or a bad collection, key, limit or precondition (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.
- `401` No credential, or a wrong platform secret (`missing_credential`, `invalid_credential`) (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` Any other credential: a person's token, an agent link, a service account key, a module key or Nexus UI's secret (`agents_secret_refused`, `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.
- `503` The Gateway holds no platform secret (`not_configured`) (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 |  | The platform secret came with another credential, or twice (`credential_conflict`); or a bad collection, key, limit or precondition |
| 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 |
| 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 |
| 503 |  | The Gateway holds no platform secret (`not_configured`) |

### Example

```sh
curl "$NEXUS_URL/v1/agents/state/<collection>" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fagents%2Fstate%2F%7Bcollection%7D)

## Get agent state

`GET /v1/agents/state/{collection}/{key}`

One row of the agents service's own state (its links, journal and approvals): the value as the agent sealed it, and its version (also the `ETag`). 404 agent_memory_not_found when there is none. The agents service only, with its platform secret in `x-nexus-agents-secret`: no person, key, agent link or operator of an organization reaches these rows, and every other route refuses the secret with a 403. Gateway never opens a value, and writes no audit event: the rows belong to no organization.

Permission: `chat_apps.runtime` ().

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `collection` | path | string | yes | 1 to 64 characters: a lowercase letter, then lowercase letters, digits, _ or - (400 agent_memory_collection_invalid) |
| `key` | path | string | yes | 1 to 256 characters of A-Z, a-z, 0-9, ., _, ~ and -, and not . or .. (400 agent_memory_key_invalid). Encode any other key, as base64url. |

### Responses

- `200` OK (application/json, AgentMemoryRow)
  - `collection` (string, required)
  - `key` (string, required)
  - `value` (string, required): The agent's sealed text, as it wrote it
  - `version` (integer, required): What a later write names in If-Match. It never repeats, also after a delete. [min 1]
  - `updatedAt` (string (date-time), required)
- `400` The platform secret came with another credential, or twice (`credential_conflict`); or a bad collection, key, limit or precondition (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.
- `401` No credential, or a wrong platform secret (`missing_credential`, `invalid_credential`) (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` Any other credential: a person's token, an agent link, a service account key, a module key or Nexus UI's secret (`agents_secret_refused`, `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.
- `503` The Gateway holds no platform secret (`not_configured`) (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 |  | The platform secret came with another credential, or twice (`credential_conflict`); or a bad collection, key, limit or precondition |
| 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 |
| 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 |
| 503 |  | The Gateway holds no platform secret (`not_configured`) |

### Example

```sh
curl "$NEXUS_URL/v1/agents/state/<collection>/<key>" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fagents%2Fstate%2F%7Bcollection%7D%2F%7Bkey%7D)

## Set agent state

`PUT /v1/agents/state/{collection}/{key}`

Write one row of the agents service's own state, if it is as the agent read it: `If-Match: <version>` replaces the row at that version, and `If-None-Match: *` creates it. With neither, a 428 agent_memory_precondition_required. A write that loses a race, or creates a row that exists, is a 409 agent_memory_version_conflict, and nothing changes. The value is the agent's sealed text, 1 byte to 256 KiB (413 agent_memory_value_too_large). A collection holds at most 100000 rows (413 agent_state_full). Versions never repeat, also after a delete. The agents service only, with its platform secret in `x-nexus-agents-secret`: no person, key, agent link or operator of an organization reaches these rows, and every other route refuses the secret with a 403. Gateway never opens a value, and writes no audit event: the rows belong to no organization.

Permission: `chat_apps.runtime` ().

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `collection` | path | string | yes | 1 to 64 characters: a lowercase letter, then lowercase letters, digits, _ or - (400 agent_memory_collection_invalid) |
| `key` | path | string | yes | 1 to 256 characters of A-Z, a-z, 0-9, ., _, ~ and -, and not . or .. (400 agent_memory_key_invalid). Encode any other key, as base64url. |
| `If-Match` | header | string | no | The version the write read (`"12"` or `12`, the row's `ETag`). The write happens only while the row is at it. |
| `If-None-Match` | header | "*" | no | `*`: create the row, only when none exists. |
| `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)

- `value` (string, required): The agent's sealed text, at most 256 KiB [min length 1]

### Responses

- `200` Written (application/json, AgentMemoryWritten)
  - `collection` (string, required)
  - `key` (string, required)
  - `version` (integer, required): What a later write names in If-Match. It never repeats, also after a delete. [min 1]
  - `created` (boolean, required): True when the write made the row (If-None-Match: *)
  - `updatedAt` (string (date-time), required)
- `400` The platform secret came with another credential, or twice (`credential_conflict`); or a bad collection, key, limit or precondition (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.
- `401` No credential, or a wrong platform secret (`missing_credential`, `invalid_credential`) (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` Any other credential: a person's token, an agent link, a service account key, a module key or Nexus UI's secret (`agents_secret_refused`, `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.
- `503` The Gateway holds no platform secret (`not_configured`) (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 |  | The platform secret came with another credential, or twice (`credential_conflict`); or a bad collection, key, limit or precondition |
| 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 |
| 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 |
| 503 |  | The Gateway holds no platform secret (`not_configured`) |

### Example

```sh
curl -X PUT "$NEXUS_URL/v1/agents/state/<collection>/<key>" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "value": "<value>"
  }'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#put%3A%2Fv1%2Fagents%2Fstate%2F%7Bcollection%7D%2F%7Bkey%7D)

## Delete agent state

`DELETE /v1/agents/state/{collection}/{key}`

Delete one row of the agents service's own state at the version `If-Match: <version>` names (409 agent_memory_version_conflict when the row is at another version, or gone). Without `If-Match`, a 428 agent_memory_precondition_required: several processes share these rows, so a delete names what it read. The agents service only, with its platform secret in `x-nexus-agents-secret`: no person, key, agent link or operator of an organization reaches these rows, and every other route refuses the secret with a 403. Gateway never opens a value, and writes no audit event: the rows belong to no organization.

Permission: `chat_apps.runtime` ().

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `collection` | path | string | yes | 1 to 64 characters: a lowercase letter, then lowercase letters, digits, _ or - (400 agent_memory_collection_invalid) |
| `key` | path | string | yes | 1 to 256 characters of A-Z, a-z, 0-9, ., _, ~ and -, and not . or .. (400 agent_memory_key_invalid). Encode any other key, as base64url. |
| `If-Match` | header | string | no | The version the write read (`"12"` or `12`, the row's `ETag`). The write happens only while the row is at it. |
| `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 (application/json, AgentMemoryDeleted)
  - `collection` (string, required)
  - `key` (string, required)
  - `version` (integer, required): The version the row had
- `400` The platform secret came with another credential, or twice (`credential_conflict`); or a bad collection, key, limit or precondition (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.
- `401` No credential, or a wrong platform secret (`missing_credential`, `invalid_credential`) (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` Any other credential: a person's token, an agent link, a service account key, a module key or Nexus UI's secret (`agents_secret_refused`, `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.
- `503` The Gateway holds no platform secret (`not_configured`) (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 |  | The platform secret came with another credential, or twice (`credential_conflict`); or a bad collection, key, limit or precondition |
| 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 |
| 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 |
| 503 |  | The Gateway holds no platform secret (`not_configured`) |

### Example

```sh
curl -X DELETE "$NEXUS_URL/v1/agents/state/<collection>/<key>" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#delete%3A%2Fv1%2Fagents%2Fstate%2F%7Bcollection%7D%2F%7Bkey%7D)

## Get agent profile

`GET /v1/agents/profiles/{id}`

One agent profile you see. The person, or their own agent link that holds `agents.profiles` (on the person's opt-in); no operator grant names it. Another person's personal agent is a 404 agent_profile_not_found. 503 not_configured when Gateway has no database.

Permission: `agents.profiles` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The profile's id (`agp_…`) |

### Responses

- `200` OK (application/json, AgentProfile)
  - `name` (string): The display name: plain text without <, > or @. Not Nexus nor an admin's name (400 agent_profile_name_reserved), except that a personal agent may keep its own name, Nexus [min length 1; max length 40]
  - `avatar` (string | null): An emoji, a :shortcode: or an https image URL with no credentials (400 agent_profile_avatar_invalid) [max length 512]
  - `tone` ("calm" | "warm" | "direct" | "lively" | "custom" | null): A tone preset; custom leaves the tone to the instructions. null: the agent's own
  - `greeting` (string | null): One short line the agent says first in a conversation; control characters stripped (400 agent_profile_greeting_invalid) [max length 200]
  - `language` (string | null): A BCP-47 tag the agent answers in by default, such as es or pt-BR (400 agent_profile_language_invalid) [max length 35; pattern ^[A-Za-z]{2,3}(-[A-Za-z0-9]{1,8})*$]
  - `labels` (array of string): Short labels that sort, route and filter agents; repeats are dropped [at most 8 items]
  - `instructions` (string): The owner's guidance, added to the agent's system prompt below its own rules [max length 4000]
  - `tools` (array of string | null): Null: every tool the agent's link holds. A list: only these connectors or connector.operation ids; an empty list offers none [at most 64 items]
  - `proactivity` ("always" | "ask_first" | "never"): W4.3's levels: whether the agent may start something the person did not ask for
  - `length` (integer | null): How much the agent says: 0 brief to 100 detailed. null: its tone's own (400 agent_profile_personality_invalid) [min 0; max 100]
  - `formality` (integer | null): How formal the agent is: 0 casual to 100 formal. null: its tone's own (400 agent_profile_personality_invalid) [min 0; max 100]
  - `humour` (integer | null): How much humour the agent uses: 0 none to 100 some. null: its tone's own (400 agent_profile_personality_invalid) [min 0; max 100]
  - `emoji` (boolean | null): Emoji in the agent's answers. null: off
  - `shortTexts` (boolean | null): Shorter answers by text and push than in the app. null: on
  - `id` (string, required)
  - `owner` ("person" | "team", required): Person: a personal agent. team: a company agent, on that team's budget and policy
  - `ownerId` (string, required): The person's user id, or the team's id
  - `teamSlug` (string): A company agent's team slug, while the team exists
  - `createdBy` (string, required): The user id of the person who created it
  - `createdAt` (string (date-time), required)
  - `updatedAt` (string (date-time), required)
- `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 |
| 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/agents/profiles/<id>" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Set agent profile

`PUT /v1/agents/profiles/{id}`

Replace an agent profile's fields; its owner never changes. The name is 1 to 40 characters of plain text, never Nexus nor a name that passes for an admin, except that a personal agent may keep its own name, Nexus (agent_profile_name_invalid, agent_profile_name_reserved). At most 8 labels (agent_profile_label_invalid), instructions of at most 4000 characters (agent_profile_instructions_invalid), and at most 64 tools, each a connector Gateway has or one of its operations (agent_profile_tool_invalid, agent_profile_tool_unknown). The tools narrow what the agent offers and never widen it: Policy still decides each call. Audited as `agent.profile_updated`, with the labels and never the instructions. Only a person, never an agent link: your own personal agent, and as an owner or admin a company agent (403 agent_profile_admin_required otherwise). No operator grant names it. 503 not_configured when Gateway has no database.

Permission: `agents.profiles_manage` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The profile's id (`agp_…`) |
| `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)

- `name` (string): The display name: plain text without <, > or @. Not Nexus nor an admin's name (400 agent_profile_name_reserved), except that a personal agent may keep its own name, Nexus [min length 1; max length 40]
- `avatar` (string | null): An emoji, a :shortcode: or an https image URL with no credentials (400 agent_profile_avatar_invalid) [max length 512]
- `tone` ("calm" | "warm" | "direct" | "lively" | "custom" | null): A tone preset; custom leaves the tone to the instructions. null: the agent's own
- `greeting` (string | null): One short line the agent says first in a conversation; control characters stripped (400 agent_profile_greeting_invalid) [max length 200]
- `language` (string | null): A BCP-47 tag the agent answers in by default, such as es or pt-BR (400 agent_profile_language_invalid) [max length 35; pattern ^[A-Za-z]{2,3}(-[A-Za-z0-9]{1,8})*$]
- `labels` (array of string): Short labels that sort, route and filter agents; repeats are dropped [at most 8 items]
- `instructions` (string): The owner's guidance, added to the agent's system prompt below its own rules [max length 4000]
- `tools` (array of string | null): Null: every tool the agent's link holds. A list: only these connectors or connector.operation ids; an empty list offers none [at most 64 items]
- `proactivity` ("always" | "ask_first" | "never"): W4.3's levels: whether the agent may start something the person did not ask for
- `length` (integer | null): How much the agent says: 0 brief to 100 detailed. null: its tone's own (400 agent_profile_personality_invalid) [min 0; max 100]
- `formality` (integer | null): How formal the agent is: 0 casual to 100 formal. null: its tone's own (400 agent_profile_personality_invalid) [min 0; max 100]
- `humour` (integer | null): How much humour the agent uses: 0 none to 100 some. null: its tone's own (400 agent_profile_personality_invalid) [min 0; max 100]
- `emoji` (boolean | null): Emoji in the agent's answers. null: off
- `shortTexts` (boolean | null): Shorter answers by text and push than in the app. null: on

### Responses

- `200` OK (application/json, AgentProfile)
  - `name` (string): The display name: plain text without <, > or @. Not Nexus nor an admin's name (400 agent_profile_name_reserved), except that a personal agent may keep its own name, Nexus [min length 1; max length 40]
  - `avatar` (string | null): An emoji, a :shortcode: or an https image URL with no credentials (400 agent_profile_avatar_invalid) [max length 512]
  - `tone` ("calm" | "warm" | "direct" | "lively" | "custom" | null): A tone preset; custom leaves the tone to the instructions. null: the agent's own
  - `greeting` (string | null): One short line the agent says first in a conversation; control characters stripped (400 agent_profile_greeting_invalid) [max length 200]
  - `language` (string | null): A BCP-47 tag the agent answers in by default, such as es or pt-BR (400 agent_profile_language_invalid) [max length 35; pattern ^[A-Za-z]{2,3}(-[A-Za-z0-9]{1,8})*$]
  - `labels` (array of string): Short labels that sort, route and filter agents; repeats are dropped [at most 8 items]
  - `instructions` (string): The owner's guidance, added to the agent's system prompt below its own rules [max length 4000]
  - `tools` (array of string | null): Null: every tool the agent's link holds. A list: only these connectors or connector.operation ids; an empty list offers none [at most 64 items]
  - `proactivity` ("always" | "ask_first" | "never"): W4.3's levels: whether the agent may start something the person did not ask for
  - `length` (integer | null): How much the agent says: 0 brief to 100 detailed. null: its tone's own (400 agent_profile_personality_invalid) [min 0; max 100]
  - `formality` (integer | null): How formal the agent is: 0 casual to 100 formal. null: its tone's own (400 agent_profile_personality_invalid) [min 0; max 100]
  - `humour` (integer | null): How much humour the agent uses: 0 none to 100 some. null: its tone's own (400 agent_profile_personality_invalid) [min 0; max 100]
  - `emoji` (boolean | null): Emoji in the agent's answers. null: off
  - `shortTexts` (boolean | null): Shorter answers by text and push than in the app. null: on
  - `id` (string, required)
  - `owner` ("person" | "team", required): Person: a personal agent. team: a company agent, on that team's budget and policy
  - `ownerId` (string, required): The person's user id, or the team's id
  - `teamSlug` (string): A company agent's team slug, while the team exists
  - `createdBy` (string, required): The user id of the person who created it
  - `createdAt` (string (date-time), required)
  - `updatedAt` (string (date-time), required)
- `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 |
| 404 | `not_found` | Nothing matches the path in your organization |
| 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 PUT "$NEXUS_URL/v1/agents/profiles/<id>" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Platform",
    "avatar": "<avatar>",
    "tone": "calm",
    "greeting": "<greeting>",
    "language": "<language>",
    "labels": [
      "CI"
    ],
    "instructions": "<instructions>",
    "tools": [
      "<tool>"
    ],
    "proactivity": "always",
    "length": 0,
    "formality": 0,
    "humour": 0,
    "emoji": false,
    "shortTexts": false
  }'
```

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

## Delete agent profile

`DELETE /v1/agents/profiles/{id}`

Delete an agent profile. Audited as `agent.profile_deleted`. Only a person, never an agent link: your own personal agent, and as an owner or admin a company agent (403 agent_profile_admin_required otherwise). No operator grant names it. 503 not_configured when Gateway has no database.

Permission: `agents.profiles_manage` (Every member).

### Parameters

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

### Responses

- `204` Deleted
- `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 |
| 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/agents/profiles/<id>" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

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

## List agent profiles

`GET /v1/agents/profiles`

Your agents' profiles, by name: your own personal agent and every company agent in the organization. The person, or their own agent link that holds `agents.profiles` (on the person's opt-in); no operator grant names it. Another person's personal agent is a 404 agent_profile_not_found. 503 not_configured when Gateway has no database.

Permission: `agents.profiles` (Every member).

### Responses

- `200` OK (application/json, AgentProfileList)
  - `data` (array of AgentProfile, required)
    - `name` (string): The display name: plain text without <, > or @. Not Nexus nor an admin's name (400 agent_profile_name_reserved), except that a personal agent may keep its own name, Nexus [min length 1; max length 40]
    - `avatar` (string | null): An emoji, a :shortcode: or an https image URL with no credentials (400 agent_profile_avatar_invalid) [max length 512]
    - `tone` ("calm" | "warm" | "direct" | "lively" | "custom" | null): A tone preset; custom leaves the tone to the instructions. null: the agent's own
    - `greeting` (string | null): One short line the agent says first in a conversation; control characters stripped (400 agent_profile_greeting_invalid) [max length 200]
    - `language` (string | null): A BCP-47 tag the agent answers in by default, such as es or pt-BR (400 agent_profile_language_invalid) [max length 35; pattern ^[A-Za-z]{2,3}(-[A-Za-z0-9]{1,8})*$]
    - `labels` (array of string): Short labels that sort, route and filter agents; repeats are dropped [at most 8 items]
    - `instructions` (string): The owner's guidance, added to the agent's system prompt below its own rules [max length 4000]
    - `tools` (array of string | null): Null: every tool the agent's link holds. A list: only these connectors or connector.operation ids; an empty list offers none [at most 64 items]
    - `proactivity` ("always" | "ask_first" | "never"): W4.3's levels: whether the agent may start something the person did not ask for
    - `length` (integer | null): How much the agent says: 0 brief to 100 detailed. null: its tone's own (400 agent_profile_personality_invalid) [min 0; max 100]
    - `formality` (integer | null): How formal the agent is: 0 casual to 100 formal. null: its tone's own (400 agent_profile_personality_invalid) [min 0; max 100]
    - `humour` (integer | null): How much humour the agent uses: 0 none to 100 some. null: its tone's own (400 agent_profile_personality_invalid) [min 0; max 100]
    - `emoji` (boolean | null): Emoji in the agent's answers. null: off
    - `shortTexts` (boolean | null): Shorter answers by text and push than in the app. null: on
    - `id` (string, required)
    - `owner` ("person" | "team", required): Person: a personal agent. team: a company agent, on that team's budget and policy
    - `ownerId` (string, required): The person's user id, or the team's id
    - `teamSlug` (string): A company agent's team slug, while the team exists
    - `createdBy` (string, required): The user id of the person who created it
    - `createdAt` (string (date-time), required)
    - `updatedAt` (string (date-time), required)
- `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 |
| 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/agents/profiles" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Create agent profile

`POST /v1/agents/profiles`

Create an agent profile: without `team`, your personal agent; with `team` (a slug or id), a company agent that answers on that team's budget and policy (404 unknown_team). One profile per owner (409 agent_profile_exists). The name is 1 to 40 characters of plain text, never Nexus nor a name that passes for an admin, except that a personal agent may keep its own name, Nexus (agent_profile_name_invalid, agent_profile_name_reserved). At most 8 labels (agent_profile_label_invalid), instructions of at most 4000 characters (agent_profile_instructions_invalid), and at most 64 tools, each a connector Gateway has or one of its operations (agent_profile_tool_invalid, agent_profile_tool_unknown). The tools narrow what the agent offers and never widen it: Policy still decides each call. Audited as `agent.profile_created`, with the labels and never the instructions. Only a person, never an agent link: your own personal agent, and as an owner or admin a company agent (403 agent_profile_admin_required otherwise). No operator grant names it. 503 not_configured when Gateway has no database.

Permission: `agents.profiles_manage` (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)

- `name` (string): The display name: plain text without <, > or @. Not Nexus nor an admin's name (400 agent_profile_name_reserved), except that a personal agent may keep its own name, Nexus [min length 1; max length 40]
- `avatar` (string | null): An emoji, a :shortcode: or an https image URL with no credentials (400 agent_profile_avatar_invalid) [max length 512]
- `tone` ("calm" | "warm" | "direct" | "lively" | "custom" | null): A tone preset; custom leaves the tone to the instructions. null: the agent's own
- `greeting` (string | null): One short line the agent says first in a conversation; control characters stripped (400 agent_profile_greeting_invalid) [max length 200]
- `language` (string | null): A BCP-47 tag the agent answers in by default, such as es or pt-BR (400 agent_profile_language_invalid) [max length 35; pattern ^[A-Za-z]{2,3}(-[A-Za-z0-9]{1,8})*$]
- `labels` (array of string): Short labels that sort, route and filter agents; repeats are dropped [at most 8 items]
- `instructions` (string): The owner's guidance, added to the agent's system prompt below its own rules [max length 4000]
- `tools` (array of string | null): Null: every tool the agent's link holds. A list: only these connectors or connector.operation ids; an empty list offers none [at most 64 items]
- `proactivity` ("always" | "ask_first" | "never"): W4.3's levels: whether the agent may start something the person did not ask for
- `length` (integer | null): How much the agent says: 0 brief to 100 detailed. null: its tone's own (400 agent_profile_personality_invalid) [min 0; max 100]
- `formality` (integer | null): How formal the agent is: 0 casual to 100 formal. null: its tone's own (400 agent_profile_personality_invalid) [min 0; max 100]
- `humour` (integer | null): How much humour the agent uses: 0 none to 100 some. null: its tone's own (400 agent_profile_personality_invalid) [min 0; max 100]
- `emoji` (boolean | null): Emoji in the agent's answers. null: off
- `shortTexts` (boolean | null): Shorter answers by text and push than in the app. null: on
- `team` (string): A team's slug or id: a company agent for that team. Absent: your personal agent

### Responses

- `201` Created (application/json, AgentProfile)
  - `name` (string): The display name: plain text without <, > or @. Not Nexus nor an admin's name (400 agent_profile_name_reserved), except that a personal agent may keep its own name, Nexus [min length 1; max length 40]
  - `avatar` (string | null): An emoji, a :shortcode: or an https image URL with no credentials (400 agent_profile_avatar_invalid) [max length 512]
  - `tone` ("calm" | "warm" | "direct" | "lively" | "custom" | null): A tone preset; custom leaves the tone to the instructions. null: the agent's own
  - `greeting` (string | null): One short line the agent says first in a conversation; control characters stripped (400 agent_profile_greeting_invalid) [max length 200]
  - `language` (string | null): A BCP-47 tag the agent answers in by default, such as es or pt-BR (400 agent_profile_language_invalid) [max length 35; pattern ^[A-Za-z]{2,3}(-[A-Za-z0-9]{1,8})*$]
  - `labels` (array of string): Short labels that sort, route and filter agents; repeats are dropped [at most 8 items]
  - `instructions` (string): The owner's guidance, added to the agent's system prompt below its own rules [max length 4000]
  - `tools` (array of string | null): Null: every tool the agent's link holds. A list: only these connectors or connector.operation ids; an empty list offers none [at most 64 items]
  - `proactivity` ("always" | "ask_first" | "never"): W4.3's levels: whether the agent may start something the person did not ask for
  - `length` (integer | null): How much the agent says: 0 brief to 100 detailed. null: its tone's own (400 agent_profile_personality_invalid) [min 0; max 100]
  - `formality` (integer | null): How formal the agent is: 0 casual to 100 formal. null: its tone's own (400 agent_profile_personality_invalid) [min 0; max 100]
  - `humour` (integer | null): How much humour the agent uses: 0 none to 100 some. null: its tone's own (400 agent_profile_personality_invalid) [min 0; max 100]
  - `emoji` (boolean | null): Emoji in the agent's answers. null: off
  - `shortTexts` (boolean | null): Shorter answers by text and push than in the app. null: on
  - `id` (string, required)
  - `owner` ("person" | "team", required): Person: a personal agent. team: a company agent, on that team's budget and policy
  - `ownerId` (string, required): The person's user id, or the team's id
  - `teamSlug` (string): A company agent's team slug, while the team exists
  - `createdBy` (string, required): The user id of the person who created it
  - `createdAt` (string (date-time), required)
  - `updatedAt` (string (date-time), required)
- `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 |
| 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/agents/profiles" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Platform",
    "avatar": "<avatar>",
    "tone": "calm",
    "greeting": "<greeting>",
    "language": "<language>",
    "labels": [
      "CI"
    ],
    "instructions": "<instructions>",
    "tools": [
      "<tool>"
    ],
    "proactivity": "always",
    "length": 0,
    "formality": 0,
    "humour": 0,
    "emoji": false,
    "shortTexts": false,
    "team": "platform"
  }'
```

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