# Service accounts

> Service accounts: callers for CI and scripts. An owner or admin makes one, a member answers for it, a team owns it, and it expires (365 days at most). It is no member and holds no seat. Its keys (`nxsa_…`) are stored as a hash and shown once (a replay of the same `Idempotency-Key` within 24 hours shows one again), live 90 days by default, and stop when the account is revoked or expires, its owner leaves the organization, or its team is deleted. They reach the public endpoints only, until a Policy Engine statement admits them to more.

## List service accounts

`GET /v1/service-accounts`

The organization's service accounts (owners and admins: `service_accounts.manage`), newest first. Each has every key it held, live or not, newest first. Never a token or its hash. `limit` and `cursor` page it.

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

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `limit` | query | integer | no | Items per page, 1 to 500 (default 100). Without limit or cursor the answer holds the whole list. |
| `cursor` | query | string | no | NextCursor from the previous page. A cursor whose item left the list answers 400 `invalid_cursor`. |

### Responses

- `200` OK (application/json, ServiceAccountList)
  - `serviceAccounts` (array of ServiceAccount, required)
    - `id` (string, required): `sva_…`
    - `name` (string, required)
    - `ownerUserId` (string, required): The member who answers for it. Its keys stop when they leave the organization.
    - `teamId` (string, required): The team that owns it. Its keys stop when the team is deleted.
    - `createdBy` (string, required): The person who made it.
    - `createdAt` (string (date-time), required)
    - `expiresAt` (string (date-time), required)
    - `revokedAt` (string (date-time))
    - `keys` (array of ServiceAccountKey, required): Every key it held, newest first.
      - `id` (string, required): `sak_…`
      - `serviceAccountId` (string, required)
      - `ownerUserId` (string, required): The member who answers for its account, as the account holds it now. The key stops when they leave the organization.
      - `scope` (ServiceAccountScope, required): What a key reaches, which is its account's. Read from the account when the key is shown, never stored on the key.
        - `teamId` (string, required): The team that owns the account. Its keys stop when the team is deleted.
      - `prefix` (string, required): The first characters of the token, to recognise it in a list.
      - `label` (string)
      - `createdBy` (string, required): The person who issued it.
      - `createdAt` (string (date-time), required)
      - `expiresAt` (string (date-time), required)
      - `revokedAt` (string (date-time))
      - `lastUsedAt` (string (date-time)): When the key last authenticated, written at most once an hour.
      - `rotatedFrom` (string): The key this one replaced in a rotation.
  - `nextCursor` (string): The next page's cursor, while more items follow. Only when limit or cursor was sent.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

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

### Example

```sh
curl "$NEXUS_URL/v1/service-accounts" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Create service account

`POST /v1/service-accounts`

Make a service account, a caller for CI and scripts (owners and admins: `service_accounts.manage`). A member answers for it (`ownerUserId`, the caller by default) and a team owns it (`team`, its slug or id). It expires at `expiresAt`, at most 365 days from now. An organization holds at most 100 live accounts: the 101st is a 409 `service_account_limit`. It is no member and holds no seat. Its keys (`nxsa_…`) reach the public endpoints only, until a Policy Engine statement admits them to more: every other route answers 403. It has no key until one is issued. Audited as `service_account.created`. With `dryRun: true` everything is checked and nothing is written: the answer is a 200 with the account as it would be made, and its id is never used.

Permission: `service_accounts.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)

- `name` (string, required) [min length 1; max length 64]
- `ownerUserId` (string): The member who answers for it. The caller by default.
- `team` (string, required): The team that owns it: its slug or id.
- `expiresAt` (string (date-time), required): In the future, at most 365 days from now.
- `dryRun` (boolean): Check everything and write nothing. [default false]

### Responses

