# Organizations

> An organization's members and roles (one owner, admins, members), ownership and budget. When the sign-in provider holds the organization, its roles change through Nexus UI, which updates the provider first.

## List orgs

`GET /v1/orgs`

Your organizations: your personal organization first, then each company organization, with your role in each and which one this request is in.

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

### Responses

- `200` OK (application/json, OrgList)
  - `orgs` (array of OrgSummary, required)
    - `id` (string, required)
    - `name` (string, required)
    - `slug` (string)
    - `clerkOrgId` (string): Its sign-in provider organization's id: Nexus UI's URL segment when it has no slug
    - `kind` ("company" | "personal", required): A company organization, or a person's own personal organization (one per person, one member)
    - `role` ("owner" | "admin" | "member")
    - `current` (boolean): The organization this request is in
    - `imageUrl` (string): Its logo, as the tenant's imageUrl (https://img.clerk.com/…); unset when it has none.
- `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/orgs" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Create org

`POST /v1/orgs`

Create a company organization that Nexus Gateway alone holds, with no sign-in provider organization behind it. You become its owner. Without a slug, the first free one made from the name is used. Only once the Gateway holds organizations; before that, 409 `use_nexus_ui`. Audited as org.created and member.joined.

Permission: `org.create` (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, required): 1 to 120 characters after trimming
- `slug` (string): A lowercase DNS label that is not a Nexus UI page (`settings`, `invite`, …) [pattern ^[a-z0-9][a-z0-9-]{0,62}$]

### Responses

- `201` Created (application/json, OrgSummary)
  - `id` (string, required)
  - `name` (string, required)
  - `slug` (string)
  - `clerkOrgId` (string): Its sign-in provider organization's id: Nexus UI's URL segment when it has no slug
  - `kind` ("company" | "personal", required): A company organization, or a person's own personal organization (one per person, one member)
  - `role` ("owner" | "admin" | "member")
  - `current` (boolean): The organization this request is in
  - `imageUrl` (string): Its logo, as the tenant's imageUrl (https://img.clerk.com/…); unset when it has none.
- `400` The request is not valid; the message names the field. A JSON body that is not an object, or a string in it that holds U+0000 (`nul_in_string`), is a 400 on every route that reads one. So is an `Idempotency-Key` that is not 1 to 255 printable ASCII characters (`invalid_idempotency_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.
- `409` Another company organization has the slug (`slug_taken`), or the sign-in provider still holds the Gateway's organizations (`use_nexus_ui`) (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` `cutover_paused`: only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. (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 request is not valid; the message names the field. A JSON body that is not an object, or a string in it that holds U+0000 (`nul_in_string`), is a 400 on every route that reads one. So is an `Idempotency-Key` that is not 1 to 255 printable ASCII characters (`invalid_idempotency_key`). |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 409 |  | Another company organization has the slug (`slug_taken`), or the sign-in provider still holds the Gateway's organizations (`use_nexus_ui`) |
| 409 | `use_nexus_ui` | Only once the Gateway holds organizations; before that, 409 `use_nexus_ui` |
| 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 |  | `cutover_paused`: only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/orgs" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Platform"
  }'
```

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

## Org waiting counts

`GET /v1/orgs/waiting`

Read your pending Gateway approvals and waiting cloud sessions by organization.

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

### Responses

- `200` OK (application/json, OrgWaitingCounts)
  - `counts` (object, required): Counts keyed by the caller’s current organization memberships.
  - `checkedAt` (integer, required): Gateway time in milliseconds since the Unix epoch.
- `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/orgs/waiting" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Switch org

`POST /v1/orgs/switch`

A new token for another of your organizations (by slug, id, or `personal`), of your credential's kind (`cli` or `ui`; an API key gets a `cli` token that is still an API key to the Gateway), and who you are there. Your current credential stays valid.

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

### Parameters

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

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

- `org` (string, required): A slug, an id, or personal

### Responses

- `200` OK (application/json, SwitchedOrg)
  - `tenant` (object, required)
    - `id` (string, required)
    - `name` (string, required)
    - `createdAt` (string (date-time), required)
    - `slug` (string)
    - `kind` ("company" | "personal"): A company organization, or a person's own personal organization (one per person, one member)
    - `imageUrl` (string): The organization's logo, as Clerk serves it (https://img.clerk.com/…); unset when it has none.
    - `mark` ("staff" | "test" | "demo"): Set only when it is Nexus's own; unset for a customer's.
  - `user` (object): The person calling, when the key is a person's
    - `id` (string, required)
    - `email` (string)
    - `name` (string)
    - `mark` ("staff" | "test" | "demo"): Set only when it is Nexus's own; unset for a customer's.
  - `teams` (array of object): Your teams in this organization
    - `id` (string)
    - `slug` (string)
    - `name` (string)
    - `role` ("lead" | "member"): `lead` is reserved for the planned team-lead role and grants nothing extra yet.
  - `team` (object): Your default team
    - `id` (string)
    - `slug` (string)
    - `name` (string)
  - `features` (GatewayFeatures): The products this Gateway has on. Unset reads as all off.
    - `wiki` (boolean, required): Nexus Wiki is on. Off, its routes and Ask your code answer 404 wiki_off, and clients hide them.
    - `apps` (boolean): Nexus Apps (`NEXUS_APPS_ENABLED`): `nexus apps` and /v1/apps. An older Gateway leaves it out: off.
    - `agentSessionAudit` (boolean): Coding agent sessions write agent_session.started and agent_session.ended audit events (`NEXUS_AUDIT_AGENT_SESSIONS`). An older Gateway leaves it out: off.
  - `token` (string, required): Nx_…: shown once
  - `tokenKind` ("cli" | "ui", required)
  - `expiresAt` (string (date-time))
- `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/orgs/switch" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "org": "<org>"
  }'
```

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

## Delete account

`POST /v1/auth/account/delete`

Delete your own account, from a sign-in made in the last ten minutes (not an API key; a dry run says signInNeeded when yours is older). The sign-in provider deletes your sign-in, the payment provider deletes your personal organization's customer (its plan ends at once), and Gateway takes you out of every organization, closes your personal organization and erases your email and name. Your organizations' spend and audit trail stay, under your user id. Before the customer goes, paying after the fact turns off and one charge tries your personal organization's unpaid usage on the card on file; what it does not collect is written off (unpaidUsageUsd), and its Nexus credits are lost (creditsLostUsd). Refused while you own a company organization: transfer ownership first. A deletion needs confirm: "DELETE", which the person types to confirm. dryRun checks and changes nothing.

Permission: `account.delete` (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)

- `dryRun` (boolean)
- `confirm` ("DELETE"): What the person typed to confirm: DELETE. A deletion without it changes nothing (400 `confirmation_required`); a dry run needs none.

### Responses

- `200` OK (application/json, AccountDeleted)
  - `userId` (string, required)
  - `dryRun` (boolean, required)
  - `deleted` (boolean, required): False on a dry run; true once the account is deleted.
  - `personalOrg` (string): Your personal organization's id, closed with the account; absent when you have none.
  - `left` (array of object, required): The company organizations you leave.
    - `id` (string, required)
    - `name` (string, required)
  - `planEnded` (boolean, required): Whether your personal organization's plan and cards at the payment provider end with it.
  - `signInNeeded` (boolean, required): Whether you must sign in again first: only a sign-in from the last ten minutes deletes your account.
  - `unpaidUsageUsd` (string): Your personal organization's usage that its card has not paid, as a decimal dollar string. On a dry run, what the deletion charges to the card on file first. Once deleted, what that charge did not collect, which Nexus writes off. Absent when nothing is unpaid.
  - `creditsLostUsd` (string): Your personal organization's Nexus credits that the deletion loses, as a decimal dollar string. Nothing refunds them. Absent when none are left.
- `400` The person did not type DELETE to confirm (`confirmation_required`). Nothing changed. (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` A sign-in older than ten minutes (`recent_sign_in_required`): sign in again first. An API key, not a sign-in (`sign_in_required`), or a caller that is no person (`person_required`). Nothing changed. (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 account is already deleted (`not_found`). (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` You own a company organization (`owns_organization`); `nexus.organizations` lists each one's id, name and slug. Or calls your card pays for, or a charge for your usage, are still running (`usage_settling`): paying after the fact is now off; try again in 10 minutes. Nothing else changed. (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.
- `502` Clerk did not delete your sign-in (`clerk_unavailable`), or the payment provider did not delete the customer; retry. (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` This Gateway has no secret key for the sign-in provider, or no Stripe key while your personal organization has a customer (`not_configured`); nothing changed. Also `cutover_paused`, only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. (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 person did not type DELETE to confirm (`confirmation_required`). Nothing changed. |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 |  | The account is already deleted (`not_found`). |
| 409 |  | You own a company organization (`owns_organization`); `nexus.organizations` lists each one's id, name and slug. Or calls your card pays for, or a charge for your usage, are still running (`usage_settling`): paying after the fact is now off; try again in 10 minutes. Nothing else changed. |
| 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 |
| 502 |  | Clerk did not delete your sign-in (`clerk_unavailable`), or the payment provider did not delete the customer; retry. |
| 503 |  | This Gateway has no secret key for the sign-in provider, or no Stripe key while your personal organization has a customer (`not_configured`); nothing changed. Also `cutover_paused`, only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/auth/account/delete" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "dryRun": true,
    "confirm": "DELETE"
  }'
```

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

## Set org profile

`PATCH /v1/orgs/profile`

Rename your company organization, change its slug, or remove its logo (owners and admins). A personal organization that holds the slug moves to a free one. An organization the sign-in provider made changes here only once the Gateway holds organizations; before that, 409 `use_nexus_ui`. Audited as org.settings_changed.

Permission: `org.settings` (Owner, Admin).

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

- `name` (string): 1 to 120 characters after trimming
- `slug` (string): A lowercase DNS label that is not a Nexus UI page [pattern ^[a-z0-9][a-z0-9-]{0,62}$]
- `imageUrl` (null): Null removes the logo. A new logo is uploaded with setOrgLogo (POST /v1/orgs/logo)

### Responses

- `200` OK (application/json, OrgSummary)
  - `id` (string, required)
  - `name` (string, required)
  - `slug` (string)
  - `clerkOrgId` (string): Its sign-in provider organization's id: Nexus UI's URL segment when it has no slug
  - `kind` ("company" | "personal", required): A company organization, or a person's own personal organization (one per person, one member)
  - `role` ("owner" | "admin" | "member")
  - `current` (boolean): The organization this request is in
  - `imageUrl` (string): Its logo, as the tenant's imageUrl (https://img.clerk.com/…); unset when it has none.
- `400` The request is not valid; the message names the field. A JSON body that is not an object, or a string in it that holds U+0000 (`nul_in_string`), is a 400 on every route that reads one. So is an `Idempotency-Key` that is not 1 to 255 printable ASCII characters (`invalid_idempotency_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.
- `409` Another company organization has the slug (`slug_taken`), a personal organization's name and slug are its person's (`personal_org`), or the sign-in provider still holds this organization (`use_nexus_ui`) (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` `cutover_paused`: only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. (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 request is not valid; the message names the field. A JSON body that is not an object, or a string in it that holds U+0000 (`nul_in_string`), is a 400 on every route that reads one. So is an `Idempotency-Key` that is not 1 to 255 printable ASCII characters (`invalid_idempotency_key`). |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 409 |  | Another company organization has the slug (`slug_taken`), a personal organization's name and slug are its person's (`personal_org`), or the sign-in provider still holds this organization (`use_nexus_ui`) |
| 409 | `use_nexus_ui` | An organization the sign-in provider made changes here only once the Gateway holds organizations; before that, 409 `use_nexus_ui` |
| 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 |  | `cutover_paused`: only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. |

### Example

```sh
curl -X PATCH "$NEXUS_URL/v1/orgs/profile" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Platform",
    "slug": "platform"
  }'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#patch%3A%2Fv1%2Forgs%2Fprofile)

## Set org logo

`POST /v1/orgs/logo`

Upload your company organization's logo (owners and admins): the body is the image's bytes, a PNG, JPEG or WebP of 1 MB at most, typed by its first bytes. The Gateway stores it in Nexus's bucket and sets the organization's imageUrl to it. Only once the Gateway holds organizations; before that, 409 `use_nexus_ui`. Audited as org.settings_changed.

Permission: `org.settings` (Owner, Admin).

### Request body (image/png, required)

string (binary): the provider's own request.

### Responses

- `200` OK (application/json, OrgSummary)
  - `id` (string, required)
  - `name` (string, required)
  - `slug` (string)
  - `clerkOrgId` (string): Its sign-in provider organization's id: Nexus UI's URL segment when it has no slug
  - `kind` ("company" | "personal", required): A company organization, or a person's own personal organization (one per person, one member)
  - `role` ("owner" | "admin" | "member")
  - `current` (boolean): The organization this request is in
  - `imageUrl` (string): Its logo, as the tenant's imageUrl (https://img.clerk.com/…); unset when it has none.
- `400` The request is not valid; the message names the field. A JSON body that is not an object, or a string in it that holds U+0000 (`nul_in_string`), is a 400 on every route that reads one. So is an `Idempotency-Key` that is not 1 to 255 printable ASCII characters (`invalid_idempotency_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.
- `409` A personal organization has no logo to change (`personal_org`), or the Gateway does not hold organizations yet (`use_nexus_ui`) (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.
- `413` The image is over 1 MB (`request_too_large`) (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.
- `415` The image is not a PNG, JPEG or WebP by its first bytes (`unsupported_logo_type`) (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.
- `502` The bucket refused the image (`logo_storage_failed`); nothing changed (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` `logo_storage_unconfigured`: the Gateway has no bucket for logos (`NEXUS_ORG_LOGO_BUCKET`). `cutover_paused`: only while the operator pauses sign-in for the auth cutover; retry after `Retry-After` seconds. Nothing changed. (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 request is not valid; the message names the field. A JSON body that is not an object, or a string in it that holds U+0000 (`nul_in_string`), is a 400 on every route that reads one. So is an `Idempotency-Key` that is not 1 to 255 printable ASCII characters (`invalid_idempotency_key`). |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 409 |  | A personal organization has no logo to change (`personal_org`), or the Gateway does not hold organizations yet (`use_nexus_ui`) |
| 409 | `use_nexus_ui` | Only once the Gateway holds organizations; before that, 409 `use_nexus_ui` |
| 413 |  | The image is over 1 MB (`request_too_large`) |
| 415 |  | The image is not a PNG, JPEG or WebP by its first bytes (`unsupported_logo_type`) |
| 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 |
| 502 |  | The bucket refused the image (`logo_storage_failed`); nothing changed |
| 503 |  | `logo_storage_unconfigured`: the Gateway has no bucket for logos (`NEXUS_ORG_LOGO_BUCKET`). `cutover_paused`: only while the operator pauses sign-in for the auth cutover; retry after `Retry-After` seconds. Nothing changed. |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/orgs/logo" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '"<value>"'
```

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

## List members

`GET /v1/orgs/members`

The organization's members and roles; spend per person for owners and admins (and each person's own). `limit` and `cursor` page it.

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

### 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, object)
  - `members` (array of Member)
    - `userId` (string, required)
    - `email` (string)
    - `name` (string)
    - `role` ("owner" | "admin" | "member", required)
    - `joinedAt` (string (date-time), required)
    - `spentUsd` (number)
    - `calls` (integer)
  - `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/orgs/members" \
  -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.members();
```

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

## List presence

`GET /v1/presence`

Every member of the organization and whether they are online (seen in the last two minutes), online ones first (every role: `members.read`; a signed-in member only). `lastSeenAt` is set only while a member is online; a member who turned off showing reads offline to everyone else. You are always online to yourself. `showOnline` is your own setting. Each online member's `activity` says what they are doing, as you may see it.

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

### Responses

- `200` OK (application/json, PresenceList)
  - `members` (array of PresenceMember, required)
    - `userId` (string, required)
    - `name` (string | null, required)
    - `email` (string | null, required)
    - `role` ("owner" | "admin" | "member", required)
    - `online` (boolean, required): Seen within the online window. You are always online to yourself.
    - `lastSeenAt` (string (date-time) | null, required): The last heartbeat, only while it is within the online window.
    - `activity` (PresenceActivity | null, required): What they are doing, while online; null otherwise.
  - `onlineWindowSeconds` (integer, required): How long after a heartbeat a member still counts as online.
  - `showOnline` (boolean, required): Your own setting.

### 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 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

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

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

## Presence heartbeat

`POST /v1/presence`

Your heartbeat while Nexus UI is open and visible, about every 30 seconds (every role: `members.read`; a signed-in member only, 403 `role_required` otherwise). You count as online for two minutes after it. Gateway stores at most one every 20 seconds, and none while you turned off showing when you are online. It may carry what you are doing (`activity`): `chatting`, a `page` by id, or `idle`. A change of activity is stored at once. Answers your setting.

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

### Request body (application/json)

- `activity` (ReportedActivity): What Nexus UI reports with a heartbeat. Coarse on purpose: no chat title, no path, no repository. Gateway keeps a page's id only when you may open the page and reads its title itself. `agents` is taken as `idle`: Gateway counts running agents from agent sessions.
  - `kind` ("chatting" | "page" | "agents" | "idle", required)
  - `pageId` (string): Required with `page`.

### Responses

- `200` OK (application/json, PresenceSettings)
  - `showOnline` (boolean, required): Whether others see when you are online. On by default.
- `400` Not a known activity (`invalid_activity`) (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 |  | Not a known activity (`invalid_activity`) |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/presence" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "activity": {
      "kind": "chatting"
    }
  }'
```

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

## Get presence settings

`GET /v1/presence/settings`

Whether you show when you are online (every role: `members.read`; a signed-in member only). On unless you turned it off.

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

### Responses

- `200` OK (application/json, PresenceSettings)
  - `showOnline` (boolean, required): Whether others see when you are online. On by default.

### 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 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl "$NEXUS_URL/v1/presence/settings" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Set presence settings

`PUT /v1/presence/settings`

Choose whether you show when you are online (every role: `members.read`; a signed-in member only). Off, Gateway forgets your last heartbeat and stores none, so you read offline to everyone else at once; you still see yourself online.

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

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

- `showOnline` (boolean, required): Whether others see when you are online. On by default.

### Responses

- `200` OK (application/json, PresenceSettings)
  - `showOnline` (boolean, required): Whether others see when you are online. On by default.
- `400` Not `{ "showOnline": bool }` (`invalid_setting`) (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 |  | Not `{ "showOnline": bool }` (`invalid_setting`) |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl -X PUT "$NEXUS_URL/v1/presence/settings" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "showOnline": false
  }'
```

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

## Set member role

`POST /v1/orgs/members/{userId}/role`

Make a member an admin or a member (owners and admins). The owner's role changes only by transfer.

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

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `userId` | 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)

- `role` ("admin" | "member", required)

### Responses

- `200` OK (application/json, object)
- `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` `cutover_paused`: only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. (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 |
| 503 |  | `cutover_paused`: only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/orgs/members/user_123/role" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "role": "admin"
  }'
```

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

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.setMemberRole("<user id>", "admin");
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Forgs%2Fmembers%2F%7BuserId%7D%2Frole)

## Remove member

`DELETE /v1/orgs/members/{userId}`

Remove a member (owners and admins). The membership is flagged, not deleted, so an owner or admin can recover them for 30 days; their tokens and keys are revoked at once. The owner must transfer ownership first.

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

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `userId` | 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, object)
- `404` No such member (`not_found`). (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` They are the owner (`owner_role`): transfer ownership first. Or a token removes its own person (`self_removal`). (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.
- `502` A token's removal: Clerk did not take them out of its organization (`clerk_unavailable`); nothing changed. (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` A token's removal: the organization signs in with the sign-in provider and this Gateway has no secret key for it (`not_configured`); nothing changed. Also `cutover_paused`, only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. (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 member (`not_found`). |
| 409 |  | They are the owner (`owner_role`): transfer ownership first. Or a token removes its own person (`self_removal`). |
| 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 |
| 502 |  | A token's removal: Clerk did not take them out of its organization (`clerk_unavailable`); nothing changed. |
| 503 |  | A token's removal: the organization signs in with the sign-in provider and this Gateway has no secret key for it (`not_configured`); nothing changed. Also `cutover_paused`, only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. |

### Example

```sh
curl -X DELETE "$NEXUS_URL/v1/orgs/members/user_123" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

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

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.removeMember("<user id>");
```

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

## List removed members

`GET /v1/orgs/members/removed`

Removed members (owners and admins), newest removal first, each with the end of its 30-day recovery window.

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

### Responses

- `200` OK (application/json, RemovedMemberList)
  - `members` (array of RemovedMember, required)
    - `userId` (string, required)
    - `email` (string)
    - `name` (string)
    - `role` ("owner" | "admin" | "member", required)
    - `removedAt` (string (date-time), required)
    - `removedBy` (string): The user id who removed them; absent when the sign-in provider did.
    - `recoverableUntil` (string (date-time), required)
    - `recoverable` (boolean, 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/orgs/members/removed" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Recover member

`POST /v1/orgs/members/{userId}/recover`

Recover a removed member inside the 30-day window (owners and admins): their role, teams, default team and person spend limit come back; their tokens and keys do not. In an org that signs in with Clerk, Gateway adds them back to the Clerk organization. dryRun checks and changes nothing. A 409 removal_final after the window; 503 `not_configured` without CLERK_SECRET_KEY on Gateway, in an org that signs in with Clerk.

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

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `userId` | 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)

- `dryRun` (boolean)

### Responses

- `200` OK (application/json, MemberRecovered)
  - `userId` (string, required)
  - `email` (string)
  - `role` ("owner" | "admin" | "member", required)
  - `teams` (array of string, required): The slugs of the teams they come back to.
  - `dryRun` (boolean, required)
  - `recovered` (boolean, required)
- `404` No such member (`not_found`). (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` They are a member (`not_removed`), or the 30-day window ended (`removal_final`). (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.
- `502` Clerk did not add them back to its organization (`clerk_unavailable`); nothing changed. (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 organization signs in with the sign-in provider and this Gateway has no secret key for it (`not_configured`); nothing changed. Also `cutover_paused`, only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. (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 |  | No such member (`not_found`). |
| 409 |  | They are a member (`not_removed`), or the 30-day window ended (`removal_final`). |
| 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 |
| 502 |  | Clerk did not add them back to its organization (`clerk_unavailable`); nothing changed. |
| 503 |  | The organization signs in with the sign-in provider and this Gateway has no secret key for it (`not_configured`); nothing changed. Also `cutover_paused`, only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. |
| 503 | `not_configured` | A 409 removal_final after the window; 503 `not_configured` without CLERK_SECRET_KEY on Gateway, in an org that signs in with Clerk |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/orgs/members/user_123/recover" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "dryRun": true
  }'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Forgs%2Fmembers%2F%7BuserId%7D%2Frecover)

## List invitations

`GET /v1/orgs/invitations`

The organization's pending invitations, oldest first, expired ones included (owners and admins). Only once Core holds organizations (`NEXUS_ORG_OWNER=core`); before that, 409 `use_nexus_ui`.

Permission: `members.invite` (Owner, Admin).

### Responses

- `200` OK (application/json, object)
  - `invitations` (array of object, required)
    - `id` (string, required)
    - `email` (string, required)
    - `role` ("member" | "admin", required)
    - `invitedBy` (string | null): The person who invited them, when a person did.
    - `createdAt` (string (date-time), required)
    - `expiresAt` (string (date-time), required)
    - `sentAt` (string (date-time) | null): The last send.
    - `expired` (boolean, required): Past expiresAt: its link no longer works; resend it.
- `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 | `use_nexus_ui` | Only once Core holds organizations (`NEXUS_ORG_OWNER=core`); before that, 409 `use_nexus_ui` |
| 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/orgs/invitations" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Invite members

`POST /v1/orgs/invitations`

Invite people to the organization (owners and admins); Clerk emails each invitation. Name `emails`, or `pending: true` for everyone in a team by email who has not joined. Emails already in the organization or already invited are skipped. `dryRun` sends nothing. Sending more than one needs `expect`, the number you confirmed (409 `count_changed` if it differs). 501 without CLERK_SECRET_KEY on Gateway (dry runs still work, checking Gateway only). Once Core holds organizations (`NEXUS_ORG_OWNER=core`), Core writes each invitation and emails its one-time link itself; an expired invitation of the email is sent again.

Permission: `members.invite` (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)

- `emails` (array of string (email)) [at most 500 items]
- `pending` (boolean): Everyone with a pending team membership.
- `role` ("member" | "admin") [default "member"]
- `dryRun` (boolean) [default false]
- `expect` (integer): Required to send more than one invitation: how many you confirmed.

### Responses

- `200` OK (application/json, InvitationsResponse)
  - `dryRun` (boolean, required)
  - `role` ("member" | "admin", required)
  - `checkedClerk` (boolean, required): False on a dry run without CLERK_SECRET_KEY: only Gateway's members were checked.
  - `toSend` (integer, required): Invitations sent, or in a dry run, that would be.
  - `results` (array of object, required)
    - `email` (string, required)
    - `status` ("would_invite" | "sent" | "already_member" | "not_signed_in" | "already_invited" | "removed" | "failed", required)
    - `invitationId` (string)
    - `message` (string): The sign-in provider's message when it failed.
  - `counts` (object, 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.
- `503` `cutover_paused`: only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. (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 | `count_changed` | Sending more than one needs `expect`, the number you confirmed (409 `count_changed` if it differs) |
| 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 |  | `cutover_paused`: only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/orgs/invitations" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "pending": true,
    "dryRun": true
  }'
```

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

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

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

## Revoke invitation

`DELETE /v1/orgs/invitations/{id}`

Revoke a pending invitation (owners and admins), so its link stops working. While the sign-in provider holds organizations the id is the provider's and the provider cancels it; once Core holds them (`NEXUS_ORG_OWNER=core`) the id is Core's. Audited as `invitation.revoked`.

Permission: `members.invite` (Owner, Admin).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The invitation's id: the sign-in provider's while it holds organizations, else Core's from `GET /v1/orgs/invitations`. |
| `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, object)
  - `revoked` (boolean, 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.
- `503` `cutover_paused`: only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. (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 |
| 503 |  | `cutover_paused`: only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. |

### Example

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

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

## Resend invitation

`POST /v1/orgs/invitations/{id}/resend`

Email a pending invitation again with a new link and a new expiry, 7 days from now; the old link stops working (owners and admins). At most once per 10 minutes per invitation: 429 `resend_too_soon`. Only once Core holds organizations; before that, 409 `use_nexus_ui`. Audited as `invitation.sent` with `via: resend`.

Permission: `members.invite` (Owner, Admin).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The invitation's id, from `GET /v1/orgs/invitations`. |
| `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, object)
  - `email` (string, required)
  - `status` (string, required)
  - `invitationId` (string | null)
  - `message` (string | null)
- `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` `cutover_paused`: only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. (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 | `use_nexus_ui` | Only once Core holds organizations; before that, 409 `use_nexus_ui` |
| 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 | `resend_too_soon` | 429 `resend_too_soon` |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 503 |  | `cutover_paused`: only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/orgs/invitations/<id>/resend" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

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

## List my invitations

`GET /v1/orgs/invitations/mine`

Your own pending invitations, across organizations, oldest first: those sent to an email one of your sign-ins verified. An unverified email matches none. Expired invitations and organizations you are already in are left out. Accept one with `POST /v1/orgs/invitations/accept` and its `id`. Only once Core holds organizations (`NEXUS_ORG_OWNER=core`); before that, 409 `use_nexus_ui`. A person only (403 `person_required`).

Permission: `authenticated` (Every member, module keys).

### Responses

- `200` OK (application/json, object)
  - `invitations` (array of object, required)
    - `id` (string, required): Accept it with this id.
    - `email` (string, required): Your email it was sent to.
    - `orgName` (string, required)
    - `orgSlug` (string | null)
    - `role` ("member" | "admin", required)
    - `invitedBy` (string | null): The inviter's name, else their email; null when no person invited you or that person is gone.
    - `expiresAt` (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 |
| 403 | `person_required` | A person only (403 `person_required`) |
| 409 | `use_nexus_ui` | Only once Core holds organizations (`NEXUS_ORG_OWNER=core`); before that, 409 `use_nexus_ui` |
| 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/orgs/invitations/mine" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Accept invitation

`POST /v1/orgs/invitations/accept`

Accept an invitation: you join its organization with its role. Name the `token` in its link or the `id` from `GET /v1/orgs/invitations/mine`: exactly one. A body with neither or both is 400 `invalid_request`. For a token, Nexus UI's server must vouch that you verified the invited email (403 `email_mismatch`). For an id, one of your sign-ins must have verified the invited email; any other id is a 404. A used, revoked or replaced link is a 404; an expired invitation is 409 `invitation_expired`. Only once Core holds organizations; before that, 409 `use_nexus_ui`. Audited as `member.joined` with `via: invitation`.

Permission: `authenticated` (Every member, module keys).

### 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)

object | object: the provider's own request.

### Responses

- `200` OK (application/json, OrgSummary)
  - `id` (string, required)
  - `name` (string, required)
  - `slug` (string)
  - `clerkOrgId` (string): Its sign-in provider organization's id: Nexus UI's URL segment when it has no slug
  - `kind` ("company" | "personal", required): A company organization, or a person's own personal organization (one per person, one member)
  - `role` ("owner" | "admin" | "member")
  - `current` (boolean): The organization this request is in
  - `imageUrl` (string): Its logo, as the tenant's imageUrl (https://img.clerk.com/…); unset when it has none.
- `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` `cutover_paused`: only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. (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 | `invalid_request` | A body with neither or both is 400 `invalid_request` |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 403 | `email_mismatch` | For a token, Nexus UI's server must vouch that you verified the invited email (403 `email_mismatch`) |
| 409 | `invitation_expired` | A used, revoked or replaced link is a 404; an expired invitation is 409 `invitation_expired` |
| 409 | `use_nexus_ui` | Only once Core holds organizations; before that, 409 `use_nexus_ui` |
| 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 |  | `cutover_paused`: only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/orgs/invitations/accept" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "token": "<token>"
  }'
```

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

## List org domains

`GET /v1/orgs/domains`

The organization's verified email domains (owners and admins). While Clerk holds organizations (the default), they are Clerk's, from its Enhanced B2B add-on: people with a verified email on a domain join through Clerk as its `enrollmentMode` says; 409 `not_a_clerk_org` for an organization that does not sign in with Clerk; 503 `not_configured` without CLERK_SECRET_KEY on Gateway. Once Core holds organizations (NEXUS_ORG_OWNER=core), they are the domains a Nexus operator assigned: each one's `id` is the domain, its `enrollmentMode` is `automatic_suggestion`, and a person whose Google sign-in is on it sees the organization in listDomainSuggestions. 409 `personal_org` for a personal organization.

Permission: `members.invite` (Owner, Admin).

### Responses

- `200` OK (application/json, DomainList)
  - `domains` (array of OrgDomain, required)
    - `id` (string, required): The sign-in provider's domain id.
    - `domain` (string, required)
    - `enrollmentMode` ("automatic_invitation" | "automatic_suggestion" | "manual_invitation" | "enterprise_sso", required)
    - `verified` (boolean, required)
    - `pendingInvitations` (integer, required): Invitations the sign-in provider sent on this domain that nobody accepted yet.
- `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 | `not_a_clerk_org` | People with a verified email on a domain join through Clerk as its `enrollmentMode` says; 409 `not_a_clerk_org` for an organization that does not sign in with Clerk; 503 `not_configured` without CLERK_SECRET_KEY on Gateway |
| 409 | `personal_org` | 409 `personal_org` for a personal 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 | `not_configured` | People with a verified email on a domain join through Clerk as its `enrollmentMode` says; 409 `not_a_clerk_org` for an organization that does not sign in with Clerk; 503 `not_configured` without CLERK_SECRET_KEY on Gateway |

### Example

```sh
curl "$NEXUS_URL/v1/orgs/domains" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Add org domain

`POST /v1/orgs/domains`

Add a verified email domain (owners and admins). While Clerk holds organizations: you must have a verified email on it in Clerk (403 `domain_not_yours`), so an admin cannot add another company's domain and pull its people into their organization; a public mail provider such as gmail.com is refused (400 `public_mail_domain`), and so is a personal organization (409 `personal_org`). Clerk's refusal, such as a domain another organization has, is a 409 `clerk_refused` with Clerk's message. Audited as `domain.added`. Once Core holds organizations (NEXUS_ORG_OWNER=core), a Nexus operator assigns domains after a review, so this is 409 `operator_assigns_domains` (400 `public_mail_domain` for a public mail provider's).

Permission: `members.invite` (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)

- `domain` (string, required): A host name, as acme.com.
- `enrollmentMode` ("automatic_invitation" | "automatic_suggestion" | "manual_invitation"): Automatic_invitation: the sign-in provider invites everyone with a verified email on the domain. automatic_suggestion: the provider suggests the organization and an admin accepts each request. manual_invitation: nobody joins without an invitation. [default "automatic_invitation"]

### Responses

- `200` OK (application/json, OrgDomain)
  - `id` (string, required): The sign-in provider's domain id.
  - `domain` (string, required)
  - `enrollmentMode` ("automatic_invitation" | "automatic_suggestion" | "manual_invitation" | "enterprise_sso", required)
  - `verified` (boolean, required)
  - `pendingInvitations` (integer, required): Invitations the sign-in provider sent on this domain that nobody accepted yet.
- `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` `cutover_paused`: only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. (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 | `public_mail_domain` | You must have a verified email on it in Clerk (403 `domain_not_yours`), so an admin cannot add another company's domain and pull its people into their organization; a public mail provider such as gmail.com is refused (400 `public_mail_domain`), and so is a personal organization (409 `personal_org`) |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 403 | `domain_not_yours` | You must have a verified email on it in Clerk (403 `domain_not_yours`), so an admin cannot add another company's domain and pull its people into their organization; a public mail provider such as gmail.com is refused (400 `public_mail_domain`), and so is a personal organization (409 `personal_org`) |
| 409 | `personal_org` | You must have a verified email on it in Clerk (403 `domain_not_yours`), so an admin cannot add another company's domain and pull its people into their organization; a public mail provider such as gmail.com is refused (400 `public_mail_domain`), and so is a personal organization (409 `personal_org`) |
| 409 | `clerk_refused` | Clerk's refusal, such as a domain another organization has, is a 409 `clerk_refused` with Clerk's message |
| 409 | `operator_assigns_domains` | Once Core holds organizations (NEXUS_ORG_OWNER=core), a Nexus operator assigns domains after a review, so this is 409 `operator_assigns_domains` (400 `public_mail_domain` for a public mail provider's) |
| 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 |  | `cutover_paused`: only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/orgs/domains" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "domain": "<domain>"
  }'
```

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

## Remove org domain

`DELETE /v1/orgs/domains/{id}`

Remove a verified email domain by its id from listOrgDomains (owners and admins). New people stop joining by it; who already joined stays. Another organization's domain is a 404. Audited as `domain.removed`.

Permission: `members.invite` (Owner, Admin).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The domain's id, from listOrgDomains: the sign-in provider's id, or the domain itself once Core holds organizations. |
| `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, object)
  - `removed` (boolean, 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.
- `503` `cutover_paused`: only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. (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 |
| 503 |  | `cutover_paused`: only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. |

### Example

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

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

## List domain suggestions

`GET /v1/orgs/domain-suggestions`

The company organizations you may join by domain, with the domain of each. A suggestion needs your own Google sign-in: its `hd` is a domain a Nexus operator assigned to the organization, and Google verified your email on that domain. An email-code sign-in, an unverified email or the email on your account never counts. An organization you belong to, or were removed from, is left out. Only once Core holds organizations (NEXUS_ORG_OWNER=core); before that, 409 `use_nexus_ui`.

Permission: `authenticated` (Every member, module keys).

### Responses

- `200` OK (application/json, DomainSuggestionList)
  - `suggestions` (array of DomainSuggestion, required)
    - `domain` (string, required): The domain, lower-case.
    - `org` (OrgSummary, required): The organization; no `role` or `current`, since the person is not a member yet.
      - `id` (string, required)
      - `name` (string, required)
      - `slug` (string)
      - `clerkOrgId` (string): Its sign-in provider organization's id: Nexus UI's URL segment when it has no slug
      - `kind` ("company" | "personal", required): A company organization, or a person's own personal organization (one per person, one member)
      - `role` ("owner" | "admin" | "member")
      - `current` (boolean): The organization this request is in
      - `imageUrl` (string): Its logo, as the tenant's imageUrl (https://img.clerk.com/…); unset when it has none.
- `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 | `use_nexus_ui` | Only once Core holds organizations (NEXUS_ORG_OWNER=core); before that, 409 `use_nexus_ui` |
| 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/orgs/domain-suggestions" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Join by domain

`POST /v1/orgs/domain-suggestions/join`

Join an organization of listDomainSuggestions: you become a member, never an admin. 404 `no_domain_match` when none of your Google sign-ins is on a domain of that organization; the answer does not say whether it exists. 409 `member_removed` while an admin's removal of you can still be undone. A member already keeps their role. Only once Core holds organizations; before that, 409 `use_nexus_ui`. Audited as `member.joined` with `via: domain`.

Permission: `authenticated` (Every member, module keys).

### 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)

- `org` (string, required): The organization's id, from listDomainSuggestions.

### Responses

- `200` OK (application/json, OrgSummary)
  - `id` (string, required)
  - `name` (string, required)
  - `slug` (string)
  - `clerkOrgId` (string): Its sign-in provider organization's id: Nexus UI's URL segment when it has no slug
  - `kind` ("company" | "personal", required): A company organization, or a person's own personal organization (one per person, one member)
  - `role` ("owner" | "admin" | "member")
  - `current` (boolean): The organization this request is in
  - `imageUrl` (string): Its logo, as the tenant's imageUrl (https://img.clerk.com/…); unset when it has none.
- `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` `cutover_paused`: only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. (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 | `no_domain_match` | 404 `no_domain_match` when none of your Google sign-ins is on a domain of that organization; the answer does not say whether it exists |
| 409 | `member_removed` | 409 `member_removed` while an admin's removal of you can still be undone |
| 409 | `use_nexus_ui` | Only once Core holds organizations; before that, 409 `use_nexus_ui` |
| 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 |  | `cutover_paused`: only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/orgs/domain-suggestions/join" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "org": "<org>"
  }'
```

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

## Transfer ownership

`POST /v1/orgs/owner`

Transfer ownership to another member (the owner only); the previous owner becomes an admin.

Permission: `org.transfer` (Owner).

### 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)

- `userId` (string, required)

### Responses

- `200` OK (application/json, object)
- `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` `cutover_paused`: only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. (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 |
| 503 |  | `cutover_paused`: only while the operator pauses sign-in for the auth cutover; nothing changed. Retry after `Retry-After` seconds. |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/orgs/owner" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "userId": "user_123"
  }'
```

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

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.transferOwnership("<user id>");
```

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

## Set budget

`POST /v1/orgs/budget`

Set the organization's budget in USD, a cap per UTC day, ISO week or calendar month (owners and admins); never below what the period spent and what is reserved.

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

- `budgetUsd` (number | string): The organization's budget per period in US dollars: a JSON number (deprecated) or a decimal string with at most 6 decimals (`"12.245"`), read exactly. Send `budgetUsdDecimal` instead to send only a string.
- `budgetUsdDecimal` (string): The organization's budget per period as a decimal string in US dollars, at most 6 decimals, never below 0; read exactly into micro-dollars, never through a float. With `budgetUsd` too, both must name the same amount (400 `amount_mismatch`). [pattern ^[0-9]+(\.[0-9]{1,6})?$]
- `period` ("day" | "week" | "month"): The cap's period. Absent keeps the current one, a month unless set
- `dryRun` (boolean): Make the same checks and write nothing; the answer is { dryRun, before, after }, each { budgetUsd, budgetUsdDecimal, period }

### Responses

- `200` OK (application/json, object | object)
- `400` `budgetUsd` and `budgetUsdDecimal` both missing, `dryRun` not true or false (`invalid_request`), a decimal string with more than 6 decimals (`too_many_decimals`), an amount that is not one or is below 0 (`invalid_amount`), or a number and its `Decimal` twin that name different amounts (`amount_mismatch`), or a period other than day, week or month (`invalid_period`) (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` Only owners and admins set the organization's budget (`role_required`): a member without `budgets.manage` (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 new budget is below what the period has already spent and reserved (`conflict`) (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 |  | `budgetUsd` and `budgetUsdDecimal` both missing, `dryRun` not true or false (`invalid_request`), a decimal string with more than 6 decimals (`too_many_decimals`), an amount that is not one or is below 0 (`invalid_amount`), or a number and its `Decimal` twin that name different amounts (`amount_mismatch`), or a period other than day, week or month (`invalid_period`) |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 409 |  | The new budget is below what the period has already spent and reserved (`conflict`) |
| 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/orgs/budget" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

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

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

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

## Export directory CSV

`GET /v1/orgs/directory/export.csv`

Every person and team of the organization with its name: the one file that maps ids to names, as CSV (owners and admins). The people are its members and the people its calls and kept agent sessions name (former members too), then its teams and the teams those name, each by id. Names are read when the file is asked for. An erased person reads `erased: true` with no name; a person with no record reads with no name, and a deleted team with its id alone. It takes no parameter and has no row limit, range or cursor. The data files name people and teams by id only. Each request is an audit event (`observability.directory_exported`) with the file's manifest, never its rows, and counts toward the 60 exports an hour.

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

### Responses

- `200` CSV with a header row: one column per field of `DirectoryEntry`, 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 |
| --- | --- | --- |
| 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/orgs/directory/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.directoryExport("csv");
```

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

## Export directory JSON Lines

`GET /v1/orgs/directory/export.jsonl`

Every person and team of the organization with its name: the one file that maps ids to names, as JSON Lines (owners and admins). The people are its members and the people its calls and kept agent sessions name (former members too), then its teams and the teams those name, each by id. Names are read when the file is asked for. An erased person reads `erased: true` with no name; a person with no record reads with no name, and a deleted team with its id alone. It takes no parameter and has no row limit, range or cursor. The data files name people and teams by id only. Each request is an audit event (`observability.directory_exported`) with the file's manifest, never its rows, and counts toward the 60 exports an hour.

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

### Responses

- `200` JSON Lines: one `DirectoryEntry` 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 |
| --- | --- | --- |
| 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/orgs/directory/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.directoryExport("jsonl");
```

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

## Clerk webhook

`POST /v1/clerk/webhook`

Clerk's webhook, signed by Svix with CLERK_WEBHOOK_SECRET (svix-id, svix-timestamp and svix-signature; refused more than five minutes from now). For organizationMembership.created, .updated and .deleted, and user.deleted, Gateway reads the membership or the person from Clerk again and makes its copy match: a member Clerk no longer has loses their membership, teams and tokens (member.removed, via: clerk; the owner loses only the tokens), and a role Clerk changed is mirrored. For organization.updated, Gateway reads the organization from Clerk again and mirrors its name, slug and logo as a sign-in does (org.settings_changed, actor clerk; a logo not on img.clerk.com is dropped); an organization Gateway does not have is ignored. A repeated or late event changes nothing. 401 for a bad signature; 503 `not_configured` without CLERK_WEBHOOK_SECRET or CLERK_SECRET_KEY; 502 when Clerk does not answer, so Svix retries.

Permission: `public` (Anyone, signed in or not).

### Responses

- `200` OK (application/json, object)
  - `ok` (boolean, required)
  - `event` (string, required)
  - `changed` (integer, required): How many memberships changed.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 503 | `not_configured` | 401 for a bad signature; 503 `not_configured` without CLERK_WEBHOOK_SECRET or CLERK_SECRET_KEY; 502 when Clerk does not answer, so Svix retries |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/clerk/webhook"
```

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

## Get billing

`GET /v1/billing`

The organization's billing (owner only): the Stripe mode of this Gateway, whether the organization has a Stripe customer yet, its payment method on file (`defaultPaymentMethod`, of any type; `paymentMethod` only when it is a card), how it pays for what Nexus runs (pricing v2.0: `freeStart`, `credits` and `autoTopup`, `afterTheFact`; `plan` where this Gateway sells plans), the numbers a page shows (`pricing`), and `pastDue`. `pastDue` is null, or names the oldest month Stripe could not collect: when it first failed (`since`), its period, and when model calls stop (`blockedFrom`, `since` plus NEXUS_BILLING_GRACE_DAYS, 7 days by default). From `blockedFrom` until an owner pays, every model call is refused with 402 `payment_past_due`. Never Stripe's customer id or the card number. A customer made in the other mode (test or live) is not shown. 503 `not_configured` until STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET are both set and well formed (the message says which is wrong).

Permission: `org.billing` (Owner).

### Responses

- `200` OK (application/json, Billing)
  - `sharedPaymentTokens` (boolean): True when this Gateway supports delegated Stripe shared payment tokens on credit purchases. Currently enabled only in Stripe test mode; live mode returns false. Check before submitting a token.
  - `mode` ("test" | "live", required): The mode of Gateway's Stripe key.
  - `customer` (object | null, required): Null until the first card setup starts.
    - `state` ("creating" | "ready", required): `creating`: Gateway started the Stripe customer and the first setup has not finished. `ready`: the customer exists.
  - `paymentMethod` (CardSummary | null, required): The payment method on file when it is a card. Null when there is none, or when it is not a card: read `defaultPaymentMethod` for any type.
  - `defaultPaymentMethod` (PaymentMethodSummary | null, required): The payment method on file, of any type: the one credits, auto top-ups and charges for usage after the fact are charged to. Null until one is saved.
  - `credits` (NexusCredits | null): The organization's prepaid Nexus credits; null before it buys any.
  - `autoTopup` (AutoTopup | null): The organization's auto top-up of Nexus credits; null before an owner sets it.
  - `planAllowance` (object): The current plan's monthly allowances. Absent when no allowance is available.
    - `resetAt` (string (date-time), required): Start of the next usage month in UTC.
    - `ai` (object | null, required): AI allowance in decimal USD, counting settled usage. Null until the allowance is granted.
      - `includedUsd` (string, required)
      - `usedUsd` (string, required)
      - `leftUsd` (string, required)
    - `cloud` (object | null, required): Cloud allowance in default-size hours. Null when plan cloud metering is unavailable.
      - `includedHours` (number, required)
      - `usedHours` (number, required)
      - `leftHours` (number, required)
  - `pastDue` (object | null, required): Null while no month of this mode is unpaid after Stripe tried to collect it. Otherwise the oldest such month.
    - `since` (string (date-time), required): When the month first failed.
    - `period` (string, required): The unpaid month, YYYY-MM. [pattern ^[0-9]{4}-(0[1-9]|1[0-2])$]
    - `blockedFrom` (string (date-time) | null, required): `since` plus the grace (NEXUS_BILLING_GRACE_DAYS). From then on model calls are refused with 402 `payment_past_due`. Null when this Gateway has no gate, so nothing is refused.
    - `invoiceUrl` (string (uri) | null, required): Stripe's page that pays the unpaid month (its hosted invoice). Null when Stripe gave none.
  - `pricingChange` (object | null): A change to Nexus pricing and the Customer Terms (NEXUS_PRICING_CHANGE), until 30 days past the day it takes effect. Each organization created before that day is told once by `billing.pricing_change`. Null, or absent from an older Gateway, when there is none.
    - `effectiveOn` (string (date), required): The day the change takes effect, at 00:00 UTC: YYYY-MM-DD.
  - `plan` (BillingPlan | null): The organization's plan; null on the Free plan
  - `freeStart` (object | null): The organization's free start (pricing v2.0): what Nexus gave it once, and what is left. Null when it got none.
    - `grantedUsd` (string, required): What Nexus gave, a decimal dollar string.
    - `remainingUsd` (string, required): What is left, never below zero.
    - `expiresAt` (string (date-time) | null): When the free start expires, or expired: 30 days after its grant. Null when the organization's subsidy holds no free start.
    - `expiredUsd` (string | null): What was left of the free start when it expired, a decimal dollar string. Null before it expires.
  - `afterTheFact` (AfterTheFact | null): How the organization pays after the fact (pricing v2.0); null before an owner turns it on.
  - `pricing` (object, required): The numbers a billing page shows, so no client writes a price of its own. Decimal dollar strings.
    - `markupBps` (integer, required): Nexus's rate on AI it runs past the free start and a plan's allowance, in basis points: 500 is provider price + 5%. App hosting and cloud machines have their own prices.
    - `minPurchaseUsd` (string, required): The least one credit purchase buys.
    - `thresholdUsd` (string, required): Paying after the fact, the card is charged each time the unpaid usage reaches this.
    - `defaultLimitUsd` (string, required): The monthly usage limit a new after-the-fact setting starts at.
    - `maxLimitUsd` (string, required): The most a usage limit may be now for this organization: $100 in its first week, then $100,000. A higher `limitUsd` answers 400 `invalid_amount`.
    - `freeStartMaxOutputUsd` (string): The free start pays only for a model whose cheapest host charges at most this per million output tokens.
    - `minFinalChargeUsd` (string): Minimum final charge when pay after the fact turns off.
  - `promotionalCreditUsd` (string): Available referral and promotional credit, excluding the welcome free start.
- `403` Not the owner (`permission_error`) (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` Stripe is not configured (`not_configured`): the message says which variable is wrong (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 |
| 402 | `payment_past_due` | From `blockedFrom` until an owner pays, every model call is refused with 402 `payment_past_due` |
| 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 |
| 503 |  | Stripe is not configured (`not_configured`): the message says which variable is wrong |
| 503 | `not_configured` | 503 `not_configured` until STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET are both set and well formed (the message says which is wrong) |

### Example

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

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

## Get billing statement

`GET /v1/billing/statement`

The organization's bill for one UTC month (owner only). A month the close stored answers from the stored row, as it closed, and `invoice` shows its Stripe invoice. Any other month is priced now, from the ledger and the prices Gateway has: NEXUS_PRICE_GATEWAY_CALL_MICROS and NEXUS_PRICE_GATEWAY_COST_BPS. Both are 0 until a price is set, so the total reads 0. It counts the calls on the organization's own provider keys. Refused calls and calls a Nexus subsidy paid are left out. Money is a decimal string. The bill is the total in whole cents, rounded down, as a string. `carriedInUsd` is the rest of the newest stored month before this one. `carriedOutUsd` is the part below one cent, and it carries into the next month. A month under 50 cents is not invoiced: all of its total carries. `providerCostUsd` is what the providers charged. They bill it, not Nexus. The stored months are the ones of Gateway's Stripe key mode. Without Stripe nothing is stored, so every month is priced now. The route reads no Stripe, so it answers with Stripe off. 400 for a period that is not YYYY-MM or has not started.

Permission: `org.billing` (Owner).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `period` | query | string | no | YYYY-MM from 1970-01 to 9998-12, a UTC month that has started; default the current month |

### Responses

- `200` OK (application/json, BillingStatement)
  - `period` (string, required): The month, as YYYY-MM. [pattern ^[0-9]{4}-(0[1-9]|1[0-2])$]
  - `lines` (array of BillingStatementLine, required): Every charge. Both lines are always there, with amount 0 until a price is set.
    - `code` ("gateway.calls" | "gateway.provider_cost" | "gateway.nexus_usage", required): `gateway.calls`: the calls on the organization's own keys. `gateway.provider_cost`: Nexus's fee on what the providers charged for them. `gateway.nexus_usage`: a contract's calls on Nexus-supplied keys, at provider price plus Nexus's rate; only on a month that has some.
    - `unit` ("call" | "usd", required)
    - `quantity` (string, required): Unit `call`: a whole number of calls. Unit `usd`: a decimal dollar amount.
    - `rateUsd` (string): Unit `call` only: the price of one call. [pattern ^[0-9]+\.[0-9]{6}$]
    - `rateBps` (integer): Unit `usd` only: basis points of `quantity` (100 is 1%). [min 0; max 10000]
    - `amountUsd` (string, required): `quantity` times the rate, rounded down to a micro-dollar. [pattern ^[0-9]+\.[0-9]{6}$]
  - `providerCostUsd` (string, required): What the providers charged for the calls on the organization's own keys. The providers bill it, not Nexus. [pattern ^[0-9]+\.[0-9]{6}$]
  - `carriedInUsd` (string, required): The rest of the month before: the part of its total that no invoice took. [pattern ^[0-9]+\.[0-9]{6}$]
  - `totalUsd` (string, required): The lines and `carriedInUsd` added. [pattern ^[0-9]+\.[0-9]{6}$]
  - `amountCents` (string, required): What to charge: `totalUsd` in whole cents, rounded down. A whole number as a string. A month under 50 cents is not invoiced. [pattern ^[0-9]+$]
  - `carriedOutUsd` (string, required): What moves to the next month: the part of `totalUsd` below one cent. A month under 50 cents is not invoiced, so all of its total moves. [pattern ^[0-9]+\.[0-9]{6}$]
  - `invoice` (BillingInvoice | null, required): The Stripe invoice of a stored month. Null for a month that is priced now, and for a stored month under 50 cents, which is not invoiced.
- `400` Not a month as YYYY-MM, or a month that has not started (`invalid_request_error`) (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` Not the owner (`permission_error`) (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 |  | Not a month as YYYY-MM, or a month that has not started (`invalid_request_error`) |
| 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/billing/statement" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## List billing statements

`GET /v1/billing/statements`

The months the close stored for the organization (owner only), in the mode of Gateway's Stripe key, newest first, at most 24. Each month shows its total, its whole cents, its state and its Stripe invoice page. A `closed` month is under 50 cents: nothing was invoiced and its total carries into the next month. Money is a decimal string. The route reads no Stripe. 503 `not_configured` until STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET are both set and well formed (the message says which is wrong).

Permission: `org.billing` (Owner).

### Responses

- `200` OK (application/json, BillingStatementList)
  - `statements` (array of BillingStatementSummary, required): The stored months, newest first, at most 24.
    - `period` (string, required): The month, as YYYY-MM. [pattern ^[0-9]{4}-(0[1-9]|1[0-2])$]
    - `totalUsd` (string, required): The lines and the rest carried in, added. [pattern ^[0-9]+\.[0-9]{6}$]
    - `amountCents` (string, required): What the statement priced: `totalUsd` in whole cents, rounded down. A whole number as a string. A `closed` month invoices none of it. [pattern ^[0-9]+$]
    - `state` ("closed" | "invoicing" | "invoiced" | "paid" | "failed" | "void" | "uncollectible", required): `closed`: under 50 cents, so nothing was invoiced and the total carries into the next month. The other states are the ones of the invoice.
    - `hostedInvoiceUrl` (string | null, required): Stripe's page for the invoice. Null for a `closed` month, and until Stripe has finalized the invoice.
- `403` Not the owner (`permission_error`) (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` Stripe is not configured (`not_configured`): the message says which variable is wrong (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 |
| 503 |  | Stripe is not configured (`not_configured`): the message says which variable is wrong |
| 503 | `not_configured` | 503 `not_configured` until STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET are both set and well formed (the message says which is wrong) |

### Example

```sh
curl "$NEXUS_URL/v1/billing/statements" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Start payment method setup

`POST /v1/billing/payment-method`

Start saving a card for the organization (owner only): a link to a card page hosted by Stripe Checkout. Open `url` in a browser before `expiresAt`. Stripe sends the person back to the organization's billing page in Nexus UI (`<NEXUS_UI_URL>/<org>/billing?checkout=done` or `=cancelled`). Gateway makes the organization's Stripe customer on the first call and reuses it after; each call makes a new link. Takes no body, or `{"embedded": true}`: the same card setup as a form Nexus UI shows inside its billing page. With `STRIPE_PUBLISHABLE_KEY` on Gateway, that answer is `EmbeddedCardSetup` (Stripe.js's `clientSecret` and the `publishableKey`, no `url`), and Stripe sends the page to `?checkout=done` once the card is saved; without it, the hosted link as without the body. 400 when `embedded` is not a boolean. Audited as `billing.customer_created` when the customer is made, and as `billing.customer_deleted` when Stripe no longer has it; neither event names Stripe's customer id. 502 `stripe_error` when Stripe refuses or does not answer (the message names Stripe's type and code). 503 `not_configured` until Stripe is set up, or without NEXUS_UI_URL on Gateway; 503 `billing_setup_in_progress` while a first call for the organization is still running (try again in a moment).

Permission: `org.billing` (Owner).

### 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)

- `embedded` (boolean): Ask for the card form inside Nexus UI's billing page instead of Stripe's own page. Gateway answers the hosted link when it has no publishable key.

### Responses

- `200` OK (application/json, PaymentMethodSetup | EmbeddedCardSetup)
- `400` `embedded` is not a boolean (`invalid_request`) (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` Not the owner (`permission_error`) (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.
- `502` Stripe refused the call or did not answer (`stripe_error`) (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` Stripe is not configured, NEXUS_UI_URL is not set (`not_configured`), or a first call for this organization is still running (`billing_setup_in_progress`) (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 |  | `embedded` is not a boolean (`invalid_request`) |
| 400 | `embedded` | 400 when `embedded` is not a boolean |
| 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 |
| 502 |  | Stripe refused the call or did not answer (`stripe_error`) |
| 502 | `stripe_error` | 502 `stripe_error` when Stripe refuses or does not answer (the message names Stripe's type and code) |
| 503 |  | Stripe is not configured, NEXUS_UI_URL is not set (`not_configured`), or a first call for this organization is still running (`billing_setup_in_progress`) |
| 503 | `not_configured` | 503 `not_configured` until Stripe is set up, or without NEXUS_UI_URL on Gateway; 503 `billing_setup_in_progress` while a first call for the organization is still running (try again in a moment) |
| 503 | `billing_setup_in_progress` | 503 `not_configured` until Stripe is set up, or without NEXUS_UI_URL on Gateway; 503 `billing_setup_in_progress` while a first call for the organization is still running (try again in a moment) |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/billing/payment-method" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "embedded": false
  }'
```

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

## Confirm payment

`POST /v1/billing/confirm-payment`

Confirm a payment the bank wants the cardholder to confirm (3-D Secure), owner only. Off session, Stripe refuses such a charge with `authentication_required` and keeps its PaymentIntent; this confirms that same usage charge after the fact again on session; one the bank's page never finished is cancelled at Stripe an hour later. An auto top-up that turned off for the bank's check is fixed by saving the card again (startPaymentMethodSetup). `status` `redirect`: open `url`, the bank's page, which sends the person back to the organization's billing page in Nexus UI (`<NEXUS_UI_URL>/<org>/billing?confirmed=1`). `succeeded` or `processing`: Stripe took it, or a bank debit is on its way. Stripe's notice records the payment as for any charge; nothing is charged twice. Takes no body. 409 `nothing_to_confirm` when no charge waits for the bank's check (save the card again with startPaymentMethodSetup), `charge_running` while a usage charge is being taken. 402 when the card is declined on session.

Permission: `org.billing` (Owner).

### 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, PaymentConfirmation)
  - `status` ("redirect" | "succeeded" | "processing", required): `redirect`: open `url`. `succeeded`: Stripe took the payment. `processing`: a bank debit is on its way.
  - `url` (string (uri) | null, required): The bank's page while it waits for the cardholder; null otherwise
- `402` The card was declined on session (`stripe_error`) (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` Not the owner (`permission_error`) (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` No charge waits for the bank's check (`nothing_to_confirm`), or a usage charge is being taken now (`charge_running`) (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.
- `502` Stripe refused the call or did not answer (`stripe_error`) (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` Stripe is not configured, or NEXUS_UI_URL is not set (`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 |
| --- | --- | --- |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 402 | `budget_exceeded` | The card was declined on session (`stripe_error`) |
| 403 | `role_required` | Your role does not have this permission |
| 409 |  | No charge waits for the bank's check (`nothing_to_confirm`), or a usage charge is being taken now (`charge_running`) |
| 409 | `nothing_to_confirm` | 409 `nothing_to_confirm` when no charge waits for the bank's check (save the card again with startPaymentMethodSetup), `charge_running` while a usage charge is being taken |
| 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 |
| 502 |  | Stripe refused the call or did not answer (`stripe_error`) |
| 503 |  | Stripe is not configured, or NEXUS_UI_URL is not set (`not_configured`) |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/billing/confirm-payment" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

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

## Start billing portal

`POST /v1/billing/portal`

Open the organization's Stripe customer portal (owner only): a link to a page hosted by Stripe where the owner manages payment methods, sees and pays invoices, sets tax ids and cancels at period end. Plans and seats change through Gateway, not the portal. Open `url` in a browser at once: Stripe's link expires within minutes. Stripe sends the person back to the organization's billing page in Nexus UI (`<NEXUS_UI_URL>/<org>/billing`). Gateway makes the organization's Stripe customer on the first call and reuses it after; each call makes a new link. Takes no body. The Stripe account needs a default portal configuration. 502 `stripe_error` when Stripe refuses or does not answer (the message names Stripe's type and code). 503 `not_configured` until Stripe is set up, or without NEXUS_UI_URL on Gateway; 503 `billing_setup_in_progress` while a first call for the organization is still running (try again in a moment).

Permission: `org.billing` (Owner).

### 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, BillingPortal)
  - `url` (string, required): Stripe's customer portal for the organization. Open it at once: it expires within minutes.
- `403` Not the owner (`permission_error`) (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.
- `502` Stripe refused the call or did not answer (`stripe_error`) (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` Stripe is not configured, NEXUS_UI_URL is not set (`not_configured`), or a first call for this organization is still running (`billing_setup_in_progress`) (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 |
| 502 |  | Stripe refused the call or did not answer (`stripe_error`) |
| 502 | `stripe_error` | 502 `stripe_error` when Stripe refuses or does not answer (the message names Stripe's type and code) |
| 503 |  | Stripe is not configured, NEXUS_UI_URL is not set (`not_configured`), or a first call for this organization is still running (`billing_setup_in_progress`) |
| 503 | `not_configured` | 503 `not_configured` until Stripe is set up, or without NEXUS_UI_URL on Gateway; 503 `billing_setup_in_progress` while a first call for the organization is still running (try again in a moment) |
| 503 | `billing_setup_in_progress` | 503 `not_configured` until Stripe is set up, or without NEXUS_UI_URL on Gateway; 503 `billing_setup_in_progress` while a first call for the organization is still running (try again in a moment) |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/billing/portal" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

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

## Buy credits

`POST /v1/billing/credits`

Buy Nexus credits (owner only): the organization's own money, prepaid at face value and never expiring, spent by Nexus features after the free start and a plan's included usage at provider price plus Nexus's rate. Body: `amountUsd`, a decimal string in whole cents, from "10.00" to "10000.00"; a new organization buys at most $100 in its first 7 days, counting the purchases still being paid, such as an open Checkout page until it expires (400 `purchase_limit`). With a payment method on file, Gateway charges it off session: `status: credited` with the credits after, or `processing` for a bank debit still on its way (Stripe's notice credits it). Without one, or when the bank wants the person (3-D Secure) or the card declines, `status: checkout` with a Stripe Checkout `url` to open before `expiresAt`; Stripe sends the person back to `<NEXUS_UI_URL>/<org>/billing?checkout=credits`. A payment credits once, from Stripe's `payment_intent.succeeded`, and only to the organization whose Stripe customer paid. The Idempotency-Key header keys the Stripe call, so a retry never charges twice. Audited as `credit.purchased`. 400 `invalid_amount`; 502 `stripe_error`; 503 `not_configured` until Stripe is set up, or without NEXUS_UI_URL for a hosted purchase. With paymentToken, charge the agent wallet shared payment token directly in Stripe test mode. Live mode returns 503 payment_tokens_not_supported before contacting Stripe. There is no hosted fallback. 400 invalid_payment_token rejects a malformed credential, or one Stripe has deactivated (used, revoked or expired); 402 payment_authentication_required requires the cardholder. The same Idempotency-Key and body replay the first result.

Permission: `org.billing` (Owner).

### 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)

- `paymentToken` (string): Optional Stripe shared payment token from an agent wallet, scoped to Nexus, USD, the purchase amount and an expiry. Currently accepted only in Stripe test mode. Confirms without a saved card, NEXUS_UI_URL or Checkout. Never accepts card details or merchant API keys. Does not save a card or enable recurring charges. [max length 255; pattern ^spt_[A-Za-z0-9_]+$]
- `amountUsd` (string, required): Dollars in whole cents, such as "50.00": from 10.00 to 10000.00.

### Responses

- `200` OK (application/json, BuyCredits)
  - `status` ("credited" | "processing" | "checkout", required): `credited`: charged and credited now; `processing`: Stripe is still taking a bank debit, and its notice credits it; `checkout`: open `url` to pay.
  - `amountUsd` (string, required): What the purchase buys, in decimal dollars.
  - `credits` (NexusCredits): The organization's prepaid Nexus credits, its own money, never expiring. A Nexus feature's call spends them after the free start, at its provider cost plus `markupBps`. Decimal dollar strings.
    - `purchasedUsd` (string, required): Bought, over all time.
    - `spentUsd` (string, required): What settled calls cost the credits: each call's provider cost plus `markupBps`.
    - `reservedUsd` (string, required): Held by calls in progress.
    - `remainingUsd` (string, required): Bought, less spent, held and reversed. Below zero after a refund or a lost dispute took back credit that was already spent: then Nexus pays for no call (the free start, credits or the card after the fact) until a purchase pays it back.
    - `reversedUsd` (string): What refunds, lost disputes and operators took back, and what an open dispute holds of its purchase until it closes. A refund that fails gives its credit back. Only while something is taken back.
    - `markupBps` (integer, required): Nexus's rate on AI in basis points (500 is 5%).
  - `paymentId` (string): Stripe's PaymentIntent, while `processing`.
  - `url` (string): Stripe Checkout's page, for `checkout`.
  - `expiresAt` (string (date-time)): When Stripe stops accepting `url`.
  - `checkoutSessionId` (string): Exact Checkout session to confirm; returned by current Gateways.
- `400` An amount outside $25 to $10,000 or not in whole cents (`invalid_amount`), or past a new organization's limit (`purchase_limit`) (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `402` The delegated payment requires cardholder authentication or was not completed (payment_authentication_required, payment_declined, payment_failed). (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` Only the owner buys credits (`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.
- `502` Stripe refused the call or did not answer (`stripe_error`) (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` Delegated payment tokens are disabled in live mode (`payment_tokens_not_supported`), Stripe is not configured, NEXUS_UI_URL is not set for a hosted purchase (`not_configured`), or a first call for this organization is still running (`billing_setup_in_progress`) (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 |  | An amount outside $25 to $10,000 or not in whole cents (`invalid_amount`), or past a new organization's limit (`purchase_limit`) |
| 400 | `purchase_limit` | `amountUsd`, a decimal string in whole cents, from "10.00" to "10000.00"; a new organization buys at most $100 in its first 7 days, counting the purchases still being paid, such as an open Checkout page until it expires (400 `purchase_limit`) |
| 400 | `invalid_amount` | 400 `invalid_amount`; 502 `stripe_error`; 503 `not_configured` until Stripe is set up, or without NEXUS_UI_URL for a hosted purchase |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 402 | `budget_exceeded` | The delegated payment requires cardholder authentication or was not completed (payment_authentication_required, payment_declined, payment_failed). |
| 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 |
| 502 |  | Stripe refused the call or did not answer (`stripe_error`) |
| 502 | `stripe_error` | 400 `invalid_amount`; 502 `stripe_error`; 503 `not_configured` until Stripe is set up, or without NEXUS_UI_URL for a hosted purchase |
| 503 |  | Delegated payment tokens are disabled in live mode (`payment_tokens_not_supported`), Stripe is not configured, NEXUS_UI_URL is not set for a hosted purchase (`not_configured`), or a first call for this organization is still running (`billing_setup_in_progress`) |
| 503 | `not_configured` | 400 `invalid_amount`; 502 `stripe_error`; 503 `not_configured` until Stripe is set up, or without NEXUS_UI_URL for a hosted purchase |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/billing/credits" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "amountUsd": "<amountUsd>"
  }'
```

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

## Set auto topup

`PUT /v1/billing/auto-topup`

Turn the organization's auto top-up of Nexus credits on or off (owner only). Body: `enabled`, and `belowUsd` and `addUsd` as decimal strings in whole cents (or the ones set before). On needs the payment method on file (409 `no_payment_method`), and not a card whose payment was disputed (409 `card_disputed`). A closed organization cannot turn it on (409 `organization_closed`). When the credits left fall below `belowUsd`, Gateway's Stripe sweep (`NEXUS_STRIPE_SWEEP_MS`) charges that payment method `addUsd` off session and credits it, one top-up at a time, at most 3 top-ups or $500 a UTC day. A decline, a bank that wants the person, no payment method, a bank debit that fails later (`payment_intent.payment_failed`), a dispute, or a refund that takes the credits below zero turns it off, and `offReason` says why. Off keeps the amounts; turning off what was never set answers `autoTopup: null`. Audited as `credit.auto_topup_changed`. 400 `invalid_amount`; 503 `not_configured` until Stripe is set up.

Permission: `org.billing` (Owner).

### 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)

- `enabled` (boolean, required)
- `belowUsd` (string): Dollars in whole cents, above 0.00 and at most 10000.00. Needed to turn on the first time.
- `addUsd` (string): Dollars in whole cents, from 10.00 to 500.00. Needed to turn on the first time.

### Responses

- `200` OK (application/json, SetAutoTopup)
  - `autoTopup` (AutoTopup | null, required): The setting after; null after turning off what was never set.
- `400` `belowUsd` not above $0 or above $10,000, or `addUsd` outside $25 to $500 or not in whole cents (`invalid_amount`); `enabled` missing; or turning on without both amounts (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` Not the owner (`permission_error`) (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` Turning on with no payment method on file (`no_payment_method`) (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` Stripe is not configured (`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 |  | `belowUsd` not above $0 or above $10,000, or `addUsd` outside $25 to $500 or not in whole cents (`invalid_amount`); `enabled` missing; or turning on without both amounts |
| 400 | `invalid_amount` | 400 `invalid_amount`; 503 `not_configured` until Stripe is set up |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 409 |  | Turning on with no payment method on file (`no_payment_method`) |
| 409 | `no_payment_method` | On needs the payment method on file (409 `no_payment_method`), and not a card whose payment was disputed (409 `card_disputed`) |
| 409 | `card_disputed` | On needs the payment method on file (409 `no_payment_method`), and not a card whose payment was disputed (409 `card_disputed`) |
| 409 | `organization_closed` | A closed organization cannot turn it on (409 `organization_closed`) |
| 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 |  | Stripe is not configured (`not_configured`) |
| 503 | `not_configured` | 400 `invalid_amount`; 503 `not_configured` until Stripe is set up |

### Example

```sh
curl -X PUT "$NEXUS_URL/v1/billing/auto-topup" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "enabled": false
  }'
```

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

## Get org settings

`GET /v1/orgs/settings`

The organization's settings: how many days chat messages are kept (90 by default).

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

### Responses

- `200` OK (application/json, OrgSettings)
  - `hiddenMobilePlaces` (array of "assistant" | "artifacts" | "customize"): Places hidden from members in the mobile drawer. The owner still sees them.
  - `chatRetentionDays` (integer, required): Days chat messages are kept (90 by default) [min 1; max 3650]
  - `agentSubscriptions` (boolean): Whether `nexus claude --subscription` may run (true by default)
  - `growthEvents` (boolean): Whether the Gateway records the organization's growth events in its own store (true by default)
  - `chatSuggestions` (boolean): Whether chat sessions suggest the person's next message after an answer, a call the organization pays for (true by default)
  - `defaults` (object, required)
    - `hiddenMobilePlaces` (array of "assistant" | "artifacts" | "customize") [default []]
    - `chatRetentionDays` (integer)
    - `growthEvents` (boolean)
    - `chatSuggestions` (boolean)
    - `artifacts.external` ("off" | "named" | "public")
    - `artifacts.external.code` (boolean)
    - `artifacts.external.domains` (object)
      - `allow` (array of string, required)
      - `deny` (array of string, required)
    - `artifacts.external.expiry` (object)
      - `maxDays` (integer | null, required) [min 1; max 3650]
      - `required` (boolean, required)
    - `artifacts.external.continue` (boolean)
    - `artifacts.external.who` ("everyone" | "admins")
    - `agentSubscriptions` (boolean)
    - `artifacts.pages` (boolean)
    - `artifacts.pages.public` (boolean)
    - `artifacts.pages.queries` (boolean)
    - `webSearch.engine` ("off" | "borrowed")
    - `webSearch.model` (string | null)
    - `webSearch.domains` (object)
      - `allow` (array of string, required)
      - `deny` (array of string, required)
    - `webSearch.maxPerTurn` (integer)
    - `webSearch.requireZdr` (boolean)
    - `sessionContent` ("never" | "user" | "user_and_org")
    - `multiplayerSessions` (boolean)
    - `cloudHistory` (boolean)
    - `webSessionViewer` (boolean)
  - `updatedAt` (string (date-time))
  - `artifacts.external` ("off" | "named" | "public"): Sharing artifacts outside the organization: off, named people only, or also public links (default public)
  - `artifacts.external.code` (boolean): May external snapshots include Ask your code's sources (default false)
  - `artifacts.external.domains` (object): Email domains named outsiders may (allow, when set) or may not (deny) have; a domain matches itself and its subdomains (default both empty)
    - `allow` (array of string, required)
    - `deny` (array of string, required)
  - `artifacts.external.expiry` (object): The longest a public link may stay open, and whether every public link must expire (default none and false)
    - `maxDays` (integer | null, required) [min 1; max 3650]
    - `required` (boolean, required)
  - `artifacts.external.continue` (boolean): May people outside continue the chat in an organization of their own, at its expense (default true)
  - `artifacts.external.who` ("everyone" | "admins"): Who may share outside: everyone, or owners and admins (default everyone)
  - `artifacts.pages` (boolean): Pages: off refuses new pages, versions, shares and every page frame (default true)
  - `artifacts.pages.public` (boolean): Public links to pages: off refuses new ones and stops existing ones from opening (default false in a company organization, true in a personal one)
  - `artifacts.pages.queries` (boolean): Page queries (Nexus Data): on lets a page's owner approve read-only queries on a connection, whose results the page's readers see; off refuses saving and running them (default false)
  - `webSearch.engine` ("off" | "borrowed"): Gates hosted web search in chat and in Code (`nexus claude --api`, `nexus codex --api`): off or borrowed (default borrowed; off means no web search runs)
  - `webSearch.model` (string | null): The model that runs a chat's search: null for the default (the chat's own model, the cheapest on nexus/auto), cheapest, or a model's catalog id. A pinned model the person may not use, or nobody pays for, gives that person no search, and so does an id this Gateway cannot call, which is shown as stored. Chat only
  - `webSearch.domains` (object): Domains a search result may (allow, when set) or may not (deny) come from (default both empty). While any is set, no web search runs, in chat or in Code, until the engine applies them
    - `allow` (array of string, required)
    - `deny` (array of string, required)
  - `webSearch.maxPerTurn` (integer): Most searches in one chat turn (default 3). Applies to Gateway-run engines (chat) only [min 1; max 10]
  - `webSearch.requireZdr` (boolean): Whether only engines with zero data retention may run (default false). While set, no web search runs, in chat or in Code, until the engine applies it
  - `sessionContent` ("never" | "user" | "user_and_org"): The content policy for synced sessions that runners follow, readable by every member. The default is user in every organization; only a saved user_and_org applies, and it reads as user while the organization has no recovery key (getOrgRecoveryKey)
  - `multiplayerSessions` (boolean): Whether members read each other's team-visible synced sessions, still end-to-end encrypted. False by default; always false in a personal one
  - `cloudHistory` (boolean): Whether Gateway stores the organization's cloud session history, so a sleeping cloud session reads on any device. True by default. Off, Gateway stores none. Omitted for an organization that cannot run cloud machines and stores no cloud history
  - `webSessionViewer` (boolean): Whether Nexus UI in a browser opens the organization's synced sessions. True by default. Off, Nexus UI's credential (its session token or its server's secret) gets 403 web_session_viewer_off for sealed events, key copies and a new device
- `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/orgs/settings" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Set org settings

`PUT /v1/orgs/settings`

Change the organization's settings (owners and admins). chatRetentionDays: 1 to 3650, or null for the default; a shorter window deletes expired messages at once. Audited as org.settings_changed.

Permission: `org.settings` (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)

- `hiddenMobilePlaces` (array of "assistant" | "artifacts" | "customize" | null): Places an owner hides from members in the mobile drawer. Only an owner can change this setting. Null makes all places visible.
- `chatRetentionDays` (integer | null) [min 1; max 3650]
- `agentSubscriptions` (boolean | null): Whether `nexus claude --subscription` may run (people's own Claude logins, outside Gateway's checks); null for the default, true
- `growthEvents` (boolean | null): Whether the Gateway records the organization's growth events in its own store; null for the default, true. No safety control depends on it
- `chatSuggestions` (boolean | null): Whether chat sessions suggest the person's next message after an answer, a call the organization pays for; null for the default, true
- `webSearch.engine` ("off" | "borrowed" | null): Gates hosted web search in chat and in Code (`nexus claude --api`, `nexus codex --api`): off or borrowed; null for the default, borrowed. An unknown engine is a 400 that names the allowed values
- `webSearch.model` (string | null): The model that runs a chat's search, whatever the chat's model is: cheapest, or the catalog id of a model that can search (`GET /v1/models` lists it with `web_search_usd`); null or default for the default, the chat's own model (the cheapest on nexus/auto). It is stored as the model's catalog id. Chat only: in Code an agent searches on its own model. Anything else is a 400 that lists the models
- `webSearch.domains` (object | null): Domains a search result may (allow, when set) or may not (deny) come from; null for the default, both empty. While any is set, no web search runs, in chat or in Code, until the engine applies them
  - `allow` (array of string)
  - `deny` (array of string)
- `webSearch.maxPerTurn` (integer | null): Most searches in one chat turn; null for the default, 3. Applies to Gateway-run engines (chat) only [min 1; max 10]
- `webSearch.requireZdr` (boolean | null): Whether only engines with zero data retention may run; null for the default, false. While set, no web search runs, in chat or in Code, until the engine applies it
- `artifacts.external` ("off" | "named" | "public" | null): Sharing an artifact outside the organization: off, named (named people by verified email) or public (also anyone with an unguessable link); null for the default, public. Another value is a 400
- `artifacts.external.code` (boolean | null): Whether an artifact shared outside the organization may include Ask your code's sources; null for the default, false
- `artifacts.external.domains` (object | null): Email domains a named share outside the organization may (allow, when set) or may not (deny) go to; null for the default, both empty
  - `allow` (array of string)
  - `deny` (array of string)
- `artifacts.external.expiry` (object | null): Limits on how long a public link stays open: maxDays (1-3650, or null for no limit) and whether an expiry is required; null for the default, no limit and not required
  - `maxDays` (integer | null) [min 1; max 3650]
  - `required` (boolean)
- `artifacts.external.continue` (boolean | null): Whether people outside the organization may continue or remix what it shares; null for the default, true
- `artifacts.external.who` ("everyone" | "admins" | null): Who may share outside the organization: everyone or admins; null for the default, everyone
- `artifacts.pages` (boolean | null): Pages on or off; null for the default, true
- `artifacts.pages.public` (boolean | null): Public links to pages; null for the default (false in a company organization, true in a personal one)
- `artifacts.pages.queries` (boolean | null): Page queries (Nexus Data): a page's owner may approve read-only queries on a connection for its readers; null for the default, false
- `sessionContent` ("never" | "user" | "user_and_org" | null): What leaves a person's machine when coding sessions sync, end-to-end encrypted: never (only usage numbers), user (only the person's own devices can read it) or user_and_org (also the organization's recovery key); null for the default. Needs synced_sessions.manage_policy. user_and_org answers 409 org_recovery_key_required until the organization registers a recovery key (putOrgRecoveryKey)
- `multiplayerSessions` (boolean | null): Whether members read each other's team-visible synced sessions; null for the default, false. A personal organization answers 403 personal_organization
- `cloudHistory` (boolean | null): Whether Gateway stores the organization's cloud session history, readable by Nexus's systems and encrypted at rest; null for the default, true. Off, Gateway stores none and deletes what it holds
- `webSessionViewer` (boolean | null): Whether Nexus UI in a browser opens the organization's synced sessions; null for the default, true. Needs synced_sessions.manage_policy. Off, Nexus UI's credential gets 403 web_session_viewer_off for sealed events, key copies and a new device; the desktop, the phone and the CLI read as before

### Responses

- `200` OK (application/json, OrgSettings)
  - `hiddenMobilePlaces` (array of "assistant" | "artifacts" | "customize"): Places hidden from members in the mobile drawer. The owner still sees them.
  - `chatRetentionDays` (integer, required): Days chat messages are kept (90 by default) [min 1; max 3650]
  - `agentSubscriptions` (boolean): Whether `nexus claude --subscription` may run (true by default)
  - `growthEvents` (boolean): Whether the Gateway records the organization's growth events in its own store (true by default)
  - `chatSuggestions` (boolean): Whether chat sessions suggest the person's next message after an answer, a call the organization pays for (true by default)
  - `defaults` (object, required)
    - `hiddenMobilePlaces` (array of "assistant" | "artifacts" | "customize") [default []]
    - `chatRetentionDays` (integer)
    - `growthEvents` (boolean)
    - `chatSuggestions` (boolean)
    - `artifacts.external` ("off" | "named" | "public")
    - `artifacts.external.code` (boolean)
    - `artifacts.external.domains` (object)
      - `allow` (array of string, required)
      - `deny` (array of string, required)
    - `artifacts.external.expiry` (object)
      - `maxDays` (integer | null, required) [min 1; max 3650]
      - `required` (boolean, required)
    - `artifacts.external.continue` (boolean)
    - `artifacts.external.who` ("everyone" | "admins")
    - `agentSubscriptions` (boolean)
    - `artifacts.pages` (boolean)
    - `artifacts.pages.public` (boolean)
    - `artifacts.pages.queries` (boolean)
    - `webSearch.engine` ("off" | "borrowed")
    - `webSearch.model` (string | null)
    - `webSearch.domains` (object)
      - `allow` (array of string, required)
      - `deny` (array of string, required)
    - `webSearch.maxPerTurn` (integer)
    - `webSearch.requireZdr` (boolean)
    - `sessionContent` ("never" | "user" | "user_and_org")
    - `multiplayerSessions` (boolean)
    - `cloudHistory` (boolean)
    - `webSessionViewer` (boolean)
  - `updatedAt` (string (date-time))
  - `artifacts.external` ("off" | "named" | "public"): Sharing artifacts outside the organization: off, named people only, or also public links (default public)
  - `artifacts.external.code` (boolean): May external snapshots include Ask your code's sources (default false)
  - `artifacts.external.domains` (object): Email domains named outsiders may (allow, when set) or may not (deny) have; a domain matches itself and its subdomains (default both empty)
    - `allow` (array of string, required)
    - `deny` (array of string, required)
  - `artifacts.external.expiry` (object): The longest a public link may stay open, and whether every public link must expire (default none and false)
    - `maxDays` (integer | null, required) [min 1; max 3650]
    - `required` (boolean, required)
  - `artifacts.external.continue` (boolean): May people outside continue the chat in an organization of their own, at its expense (default true)
  - `artifacts.external.who` ("everyone" | "admins"): Who may share outside: everyone, or owners and admins (default everyone)
  - `artifacts.pages` (boolean): Pages: off refuses new pages, versions, shares and every page frame (default true)
  - `artifacts.pages.public` (boolean): Public links to pages: off refuses new ones and stops existing ones from opening (default false in a company organization, true in a personal one)
  - `artifacts.pages.queries` (boolean): Page queries (Nexus Data): on lets a page's owner approve read-only queries on a connection, whose results the page's readers see; off refuses saving and running them (default false)
  - `webSearch.engine` ("off" | "borrowed"): Gates hosted web search in chat and in Code (`nexus claude --api`, `nexus codex --api`): off or borrowed (default borrowed; off means no web search runs)
  - `webSearch.model` (string | null): The model that runs a chat's search: null for the default (the chat's own model, the cheapest on nexus/auto), cheapest, or a model's catalog id. A pinned model the person may not use, or nobody pays for, gives that person no search, and so does an id this Gateway cannot call, which is shown as stored. Chat only
  - `webSearch.domains` (object): Domains a search result may (allow, when set) or may not (deny) come from (default both empty). While any is set, no web search runs, in chat or in Code, until the engine applies them
    - `allow` (array of string, required)
    - `deny` (array of string, required)
  - `webSearch.maxPerTurn` (integer): Most searches in one chat turn (default 3). Applies to Gateway-run engines (chat) only [min 1; max 10]
  - `webSearch.requireZdr` (boolean): Whether only engines with zero data retention may run (default false). While set, no web search runs, in chat or in Code, until the engine applies it
  - `sessionContent` ("never" | "user" | "user_and_org"): The content policy for synced sessions that runners follow, readable by every member. The default is user in every organization; only a saved user_and_org applies, and it reads as user while the organization has no recovery key (getOrgRecoveryKey)
  - `multiplayerSessions` (boolean): Whether members read each other's team-visible synced sessions, still end-to-end encrypted. False by default; always false in a personal one
  - `cloudHistory` (boolean): Whether Gateway stores the organization's cloud session history, so a sleeping cloud session reads on any device. True by default. Off, Gateway stores none. Omitted for an organization that cannot run cloud machines and stores no cloud history
  - `webSessionViewer` (boolean): Whether Nexus UI in a browser opens the organization's synced sessions. True by default. Off, Nexus UI's credential (its session token or its server's secret) gets 403 web_session_viewer_off for sealed events, key copies and a new device
- `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 PUT "$NEXUS_URL/v1/orgs/settings" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "hiddenMobilePlaces": [
      "assistant"
    ],
    "chatRetentionDays": 1,
    "agentSubscriptions": false,
    "growthEvents": false,
    "chatSuggestions": false,
    "webSearch.engine": "off",
    "webSearch.model": "<webSearch.model>",
    "webSearch.domains": {
      "allow": [
        "<allow>"
      ],
      "deny": [
        "<deny>"
      ]
    },
    "webSearch.maxPerTurn": 1,
    "webSearch.requireZdr": false,
    "artifacts.external": "off",
    "artifacts.external.code": false,
    "artifacts.external.domains": {
      "allow": [
        "<allow>"
      ],
      "deny": [
        "<deny>"
      ]
    },
    "artifacts.external.expiry": {
      "maxDays": 1,
      "required": false
    },
    "artifacts.external.continue": false,
    "artifacts.external.who": "everyone",
    "artifacts.pages": false,
    "artifacts.pages.public": false,
    "artifacts.pages.queries": false,
    "sessionContent": "never",
    "multiplayerSessions": false,
    "cloudHistory": false,
    "webSessionViewer": false
  }'
```

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

## Get effective settings

`GET /v1/orgs/effective-settings`

Every control in the control inventory, as far as the caller reaches: owners and admins every control, a team lead the controls of the teams they lead, everyone their own values and those of their teams and the organization. An entry also keeps its own route's permission: a control the caller may not read there (the automatic top-up without `org.billing`) carries the refusal. An entry whose source was not read carries an error, and the answer stays 200.

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

### Responses

- `200` OK (application/json, EffectiveSettings)
  - `controls` (array of EffectiveSetting, required)
    - `key` (string, required): The control's key in the inventory (controls.json).
    - `capability` (string, required)
    - `value` (any): The control's value, when its source was read: any JSON value. A model policy control maps each level that stores a rule (`organization:organization`, `team:<slug>`, `agent:<name>`) to the rule it stores. A level without a rule inherits the rule above it, so one level's entry is not, on its own, the rule enforced there.
    - `error` (string): Set only when the control's value was not read. Tell a read value from an unread one by this field, not by `value`: a read value can be `null`.
- `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/orgs/effective-settings" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Get custody report

`GET /v1/orgs/custody`

The vault's custody report for the organization (owners and admins): which master key wraps its data keys and who holds that master (Nexus's NEXUS_SECRET, a Cloud KMS key in Nexus's project, or one in the customer's own project, which the customer can revoke); every version of its data key; and every secret or reference the vault holds, with its table, its data key version and its last four characters. It never holds a secret or a data key.

Permission: `audit.read_all` (Owner, Admin).

### Responses

- `200` OK (application/json, CustodyReport)
  - `master` (CustodyMaster, required)
    - `holder` ("nexus_secret" | "nexus_kms" | "customer_kms", required): `nexus_secret`: derived from Nexus's NEXUS_SECRET. `nexus_kms`: a Cloud KMS key in Nexus's project. `customer_kms`: a Cloud KMS key in the customer's own project; the customer can revoke Nexus's access.
    - `key` (string): The customer's Cloud KMS key's resource name; absent when Nexus holds the master.
  - `dataKeys` (array of CustodyDataKey, required)
    - `version` (integer, required)
    - `master` (CustodyMaster, required)
      - `holder` ("nexus_secret" | "nexus_kms" | "customer_kms", required): `nexus_secret`: derived from Nexus's NEXUS_SECRET. `nexus_kms`: a Cloud KMS key in Nexus's project. `customer_kms`: a Cloud KMS key in the customer's own project; the customer can revoke Nexus's access.
      - `key` (string): The customer's Cloud KMS key's resource name; absent when Nexus holds the master.
    - `createdAt` (string (date-time), required)
  - `holdings` (array of CustodyHolding, required)
    - `kind` ("provider_key" | "connector_credential", required)
    - `name` (string, required): The provider (`anthropic`, or `anthropic:team:team_…` for a team's key), or the connector and its scope (`linear:user:usr_…`).
    - `table` (string, required): The table that stores it.
    - `sealedWith` ("data_key" | "nexus_secret" | "reference", required): `data_key`: the organization's data key of version `keyVersion`. `nexus_secret`: a key derived from NEXUS_SECRET, sealed before data keys. `reference`: no secret is held, only a reference to a vendor's short-lived token.
    - `keyVersion` (integer)
    - `last4` (string)
    - `createdAt` (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/orgs/custody" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Get org subscription

`GET /v1/orgs/subscription`

The organization's subscription (anyone in it): the plan, the member who pays, the member who receives billing mail, the paid term, the status and the seats (one per human member). An organization nobody changed yet reads as `active` since it was created, with everything else `null` and `updatedAt: null`.

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

### Responses

- `200` OK (application/json, OrgSubscription)
  - `plan` (string | null, required): Written by Billing: an entry of Billing Capabilities' plan catalogue; null until one is chosen.
  - `payerUserId` (string | null, required): The member who pays; null until named.
  - `billingContactUserId` (string | null, required): The member who receives billing mail; null until named.
  - `periodStart` (string (date) | null, required): Written by Billing: the first day of the paid term.
  - `periodEnd` (string (date) | null, required): Written by Billing: the day the paid term ends; null for an open term.
  - `status` ("active" | "past_due" | "cancelled" | "under_contract", required): Written by Billing alone. It changes what the organization is entitled to, never who is in it.
  - `statusEffectiveAt` (string (date-time), required): When the status took effect.
  - `effectiveAt` (string (date-time), required): When the newest change took effect.
  - `updatedAt` (string (date-time) | null, required): When the subscription was last written; null until its first change.
  - `seats` (integer, required): One per member that `GET /v1/orgs/members` lists, counted when read. [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 |
| 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/orgs/subscription" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Change org subscription

`PATCH /v1/orgs/subscription`

Name the payer and the billing contact (owners only). A field changes when present and clears when `null`; an absent field stays. Both must be members (400 `not_a_member`). `plan`, `periodStart`, `periodEnd` and `status` are refused (400 `written_by_billing`): Billing writes them from what the organization pays for. `effectiveAt` (default now) is when the change took effect: never in the future and never before the newest change (400 `invalid_effective_at`). `dryRun: true` answers with the result and writes nothing. Audited as `subscription.changed`, with the changed fields before and after and `metadata.effectiveAt`; a body that changes nothing writes nothing.

Permission: `org.billing` (Owner).

### 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)

- `payerUserId` (string | null): The member who pays: a user id from `GET /v1/orgs/members`.
- `billingContactUserId` (string | null): The member who receives billing mail.
- `effectiveAt` (string (date-time)): When the change took effect; default now.
- `dryRun` (boolean): Check the change and answer with the result; write nothing. [default false]

### Responses

- `200` OK (application/json, OrgSubscriptionChange)
  - `subscription` (OrgSubscription, required)
    - `plan` (string | null, required): Written by Billing: an entry of Billing Capabilities' plan catalogue; null until one is chosen.
    - `payerUserId` (string | null, required): The member who pays; null until named.
    - `billingContactUserId` (string | null, required): The member who receives billing mail; null until named.
    - `periodStart` (string (date) | null, required): Written by Billing: the first day of the paid term.
    - `periodEnd` (string (date) | null, required): Written by Billing: the day the paid term ends; null for an open term.
    - `status` ("active" | "past_due" | "cancelled" | "under_contract", required): Written by Billing alone. It changes what the organization is entitled to, never who is in it.
    - `statusEffectiveAt` (string (date-time), required): When the status took effect.
    - `effectiveAt` (string (date-time), required): When the newest change took effect.
    - `updatedAt` (string (date-time) | null, required): When the subscription was last written; null until its first change.
    - `seats` (integer, required): One per member that `GET /v1/orgs/members` lists, counted when read. [min 0]
  - `changed` (array of string, required): The fields that changed, or would change on a dry run; empty when nothing did.
  - `dryRun` (boolean, required): True when nothing was written.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 | `not_a_member` | Both must be members (400 `not_a_member`) |
| 400 | `written_by_billing` | `plan`, `periodStart`, `periodEnd` and `status` are refused (400 `written_by_billing`): Billing writes them from what the organization pays for |
| 400 | `invalid_effective_at` | Never in the future and never before the newest change (400 `invalid_effective_at`) |
| 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 PATCH "$NEXUS_URL/v1/orgs/subscription" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "payerUserId": "<payerUserId>",
    "billingContactUserId": "<billingContactUserId>",
    "effectiveAt": "2026-10-01T00:00:00Z",
    "dryRun": false
  }'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#patch%3A%2Fv1%2Forgs%2Fsubscription)

## List plans

`GET /v1/billing/plans`

The plans this organization can take, priced as Stripe holds them (owner only): one source for Nexus UI, the desktop app, both CLIs and the phone. A per-seat plan is for companies and any other plan for personal organizations, so only the organization's kind is listed (`audience`). Each plan has its name (the Stripe Product's), `perSeat`, `minSeats`, and per interval `amountUsd` (the price, per seat for a per-seat plan) and `includedUsd` (included usage each month, per seat), as decimal strings. Each plan also has its cloud hours a month per seat (`includedHours`), the price of an hour past them (`hourlyUsd`, a decimal string or null) and the machine sizes it allows (`sizes`). A price Stripe could not give has `amountUsd: null` and a machine-readable `error` (`stripe_error`, `stripe_timeout`, `inactive`, `not_usd`, `interval_mismatch`, `no_fixed_amount`). Cheapest a month first. `current` is the plan the organization's subscription holds. Prices are cached for 10 minutes. 502 `stripe_error` when Stripe gave none of the listed prices; 503 `not_configured` without Stripe or NEXUS_PLANS.

Permission: `org.billing` (Owner).

### Responses

- `200` OK (application/json, PlanCatalogue)
  - `audience` ("personal" | "company", required)
  - `plans` (array of CataloguePlan, required)
    - `plan` (string, required): The plan's key in NEXUS_PLANS, such as `plus`, `pro` or `teams_pro`.
    - `name` (string, required): The Stripe Product's name; the key when Stripe gave none.
    - `perSeat` (boolean, required)
    - `minSeats` (integer, required)
    - `includedHours` (integer, required): Cloud hours each month, in hours of the default machine size, per seat for a per-seat plan; 0 when NEXUS_PLANS sets none (pricing v3.0). [min 0]
    - `hourlyUsd` (string | null, required): The price of a default-size hour past the plan's hours, as a decimal string with six places; null when NEXUS_PLANS sets none. [pattern ^[0-9]+\.[0-9]{6}$]
    - `sizes` (array of "small" | "default" | "large" | "xlarge", required): The machine sizes the plan allows, smallest first; only `default` when NEXUS_PLANS sets none.
    - `intervals` (array of object, required)
      - `interval` ("month" | "year", required)
      - `amountUsd` (string | null, required): The price for the interval, per seat for a per-seat plan; null with `error`.
      - `includedUsd` (string, required): Included usage each month, per seat for a per-seat plan.
      - `error` (string | null, required): Why the price is not shown: `stripe_error`, `stripe_timeout`, `inactive`, `not_usd`, `interval_mismatch` or `no_fixed_amount`.
    - `current` (boolean, required): The organization's subscription holds this plan.
  - `current` (object | null, required): The plan the organization's subscription holds; null on the Free plan.
- `403` Not the owner (`permission_error`) (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.
- `502` Stripe gave none of the listed prices (`stripe_error`) (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` Stripe or NEXUS_PLANS is not configured (`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 |
| --- | --- | --- |
| 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 |
| 502 |  | Stripe gave none of the listed prices (`stripe_error`) |
| 502 | `stripe_error` | 502 `stripe_error` when Stripe gave none of the listed prices; 503 `not_configured` without Stripe or NEXUS_PLANS |
| 503 |  | Stripe or NEXUS_PLANS is not configured (`not_configured`) |
| 503 | `not_configured` | 502 `stripe_error` when Stripe gave none of the listed prices; 503 `not_configured` without Stripe or NEXUS_PLANS |

### Example

```sh
curl "$NEXUS_URL/v1/billing/plans" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Change plan

`POST /v1/billing/plan/change`

Change the organization's plan, interval or seats (owner only). Body: `plan`, `interval`, `seats` for a per-seat plan (one per member, at least its minimum: left out, Gateway counts them), and `dryRun`. A change that costs more a month applies now, and so does monthly to yearly at the same rate a month or more (a yearly price costs its plan's monthly price a month): Stripe prorates it and invoices the difference at once, and the month's included usage grows by the difference at once (live mode, or `NEXUS_PLANS_TEST_GRANTS=on`). A payment that fails changes nothing (402 `payment_failed`). Any other change (a cheaper plan, fewer seats, yearly to monthly, monthly to a yearly plan that costs less a month) applies at the period's end through a Stripe subscription schedule, shows as `pendingChange` on `GET /v1/billing`, and replaces an earlier pending change; `DELETE` cancels it. `dryRun: true` answers `when`, `at` and `amountDueUsd` (what is invoiced now) and changes nothing. The Idempotency-Key header keys the Stripe call. 400 `unknown_plan`, `plan_not_for_org`, `same_plan`; 409 `no_plan` without a paid plan, `plan_ending` while the plan is cancelled (renew it on Stripe's billing page first); 502 `stripe_error`; 503 `not_configured` until Stripe and NEXUS_PLANS are set.

Permission: `org.billing` (Owner).

### 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)

- `plan` (string, required)
- `interval` ("month" | "year", required)
- `seats` (integer): For a per-seat plan: from its minimum to 1000 (its minimum when absent).
- `dryRun` (boolean): Answer what the change would charge and when, and change nothing.

### Responses

- `200` OK (application/json, PlanChange)
  - `when` ("now" | "period_end", required)
  - `at` (string, required): When it applies (ISO 8601).
  - `amountDueUsd` (string | null, required): What is invoiced now, a decimal string: a dry run's preview, or 0 for a change at the period's end; null after a change applied now (Stripe invoiced it).
  - `dryRun` (boolean, required)
  - `plan` (BillingPlan | null, required): The plan after the change, or as it is for a dry run.
- `400` An unknown plan or interval, seats out of range, a plan for the other kind of organization, or the plan the organization is on (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.
- `402` Stripe could not take the payment for the change (`payment_failed`); nothing changed (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` Not the owner (`permission_error`) (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` No paid plan to change (`no_plan`), or the plan is cancelled, for this period or a later one (`plan_ending`, with `cancelAt` on `GET /v1/billing`) (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.
- `502` Stripe refused the call, did not answer, or gave no prices to compare (`stripe_error`) (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` Stripe or NEXUS_PLANS is not configured (`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 |  | An unknown plan or interval, seats out of range, a plan for the other kind of organization, or the plan the organization is on |
| 400 | `unknown_plan` | 400 `unknown_plan`, `plan_not_for_org`, `same_plan`; 409 `no_plan` without a paid plan, `plan_ending` while the plan is cancelled (renew it on Stripe's billing page first); 502 `stripe_error`; 503 `not_configured` until Stripe and NEXUS_PLANS are set |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 402 | `budget_exceeded` | Stripe could not take the payment for the change (`payment_failed`); nothing changed |
| 402 | `payment_failed` | A payment that fails changes nothing (402 `payment_failed`) |
| 403 | `role_required` | Your role does not have this permission |
| 409 |  | No paid plan to change (`no_plan`), or the plan is cancelled, for this period or a later one (`plan_ending`, with `cancelAt` on `GET /v1/billing`) |
| 409 | `no_plan` | 400 `unknown_plan`, `plan_not_for_org`, `same_plan`; 409 `no_plan` without a paid plan, `plan_ending` while the plan is cancelled (renew it on Stripe's billing page first); 502 `stripe_error`; 503 `not_configured` until Stripe and NEXUS_PLANS are set |
| 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 |
| 502 |  | Stripe refused the call, did not answer, or gave no prices to compare (`stripe_error`) |
| 502 | `stripe_error` | 400 `unknown_plan`, `plan_not_for_org`, `same_plan`; 409 `no_plan` without a paid plan, `plan_ending` while the plan is cancelled (renew it on Stripe's billing page first); 502 `stripe_error`; 503 `not_configured` until Stripe and NEXUS_PLANS are set |
| 503 |  | Stripe or NEXUS_PLANS is not configured (`not_configured`) |
| 503 | `not_configured` | 400 `unknown_plan`, `plan_not_for_org`, `same_plan`; 409 `no_plan` without a paid plan, `plan_ending` while the plan is cancelled (renew it on Stripe's billing page first); 502 `stripe_error`; 503 `not_configured` until Stripe and NEXUS_PLANS are set |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/billing/plan/change" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "plan": "3f9c0a1b2c3d4e5f",
    "interval": "month"
  }'
```

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

## Cancel plan change

`DELETE /v1/billing/plan/change`

Cancel the plan change pending for the period's end (owner only): Stripe releases the schedule and the plan stays as it is. 409 `no_pending_change` without one; 502 `stripe_error`; 503 `not_configured` until Stripe is set up.

Permission: `org.billing` (Owner).

### 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, object)
  - `plan` (BillingPlan | null, required)
- `403` Not the owner (`permission_error`) (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` No plan change pending (`no_pending_change`) (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.
- `502` Stripe refused the call or did not answer (`stripe_error`) (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` Stripe is not configured (`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 |
| --- | --- | --- |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 409 |  | No plan change pending (`no_pending_change`) |
| 409 | `no_pending_change` | 409 `no_pending_change` without one; 502 `stripe_error`; 503 `not_configured` until Stripe is set up |
| 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 |
| 502 |  | Stripe refused the call or did not answer (`stripe_error`) |
| 502 | `stripe_error` | 409 `no_pending_change` without one; 502 `stripe_error`; 503 `not_configured` until Stripe is set up |
| 503 |  | Stripe is not configured (`not_configured`) |
| 503 | `not_configured` | 409 `no_pending_change` without one; 502 `stripe_error`; 503 `not_configured` until Stripe is set up |

### Example

```sh
curl -X DELETE "$NEXUS_URL/v1/billing/plan/change" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

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

## Start plan

`POST /v1/billing/plan`

Start a plan for the organization (owner only): a link to a Stripe Checkout page that starts the subscription. Stripe sends the person back to `<NEXUS_UI_URL>/<org>/billing?checkout=plan`, or `=plan_cancelled`. The plans are the ones in NEXUS_PLANS (Pro, Max's tiers, Team, Team Premium), billed monthly or yearly; a per-seat plan has one seat per member, at least its minimum (the seats follow the members), so `seats` may be left out and, when given, must be that number. The plan's included usage is granted once a month as a Nexus subsidy and does not roll over. A per-seat plan is for companies and any other plan for personal organizations (`GET /v1/billing/plans` lists an organization's). 400 `unknown_plan` for a plan or interval this Gateway does not sell; 400 `plan_not_for_org` for a plan of the other kind of organization; 409 `plan_active` while the organization has a live subscription: change it with `POST /v1/billing/plan/change`. 502 `stripe_error` when Stripe refuses or does not answer. 503 `not_configured` until Stripe and NEXUS_PLANS are set, or without NEXUS_UI_URL.

Permission: `org.billing` (Owner).

### 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)

- `plan` (string, required): A plan in NEXUS_PLANS, such as plus, pro, teams_plus or teams_pro
- `interval` ("month" | "year", required)
- `seats` (integer): Per-seat plans only (Teams Plus, Teams Pro); the plan's minimum when absent [min 1; max 1000]

### Responses

- `200` OK (application/json, PaymentMethodSetup)
  - `url` (string, required): Stripe Checkout's page, where the person enters the card.
  - `expiresAt` (string (date-time), required): When Stripe stops accepting `url`.
  - `checkoutSessionId` (string): Exact Checkout session to confirm; returned by current Gateways.
- `400` A bad plan, interval or seats (`unknown_plan`, `invalid_request`) (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` Not the owner (`permission_error`) (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` A live subscription already holds the plan (`plan_active`) (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.
- `502` Stripe refused the call or did not answer (`stripe_error`) (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` Stripe or NEXUS_PLANS is not configured, or NEXUS_UI_URL is not set (`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 |  | A bad plan, interval or seats (`unknown_plan`, `invalid_request`) |
| 400 | `unknown_plan` | 400 `unknown_plan` for a plan or interval this Gateway does not sell; 400 `plan_not_for_org` for a plan of the other kind of organization; 409 `plan_active` while the organization has a live subscription: change it with `POST /v1/billing/plan/change` |
| 400 | `plan_not_for_org` | 400 `unknown_plan` for a plan or interval this Gateway does not sell; 400 `plan_not_for_org` for a plan of the other kind of organization; 409 `plan_active` while the organization has a live subscription: change it with `POST /v1/billing/plan/change` |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 409 |  | A live subscription already holds the plan (`plan_active`) |
| 409 | `plan_active` | 400 `unknown_plan` for a plan or interval this Gateway does not sell; 400 `plan_not_for_org` for a plan of the other kind of organization; 409 `plan_active` while the organization has a live subscription: change it with `POST /v1/billing/plan/change` |
| 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 |
| 502 |  | Stripe refused the call or did not answer (`stripe_error`) |
| 502 | `stripe_error` | 502 `stripe_error` when Stripe refuses or does not answer |
| 503 |  | Stripe or NEXUS_PLANS is not configured, or NEXUS_UI_URL is not set (`not_configured`) |
| 503 | `not_configured` | 503 `not_configured` until Stripe and NEXUS_PLANS are set, or without NEXUS_UI_URL |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/billing/plan" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "plan": "3f9c0a1b2c3d4e5f",
    "interval": "month"
  }'
```

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

## Set after the fact

`PUT /v1/billing/after-the-fact`

Turn paying after the fact on or off, or change its monthly usage limit (owner only; pricing v2.0). Body: `enabled`, and `limitUsd` as a decimal string in whole cents. Turning it on needs the payment method on file (409 `no_payment_method`), and so does turning it on again with no `limitUsd`; a call with `limitUsd` changes the limit of a setting already on without one. A closed organization cannot turn it on (409 `organization_closed`). Calls the free start and the credits cannot pay then go on the card, at provider price plus Nexus's rate, up to the limit in a UTC month (past it, 402 `usage_limit_reached`). Gateway's Stripe sweep charges the card off session each time the unpaid usage reaches `pricing.thresholdUsd` (less carries over, and what is left is charged once it is turned off); a charge that fails stops the calls the card pays (402 `payment_failed`) and tells the owners, until a charge goes through. A disputed payment (`charge.dispute.created`) stops its card the same way (`failed.reason`: `disputed`) until an owner adds another card, and that card never pays again (409 `card_disputed` on turning it on with that card, or on again with no `limitUsd`; a limit change still works). Off stops new calls on the card and still charges what is owed. Off with `limitUsd` keeps the limit, even when it was never on. Audited as `billing.after_the_fact_changed`. 400 `invalid_amount`; 503 `not_configured` until Stripe is set up.

Permission: `org.billing` (Owner).

### 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)

- `enabled` (boolean, required)
- `limitUsd` (string): The monthly usage limit, dollars in whole cents, from 1.00 to 100000.00 (at most 100.00 in a new organization's first 7 days). A new setting starts at `pricing.defaultLimitUsd`.

### Responses

- `200` OK (application/json, SetAfterTheFact)
  - `afterTheFact` (AfterTheFact | null, required): The setting after; null after turning off what was never on with no `limitUsd`.
- `400` `limitUsd` outside $1 to $100,000 ($100 in a new organization's first 7 days) or not in whole cents (`invalid_amount`); `enabled` missing (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` Not the owner (`permission_error`) (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` Turning on with no payment method on file (`no_payment_method`) (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` Stripe is not configured (`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 |  | `limitUsd` outside $1 to $100,000 ($100 in a new organization's first 7 days) or not in whole cents (`invalid_amount`); `enabled` missing |
| 400 | `invalid_amount` | 400 `invalid_amount`; 503 `not_configured` until Stripe is set up |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 402 | `usage_limit_reached` | Calls the free start and the credits cannot pay then go on the card, at provider price plus Nexus's rate, up to the limit in a UTC month (past it, 402 `usage_limit_reached`) |
| 402 | `payment_failed` | Gateway's Stripe sweep charges the card off session each time the unpaid usage reaches `pricing.thresholdUsd` (less carries over, and what is left is charged once it is turned off); a charge that fails stops the calls the card pays (402 `payment_failed`) and tells the owners, until a charge goes through |
| 403 | `role_required` | Your role does not have this permission |
| 409 |  | Turning on with no payment method on file (`no_payment_method`) |
| 409 | `no_payment_method` | Turning it on needs the payment method on file (409 `no_payment_method`), and so does turning it on again with no `limitUsd`; a call with `limitUsd` changes the limit of a setting already on without one |
| 409 | `organization_closed` | A closed organization cannot turn it on (409 `organization_closed`) |
| 409 | `card_disputed` | `disputed`) until an owner adds another card, and that card never pays again (409 `card_disputed` on turning it on with that card, or on again with no `limitUsd`; a limit change still works) |
| 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 |  | Stripe is not configured (`not_configured`) |
| 503 | `not_configured` | 400 `invalid_amount`; 503 `not_configured` until Stripe is set up |

### Example

```sh
curl -X PUT "$NEXUS_URL/v1/billing/after-the-fact" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "enabled": false
  }'
```

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

## List receipts

`GET /v1/billing/receipts`

The organization's receipts (owner only; pricing v2.0), newest first, at most 100: credit purchases (`credits`, `auto_topup`), charges for usage after the fact (`usage`) and invoiced months (`invoice`). Read from Gateway's own records, with no call to Stripe. 503 `not_configured` until Stripe is set up.

Permission: `org.billing` (Owner).

### Responses

- `200` OK (application/json, ReceiptList)
  - `receipts` (array of Receipt, required)
    - `id` (string, required): The payment (`pi_…`), or `month:<YYYY-MM>` for an invoiced month.
    - `at` (string (date-time), required)
    - `kind` ("credits" | "auto_topup" | "usage" | "invoice", required)
    - `description` (string, required): What it paid for, such as `Credits` or `Usage, threshold charge`.
    - `amountUsd` (string, required)
    - `status` ("paid" | "open" | "failed" | "void", required)
    - `url` (string | null, required): Stripe's page of an invoiced month; null for a payment.
    - `receipt` (boolean, required): Stripe has a receipt page for it: `GET /v1/billing/receipts/{id}` answers its link.
- `403` Not the owner (`permission_error`) (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` Stripe is not configured (`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 |
| --- | --- | --- |
| 100 | `credits` | He organization's receipts (owner only; pricing v2.0), newest first, at most 100: credit purchases (`credits`, `auto_topup`), charges for usage after the fact (`usage`) and invoiced months (`invoice`) |
| 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 |
| 503 |  | Stripe is not configured (`not_configured`) |
| 503 | `not_configured` | 503 `not_configured` until Stripe is set up |

### Example

```sh
curl "$NEXUS_URL/v1/billing/receipts" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Get receipt

`GET /v1/billing/receipts/{paymentId}`

Stripe's receipt page of one of the organization's payments (owner only; pricing v2.0): a credit purchase or a charge for usage after the fact, by its `pi_…` id. 404 `not_found` for a payment that is not the organization's; 409 `no_receipt` while Stripe has none; 502 `stripe_error`; 503 `not_configured` until Stripe is set up.

Permission: `org.billing` (Owner).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `paymentId` | path | string | yes | The payment's id (`pi_…`); any other id is no receipt (404). |

### Responses

- `200` OK (application/json, ReceiptLink)
  - `url` (string, required): Stripe's receipt page of the payment.
- `403` Not the owner (`permission_error`) (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` Not one of the organization's payments (`not_found`) (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` Stripe has no receipt for the payment yet (`no_receipt`) (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` Stripe is not configured (`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 |
| --- | --- | --- |
| 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 |  | Not one of the organization's payments (`not_found`) |
| 409 |  | Stripe has no receipt for the payment yet (`no_receipt`) |
| 409 | `no_receipt` | 404 `not_found` for a payment that is not the organization's; 409 `no_receipt` while Stripe has none; 502 `stripe_error`; 503 `not_configured` until Stripe is set up |
| 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 |
| 502 | `stripe_error` | 404 `not_found` for a payment that is not the organization's; 409 `no_receipt` while Stripe has none; 502 `stripe_error`; 503 `not_configured` until Stripe is set up |
| 503 |  | Stripe is not configured (`not_configured`) |
| 503 | `not_configured` | 404 `not_found` for a payment that is not the organization's; 409 `no_receipt` while Stripe has none; 502 `stripe_error`; 503 `not_configured` until Stripe is set up |

### Example

```sh
curl "$NEXUS_URL/v1/billing/receipts/<paymentId>" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Billing operation

`GET /v1/billing/operations/{operationId}`

Confirm one billing operation

Permission: `org.billing` (Owner).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `operationId` | path | string | yes |  |

### Responses

- `200` OK (application/json, BillingOperation)
  - `kind` ("card" | "credits", required)
  - `status` ("pending" | "complete" | "expired" | "failed" | "superseded", required): `superseded`: a newer card setup set its card first, so this one ended without setting the default.
- `403` Not the owner (`permission_error`) (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` Not one of the organization's payments (`not_found`) (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` Stripe is not configured (`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 |
| --- | --- | --- |
| 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 |  | Not one of the organization's payments (`not_found`) |
| 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 |  | Stripe is not configured (`not_configured`) |

### Example

```sh
curl "$NEXUS_URL/v1/billing/operations/<operationId>" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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