- `200` A dry run: the account as it would be made (application/json, CreatedServiceAccount)
  - `id` (string, required): `sva_…`
  - `name` (string, required)
  - `ownerUserId` (string, required): The member who answers for it. Its keys stop when they leave the organization.
  - `teamId` (string, required): The team that owns it. Its keys stop when the team is deleted.
  - `createdBy` (string, required): The person who made it.
  - `createdAt` (string (date-time), required)
  - `expiresAt` (string (date-time), required)
  - `revokedAt` (string (date-time))
  - `keys` (array of ServiceAccountKey, required): Every key it held, newest first.
    - `id` (string, required): `sak_…`
    - `serviceAccountId` (string, required)
    - `ownerUserId` (string, required): The member who answers for its account, as the account holds it now. The key stops when they leave the organization.
    - `scope` (ServiceAccountScope, required): What a key reaches, which is its account's. Read from the account when the key is shown, never stored on the key.
      - `teamId` (string, required): The team that owns the account. Its keys stop when the team is deleted.
    - `prefix` (string, required): The first characters of the token, to recognise it in a list.
    - `label` (string)
    - `createdBy` (string, required): The person who issued it.
    - `createdAt` (string (date-time), required)
    - `expiresAt` (string (date-time), required)
    - `revokedAt` (string (date-time))
    - `lastUsedAt` (string (date-time)): When the key last authenticated, written at most once an hour.
    - `rotatedFrom` (string): The key this one replaced in a rotation.
  - `dryRun` (boolean, required): A dry run's id is never used.
- `201` Created (application/json, CreatedServiceAccount)
  - `id` (string, required): `sva_…`
  - `name` (string, required)
  - `ownerUserId` (string, required): The member who answers for it. Its keys stop when they leave the organization.
  - `teamId` (string, required): The team that owns it. Its keys stop when the team is deleted.
  - `createdBy` (string, required): The person who made it.
  - `createdAt` (string (date-time), required)
  - `expiresAt` (string (date-time), required)
  - `revokedAt` (string (date-time))
  - `keys` (array of ServiceAccountKey, required): Every key it held, newest first.
    - `id` (string, required): `sak_…`
    - `serviceAccountId` (string, required)
    - `ownerUserId` (string, required): The member who answers for its account, as the account holds it now. The key stops when they leave the organization.
    - `scope` (ServiceAccountScope, required): What a key reaches, which is its account's. Read from the account when the key is shown, never stored on the key.
      - `teamId` (string, required): The team that owns the account. Its keys stop when the team is deleted.
    - `prefix` (string, required): The first characters of the token, to recognise it in a list.
    - `label` (string)
    - `createdBy` (string, required): The person who issued it.
    - `createdAt` (string (date-time), required)
    - `expiresAt` (string (date-time), required)
    - `revokedAt` (string (date-time))
    - `lastUsedAt` (string (date-time)): When the key last authenticated, written at most once an hour.
    - `rotatedFrom` (string): The key this one replaced in a rotation.
  - `dryRun` (boolean, required): A dry run's id is never used.
- `400` Not valid: no name (1 to 64 characters), an `expiresAt` that is not a future time within 365 days (`invalid_expiry`), an owner who is not a member (`owner_not_a_member`) or a team that is not the organization's (`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 |
| --- | --- | --- |
| 101 | `service_account_limit` | The 101st is a 409 `service_account_limit` |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 |  | Not valid: no name (1 to 64 characters), an `expiresAt` that is not a future time within 365 days (`invalid_expiry`), an owner who is not a member (`owner_not_a_member`) or a team that is not the organization's (`unknown_team`) |
| 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/service-accounts" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Platform",
    "team": "platform",
    "expiresAt": "2026-10-01T00:00:00Z"
  }'
```

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

## Revoke service account

`DELETE /v1/service-accounts/{id}`

Revoke a service account and every live key it holds, in one change (owners and admins: `service_accounts.manage`). Its keys answer as an unknown token from then on. Revoking a revoked account answers `already: true` and changes nothing. With `?dryRun=1` nothing changes: the answer counts the keys it would stop. Audited as `service_account.revoked`, with the ids of the keys it stopped. Another organization's account is a 404.

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

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The service account's id (`sva_…`) |
| `dryRun` | query | "1" \| "true" \| "0" \| "false" | no | `1` or `true`: check and change nothing. `0` or `false`: the same as none. Any other value is a 400, so a mistyped flag never revokes. |
| `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, ServiceAccountRevoked)
  - `id` (string, required)
  - `already` (boolean, required): It was revoked before this request.
  - `dryRun` (boolean, required)
  - `revokedAt` (string (date-time) | null)
  - `keysRevoked` (integer, required): The live keys it stopped (with `dryRun`, the ones it would stop).
- `400` `dryRun` is not `1`, `true`, `0` or `false` (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `404` No such service account in this organization (`unknown_service_account`) (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 |  | `dryRun` is not `1`, `true`, `0` or `false` |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such service account in this organization (`unknown_service_account`) |
| 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/service-accounts/<id>" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

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

## Issue service account key

`POST /v1/service-accounts/{id}/keys`

Issue a key for a service account (owners and admins: `service_accounts.manage`). The token (`nxsa_…`) is in this answer, and in a replay of it (same `Idempotency-Key`, within 24 hours), as for `POST /v1/auth/tokens`: Gateway keeps only its hash. The key lives 90 days unless `expiresAt` says otherwise, and never past its account. An account holds at most 5 live keys: the sixth is a 409 `service_account_key_limit`. A revoked or expired account takes no key (409 `service_account_revoked`, `service_account_expired`). Audited as `service_account.key_created`, never with the token.

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

### Parameters

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

- `label` (string): Required to issue a key. A rotation keeps the old label when it names none. [min length 1; max length 80]
- `expiresAt` (string (date-time)): In the future and not past the account's own expiry. 90 days from now by default, or the account's expiry if that comes first. A rotation keeps the old key's lifetime by default.

### Responses

- `201` Created (application/json, CreatedServiceAccountKey)
  - `id` (string, required): `sak_…`
  - `serviceAccountId` (string, required)
  - `ownerUserId` (string, required): The member who answers for its account, as the account holds it now. The key stops when they leave the organization.
  - `scope` (ServiceAccountScope, required): What a key reaches, which is its account's. Read from the account when the key is shown, never stored on the key.
    - `teamId` (string, required): The team that owns the account. Its keys stop when the team is deleted.
  - `prefix` (string, required): The first characters of the token, to recognise it in a list.
  - `label` (string)
  - `createdBy` (string, required): The person who issued it.
  - `createdAt` (string (date-time), required)
  - `expiresAt` (string (date-time), required)
  - `revokedAt` (string (date-time))
  - `lastUsedAt` (string (date-time)): When the key last authenticated, written at most once an hour.
  - `rotatedFrom` (string): The key this one replaced in a rotation.
  - `token` (string, required): `nxsa_…`. In this answer, and in a replay of it (same `Idempotency-Key`) within 24 hours.
- `400` No label (1 to 80 characters), or an `expiresAt` that is not a future time within the account's life (`invalid_expiry`) (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `404` No such service account in this organization (`unknown_service_account`) (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 account is revoked or expired, or holds 5 live keys (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 |  | No label (1 to 80 characters), or an `expiresAt` that is not a future time within the account's life (`invalid_expiry`) |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such service account in this organization (`unknown_service_account`) |
| 409 |  | The account is revoked or expired, or holds 5 live keys |
| 409 | `service_account_key_limit` | The sixth is a 409 `service_account_key_limit` |
| 409 | `service_account_revoked` | A revoked or expired account takes no key (409 `service_account_revoked`, `service_account_expired`) |
| 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/service-accounts/<id>/keys" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "label": "CI",
    "expiresAt": "2026-10-01T00:00:00Z"
  }'
```

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

## Revoke service account key

`DELETE /v1/service-accounts/{id}/keys/{keyId}`

Revoke one key of a service account (owners and admins: `service_accounts.manage`). The key answers as an unknown token from then on. A key that is already revoked answers as it was, and nothing changes. A key of another service account is a 404. Audited as `service_account.key_revoked`.

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

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The service account's id (`sva_…`) |
| `keyId` | path | string | yes | The key's id (`sak_…`) |
| `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, ServiceAccountKey)
  - `id` (string, required): `sak_…`
  - `serviceAccountId` (string, required)
  - `ownerUserId` (string, required): The member who answers for its account, as the account holds it now. The key stops when they leave the organization.
  - `scope` (ServiceAccountScope, required): What a key reaches, which is its account's. Read from the account when the key is shown, never stored on the key.
    - `teamId` (string, required): The team that owns the account. Its keys stop when the team is deleted.
  - `prefix` (string, required): The first characters of the token, to recognise it in a list.
  - `label` (string)
  - `createdBy` (string, required): The person who issued it.
  - `createdAt` (string (date-time), required)
  - `expiresAt` (string (date-time), required)
  - `revokedAt` (string (date-time))
  - `lastUsedAt` (string (date-time)): When the key last authenticated, written at most once an hour.
  - `rotatedFrom` (string): The key this one replaced in a rotation.
- `404` No such key in this service account (`unknown_service_account_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 |
| --- | --- | --- |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such key in this service account (`unknown_service_account_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 DELETE "$NEXUS_URL/v1/service-accounts/<id>/keys/<keyId>" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

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

## Rotate service account key

`POST /v1/service-accounts/{id}/keys/{keyId}/rotate`

Replace a live key with a new one, in one change (owners and admins: `service_accounts.manage`). The old key stops at once. The answer holds the new key and its token, once (a replay with the same `Idempotency-Key` within 24 hours returns it again). The new key keeps the old label unless `label` names another, and lives as long as the old key did unless `expiresAt` says otherwise, never past its account. A key that is revoked or expired does not rotate (409 `key_not_live`). Audited as `service_account.key_rotated`, with the old key as `before` and the new as `after`.

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

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The service account's id (`sva_…`) |
| `keyId` | path | string | yes | The key's id (`sak_…`) |
| `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)

- `label` (string): Required to issue a key. A rotation keeps the old label when it names none. [min length 1; max length 80]
- `expiresAt` (string (date-time)): In the future and not past the account's own expiry. 90 days from now by default, or the account's expiry if that comes first. A rotation keeps the old key's lifetime by default.

### Responses

- `200` OK (application/json, CreatedServiceAccountKey)
  - `id` (string, required): `sak_…`
  - `serviceAccountId` (string, required)
  - `ownerUserId` (string, required): The member who answers for its account, as the account holds it now. The key stops when they leave the organization.
  - `scope` (ServiceAccountScope, required): What a key reaches, which is its account's. Read from the account when the key is shown, never stored on the key.
    - `teamId` (string, required): The team that owns the account. Its keys stop when the team is deleted.
  - `prefix` (string, required): The first characters of the token, to recognise it in a list.
  - `label` (string)
  - `createdBy` (string, required): The person who issued it.
  - `createdAt` (string (date-time), required)
  - `expiresAt` (string (date-time), required)
  - `revokedAt` (string (date-time))
  - `lastUsedAt` (string (date-time)): When the key last authenticated, written at most once an hour.
  - `rotatedFrom` (string): The key this one replaced in a rotation.
  - `token` (string, required): `nxsa_…`. In this answer, and in a replay of it (same `Idempotency-Key`) within 24 hours.
- `400` A label that is not 1 to 80 characters, or an `expiresAt` that is not a future time within the account's life (`invalid_expiry`) (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `404` No such key in this service account, or no such service account (`unknown_service_account_key`, `unknown_service_account`) (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 key is not live (`key_not_live`), or its account is revoked or expired (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 |  | A label that is not 1 to 80 characters, or an `expiresAt` that is not a future time within the account's life (`invalid_expiry`) |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such key in this service account, or no such service account (`unknown_service_account_key`, `unknown_service_account`) |
| 409 |  | The key is not live (`key_not_live`), or its account is revoked or expired |
| 409 | `key_not_live` | A key that is revoked or expired does not rotate (409 `key_not_live`) |
| 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/service-accounts/<id>/keys/<keyId>/rotate" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "label": "CI",
    "expiresAt": "2026-10-01T00:00:00Z"
  }'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fservice-accounts%2F%7Bid%7D%2Fkeys%2F%7BkeyId%7D%2Frotate)
