# Chat sessions

> Chat sessions, Nexus UI's home and `nexus chat`. Two modes: Chat, with any model you may use, and Ask your code, grounded in your organization's Nexus Wiki. Sessions are private to their author; messages are kept for the organization's retention window (90 days by default, GET/PUT /v1/orgs/settings).

## List chat sessions

`GET /v1/chat/sessions`

Your own chat sessions, most recently active first, a page at a time. Private: nobody else's are listed, for owners and admins too.

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

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `limit` | query | integer | no |  |
| `cursor` | query | string | no | NextCursor of the previous page |
| `q` | query | string | no | Words in the title or the messages |
| `archived` | query | "exclude" \| "include" \| "only" | no |  |

### Responses

- `200` OK (application/json, object)
  - `sessions` (array of ChatSession, required)
    - `id` (string, required)
    - `title` (string, required): The first question until you rename it
    - `mode` ("chat" | "ask", required): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
    - `model` (string, required): The model asked for: nexus/auto by default
    - `lastModel` (string): The model that ran last
    - `team` (string): The team its spend is attributed to
    - `archived` (boolean, required)
    - `webSearch` (boolean): Whether the model may search the web in this session (default false)
    - `messageCount` (integer, required)
    - `costUsd` (number, required): The sum of its model calls and of the web searches that returned results, settled in the ledger; a search that fails after the provider billed it is in the ledger, not in this sum
    - `createdAt` (string (date-time), required)
    - `updatedAt` (string (date-time), required)
    - `visibility` ("private" | "shared"): Private (the default) or shared: at least one active artifact
    - `sharing` (ChatSessionSharing): How a shared session is shared: its newest active artifact
      - `artifactId` (string, required)
      - `version` (integer, required)
      - `audience` (ArtifactAudience, required): Who may read an artifact, besides its author: inside the organization, the whole organization, chosen teams (their members and the members of the teams under them) or chosen people; outside it, named people by email (`external`) or anyone with the link (`public`). Readers outside the organization see the kind only.
        - `kind` ("org" | "teams" | "people" | "external" | "public", required)
        - `teams` (array of string, required): Team slugs (kind teams)
        - `people` (array of string, required): Members' emails (kind people); the outsiders with access (kind external). Empty for readers outside the organization.
      - `allowContinue` (boolean, required)
      - `url` (string, required): The link to hand out: a public link (kind public), the fast viewer (kind external), else the artifact in Nexus UI; absolute when the Gateway knows Nexus UI's URL (NEXUS_UI_URL), else a path
      - `path` (string, required): /app/<org>/artifacts/<id>
      - `viewerUrl` (string): The fast viewer: <origin>/a/<id>
      - `publicUrl` (string): Kind public: <origin>/a/<token>
      - `expiresAt` (string (date-time)): Kind public: when the link stops opening
    - `artifacts` (array of ArtifactLink): Every version shared from this session, newest first (revoked ones included)
      - `id` (string, required)
      - `version` (integer, required) [min 1]
      - `status` ("active" | "revoked", required)
      - `audience` ("org" | "teams" | "people" | "external" | "public", required)
      - `createdAt` (string (date-time), required)
      - `revokedAt` (string (date-time))
    - `author` (ArtifactAuthor): You (listed and read sessions)
      - `email` (string)
      - `name` (string)
    - `forkedFrom` (object): The artifact this session continues (POST /v1/artifacts/{id}/continue)
      - `artifactId` (string, required)
      - `version` (integer, required)
      - `title` (string)
  - `nextCursor` (string)
- `400` A query parameter is not valid: `limit` is not 1 to the page maximum, `cursor` is not one this API returned, or `archived` is not exclude, include or only. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `401` No credential (`missing_credential`), or a credential Gateway does not accept (`invalid_credential`). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `403` The key does not hold `chat.use` (`role_required`: a service account, a sandbox, or an agent not granted it), or the caller is not a person, such as a module key (`person_required`). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 |  | A query parameter is not valid: `limit` is not 1 to the page maximum, `cursor` is not one this API returned, or `archived` is not exclude, include or only. |
| 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/chat/sessions" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Create chat session

`POST /v1/chat/sessions`

Start a chat session. It is yours alone; its spend goes to you, the team (named, else your default) and the product chat. Audited as chat.session_created (never the title).

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

### Parameters

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

### Request body (application/json)

- `title` (string): Default: the first question [max length 120]
- `mode` ("chat" | "ask"): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
- `model` (string): Nexus/auto (default), nexus/default or a catalog id; whether you may use it is decided on each message
- `team` (string): A team slug you are in
- `webSearch` (boolean): Whether the model may search the web in this chat. It takes effect only while the organization's webSearch.engine is on [default false]

### Responses

- `201` Created (application/json, ChatSession)
  - `id` (string, required)
  - `title` (string, required): The first question until you rename it
  - `mode` ("chat" | "ask", required): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
  - `model` (string, required): The model asked for: nexus/auto by default
  - `lastModel` (string): The model that ran last
  - `team` (string): The team its spend is attributed to
  - `archived` (boolean, required)
  - `webSearch` (boolean): Whether the model may search the web in this session (default false)
  - `messageCount` (integer, required)
  - `costUsd` (number, required): The sum of its model calls and of the web searches that returned results, settled in the ledger; a search that fails after the provider billed it is in the ledger, not in this sum
  - `createdAt` (string (date-time), required)
  - `updatedAt` (string (date-time), required)
  - `visibility` ("private" | "shared"): Private (the default) or shared: at least one active artifact
  - `sharing` (ChatSessionSharing): How a shared session is shared: its newest active artifact
    - `artifactId` (string, required)
    - `version` (integer, required)
    - `audience` (ArtifactAudience, required): Who may read an artifact, besides its author: inside the organization, the whole organization, chosen teams (their members and the members of the teams under them) or chosen people; outside it, named people by email (`external`) or anyone with the link (`public`). Readers outside the organization see the kind only.
      - `kind` ("org" | "teams" | "people" | "external" | "public", required)
      - `teams` (array of string, required): Team slugs (kind teams)
      - `people` (array of string, required): Members' emails (kind people); the outsiders with access (kind external). Empty for readers outside the organization.
    - `allowContinue` (boolean, required)
    - `url` (string, required): The link to hand out: a public link (kind public), the fast viewer (kind external), else the artifact in Nexus UI; absolute when the Gateway knows Nexus UI's URL (NEXUS_UI_URL), else a path
    - `path` (string, required): /app/<org>/artifacts/<id>
    - `viewerUrl` (string): The fast viewer: <origin>/a/<id>
    - `publicUrl` (string): Kind public: <origin>/a/<token>
    - `expiresAt` (string (date-time)): Kind public: when the link stops opening
  - `artifacts` (array of ArtifactLink): Every version shared from this session, newest first (revoked ones included)
    - `id` (string, required)
    - `version` (integer, required) [min 1]
    - `status` ("active" | "revoked", required)
    - `audience` ("org" | "teams" | "people" | "external" | "public", required)
    - `createdAt` (string (date-time), required)
    - `revokedAt` (string (date-time))
  - `author` (ArtifactAuthor): You (listed and read sessions)
    - `email` (string)
    - `name` (string)
  - `forkedFrom` (object): The artifact this session continues (POST /v1/artifacts/{id}/continue)
    - `artifactId` (string, required)
    - `version` (integer, required)
    - `title` (string)
- `400` The body is not valid: `title` over 120 characters, `mode` not chat or ask, a `model` that is not a string, `webSearch` not a boolean, `team` not a slug, or a bad `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.
- `401` No credential (`missing_credential`), or a credential Gateway does not accept (`invalid_credential`). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `403` The key does not hold `chat.use` (`role_required`: a service account, a sandbox, or an agent not granted it), the caller is not a person (`person_required`), or the team named is not the caller's (`not_in_team`). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `404` The team named does not exist in this organization (`unknown_team`). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `409` The `Idempotency-Key`'s first request still runs (`idempotency_in_progress`) or was interrupted (`idempotency_interrupted`). The request does not run again. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `422` The `Idempotency-Key` was used for a different request (`idempotency_key_reused`). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 |  | The body is not valid: `title` over 120 characters, `mode` not chat or ask, a `model` that is not a string, `webSearch` not a boolean, `team` not a slug, or a bad `Idempotency-Key`. |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 |  | The team named does not exist in this organization (`unknown_team`). |
| 409 |  | The `Idempotency-Key`'s first request still runs (`idempotency_in_progress`) or was interrupted (`idempotency_interrupted`). The request does not run again. |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 |  | The `Idempotency-Key` was used for a different request (`idempotency_key_reused`). |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/chat/sessions" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "<title>",
    "mode": "chat",
    "model": "<model>",
    "team": "platform",
    "webSearch": false
  }'
```

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

## Get chat session

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

One of your sessions with its messages, oldest first. Anyone else's session is 404.

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

### Parameters

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

### Responses

- `200` OK (application/json, ChatSessionDetail)
  - `id` (string, required)
  - `title` (string, required): The first question until you rename it
  - `mode` ("chat" | "ask", required): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
  - `model` (string, required): The model asked for: nexus/auto by default
  - `lastModel` (string): The model that ran last
  - `team` (string): The team its spend is attributed to
  - `archived` (boolean, required)
  - `webSearch` (boolean): Whether the model may search the web in this session (default false)
  - `messageCount` (integer, required)
  - `costUsd` (number, required): The sum of its model calls and of the web searches that returned results, settled in the ledger; a search that fails after the provider billed it is in the ledger, not in this sum
  - `createdAt` (string (date-time), required)
  - `updatedAt` (string (date-time), required)
  - `visibility` ("private" | "shared"): Private (the default) or shared: at least one active artifact
  - `sharing` (ChatSessionSharing): How a shared session is shared: its newest active artifact
    - `artifactId` (string, required)
    - `version` (integer, required)
    - `audience` (ArtifactAudience, required): Who may read an artifact, besides its author: inside the organization, the whole organization, chosen teams (their members and the members of the teams under them) or chosen people; outside it, named people by email (`external`) or anyone with the link (`public`). Readers outside the organization see the kind only.
      - `kind` ("org" | "teams" | "people" | "external" | "public", required)
      - `teams` (array of string, required): Team slugs (kind teams)
      - `people` (array of string, required): Members' emails (kind people); the outsiders with access (kind external). Empty for readers outside the organization.
    - `allowContinue` (boolean, required)
    - `url` (string, required): The link to hand out: a public link (kind public), the fast viewer (kind external), else the artifact in Nexus UI; absolute when the Gateway knows Nexus UI's URL (NEXUS_UI_URL), else a path
    - `path` (string, required): /app/<org>/artifacts/<id>
    - `viewerUrl` (string): The fast viewer: <origin>/a/<id>
    - `publicUrl` (string): Kind public: <origin>/a/<token>
    - `expiresAt` (string (date-time)): Kind public: when the link stops opening
  - `artifacts` (array of ArtifactLink): Every version shared from this session, newest first (revoked ones included)
    - `id` (string, required)
    - `version` (integer, required) [min 1]
    - `status` ("active" | "revoked", required)
    - `audience` ("org" | "teams" | "people" | "external" | "public", required)
    - `createdAt` (string (date-time), required)
    - `revokedAt` (string (date-time))
  - `author` (ArtifactAuthor): You (listed and read sessions)
    - `email` (string)
    - `name` (string)
  - `forkedFrom` (object): The artifact this session continues (POST /v1/artifacts/{id}/continue)
    - `artifactId` (string, required)
    - `version` (integer, required)
    - `title` (string)
  - `messages` (array of ChatSessionMessage, required)
    - `id` (string, required)
    - `sessionId` (string, required)
    - `role` ("user" | "assistant", required)
    - `content` (string, required): Markdown (a question with images may have none)
    - `status` ("complete" | "failed" | "refused", required): Refused: the policy or budget refused the call (error says why); failed: it broke mid-way (content is what arrived)
    - `mode` ("chat" | "ask"): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
    - `requestedModel` (string)
    - `model` (string): The model that ran
    - `costUsd` (number)
    - `usage` (object)
      - `promptTokens` (integer)
      - `completionTokens` (integer)
    - `citations` (array of ChatCitation)
      - `n` (integer, required): The number the answer cites it by
      - `repo` (string, required): Owner/name
      - `page` (string, required)
      - `slug` (string, required)
      - `section` (string)
      - `path` (string, required): <slug>#<anchor> in the repository's wiki
      - `files` (array of string): Repository files the section names
      - `runId` (string, required): The Nexus Wiki run that wrote the page
    - `error` (object)
      - `code` (string)
      - `message` (string)
      - `status` (integer)
      - `notified` (boolean): A budget refusal told the organization's owners and admins (licensed build). Absent otherwise.
      - `remainingUsdDecimal` (string): A budget refusal's `remainingUsdDecimal`: what was left of that level's budget, as an exact decimal. Absent when the 402 had none.
      - `requestedUsd` (string): A usage-limit refusal's (`usage_limit_reached`) `requestedUsd`: the most the call may cost with Nexus's rate, as an exact decimal. Absent for any other refusal, or when the 402 had none.
      - `remainingUsd` (string): A usage-limit refusal's (`usage_limit_reached`) `remainingUsd`: what this month's usage limit had left, as an exact decimal. Absent for any other refusal, or when the 402 had none.
      - `details` (object): A 402's details, as the live error's `error.nexus` had them, cut to an allow-list: short codes, ways forward, `notified` and decimal dollar amounts. Absent for any other status, when none was kept, and on an answer stored before it.
        - `reason` (string): Why the refusal happened, such as `authentication_required` or `disputed` for `payment_failed`.
        - `level` (string): A budget refusal's level.
        - `freeStart` (string): `cheaper_models_only` when the free start pays for cheaper models only.
        - `next` (array of string): The ways forward, such as `billing` and `own_key`; at most 4.
        - `notified` (boolean): The organization's owners and admins were told.
        - `owedUsd` (string)
        - `unpaidUsd` (string)
        - `remainingUsd` (string)
        - `remainingUsdDecimal` (string)
        - `requestedUsd` (string)
        - `limitUsd` (string)
        - `chargeUsd` (string)
        - `capUsd` (string)
    - `createdAt` (string (date-time), required)
    - `attachments` (array of ChatAttachmentRef): The images attached to a question
      - `id` (string, required)
      - `type` ("image" | "file", required)
      - `mediaType` ("image/png" | "image/jpeg" | "image/gif" | "image/webp" | "text/csv" | "text/tab-separated-values" | "application/json" | "text/plain" | "text/markdown" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", required): An image's from the bytes, not as it was named; a data file's from its extension, checked against the bytes
      - `bytes` (integer, required)
      - `width` (integer)
      - `height` (integer)
      - `name` (string)
    - `page` (ChatPageBlock): A page this answer created or revised through write_page
      - `pageId` (string, required)
      - `version` (integer, required) [min 1]
      - `title` (string, required)
      - `format` ("html" | "md" | "jsx" | "sheet" | "board", required)
    - `skills` (array of ChatSkillBlock): The skills this answer loaded through load_skill, in the order it loaded them. The file stays in the skills store
      - `skillId` (string, required): Skl_… For a library skill, the library skill's id, which getSkill and getSkillVersion also take
      - `name` (string, required): The name the version had when it was served
      - `version` (integer, required): The version served: a personal skill's latest, or a library skill's latest approved version that nobody withdrew [min 1]
      - `scope` ("personal" | "team" | "org"): Where the skill came from: your own skills, a team's library, or the organization's. Left out on an answer stored before skills had a scope: read it as personal
      - `teamId` (string): The team (team_…), for scope team. Map it to the team's name with listTeams
    - `connectors` (array of ChatConnectorBlock): The connector reads this answer ran through read_connector, in order. What they returned is never kept. In a shared artifact, a reader sees only the reads of connectors they may use
      - `connector` (string, required)
      - `operation` (string, required)
      - `input` (object, required)
      - `account` (object): The connection the read ran with: whose it is and the account's name. Absent while the read streams, and on reads kept before it was recorded
        - `scope` ("org" | "team" | "user", required)
        - `name` (string, required)
    - `sources` (array of ChatWebSource): The web pages this answer's searches gave the model, one per URL, in the order they were found. Only the session's author reads them; a shared artifact keeps none
      - `title` (string, required)
      - `url` (string, required)
      - `date` (string): The page's date as the engine gave it, cut as the model read it
      - `query` (string, required): The first query in the turn that found this page
    - `rewound` (boolean): Retained for the author, but excluded from future model context after a conversation rewind.
- `404` No such session among yours (`chat_session_not_found`): someone else's session answers the same. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such session among yours (`chat_session_not_found`): someone else's session answers the same. |
| 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/chat/sessions/<id>" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Update chat session

`PATCH /v1/chat/sessions/{id}`

Rename, archive or restore a session, or change the model, mode, web search switch or team its next messages use.

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

### Parameters

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

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

- `title` (string) [max length 120]
- `archived` (boolean)
- `model` (string)
- `mode` ("chat" | "ask"): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
- `team` (string | null)
- `webSearch` (boolean): Whether the model may search the web in this chat. It takes effect only while the organization's webSearch.engine is on

### Responses

- `200` OK (application/json, ChatSession)
  - `id` (string, required)
  - `title` (string, required): The first question until you rename it
  - `mode` ("chat" | "ask", required): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
  - `model` (string, required): The model asked for: nexus/auto by default
  - `lastModel` (string): The model that ran last
  - `team` (string): The team its spend is attributed to
  - `archived` (boolean, required)
  - `webSearch` (boolean): Whether the model may search the web in this session (default false)
  - `messageCount` (integer, required)
  - `costUsd` (number, required): The sum of its model calls and of the web searches that returned results, settled in the ledger; a search that fails after the provider billed it is in the ledger, not in this sum
  - `createdAt` (string (date-time), required)
  - `updatedAt` (string (date-time), required)
  - `visibility` ("private" | "shared"): Private (the default) or shared: at least one active artifact
  - `sharing` (ChatSessionSharing): How a shared session is shared: its newest active artifact
    - `artifactId` (string, required)
    - `version` (integer, required)
    - `audience` (ArtifactAudience, required): Who may read an artifact, besides its author: inside the organization, the whole organization, chosen teams (their members and the members of the teams under them) or chosen people; outside it, named people by email (`external`) or anyone with the link (`public`). Readers outside the organization see the kind only.
      - `kind` ("org" | "teams" | "people" | "external" | "public", required)
      - `teams` (array of string, required): Team slugs (kind teams)
      - `people` (array of string, required): Members' emails (kind people); the outsiders with access (kind external). Empty for readers outside the organization.
    - `allowContinue` (boolean, required)
    - `url` (string, required): The link to hand out: a public link (kind public), the fast viewer (kind external), else the artifact in Nexus UI; absolute when the Gateway knows Nexus UI's URL (NEXUS_UI_URL), else a path
    - `path` (string, required): /app/<org>/artifacts/<id>
    - `viewerUrl` (string): The fast viewer: <origin>/a/<id>
    - `publicUrl` (string): Kind public: <origin>/a/<token>
    - `expiresAt` (string (date-time)): Kind public: when the link stops opening
  - `artifacts` (array of ArtifactLink): Every version shared from this session, newest first (revoked ones included)
    - `id` (string, required)
    - `version` (integer, required) [min 1]
    - `status` ("active" | "revoked", required)
    - `audience` ("org" | "teams" | "people" | "external" | "public", required)
    - `createdAt` (string (date-time), required)
    - `revokedAt` (string (date-time))
  - `author` (ArtifactAuthor): You (listed and read sessions)
    - `email` (string)
    - `name` (string)
  - `forkedFrom` (object): The artifact this session continues (POST /v1/artifacts/{id}/continue)
    - `artifactId` (string, required)
    - `version` (integer, required)
    - `title` (string)
- `404` No such session among yours (`chat_session_not_found`): someone else's session answers the same. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such session among yours (`chat_session_not_found`): someone else's session answers the same. |
| 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/chat/sessions/<id>" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "<title>",
    "archived": false,
    "model": "<model>",
    "mode": "chat",
    "team": "platform",
    "webSearch": false
  }'
```

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

## Delete chat session

`DELETE /v1/chat/sessions/{id}`

Delete a session and its messages. Audited as chat.session_deleted (never the content).

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

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The session's id (`chs_…`) |
| `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)
  - `deleted` (boolean)
  - `id` (string)
  - `messages` (integer)
- `404` No such session among yours (`chat_session_not_found`): someone else's session answers the same. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

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

### Example

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

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

## Send chat message

`POST /v1/chat/sessions/{id}/messages`

Send a message; the answer streams as server-sent events (OpenAI chat.completion.chunk; `stream: false` answers with JSON). The call takes the same path as /v1/chat/completions: the model policy decision (nexus/auto by default), the ledger's reserve and settle, attribution to you, your team and chat. Ask your code ranks your organization's Nexus Wiki sections (BM25) and cites them. A refusal is stored in the session and answered before any stream: 403 model_not_allowed (naming the level and rule), 402 budget_exceeded or payment_past_due; error.nexus names the session and the stored message. With an Idempotency-Key a message runs at most once; a finished stream is not replayed (409 idempotency_stream_replay). With `images` a question carries up to 8 images, PNG, JPEG, GIF or WebP by their bytes, at most 5 MB each and 20 MB in all; `content` may then be empty. They go to the model with the question (and with the next ones while they are among the last two questions that had any) and are stored beside it: the message lists them in `attachments`, and getChatAttachment returns their bytes. 400 invalid_image, 413 image_too_large, 400 model_no_image_input for a model that does not read images.

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

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The session's id (`chs_…`) |
| `x-nexus-team` | header | string | no | The team (slug) this message's spend goes to; you must be in it. Default: the session's team. |
| `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)

- `content` (string, required): The question; may be empty when `images` or `files` has at least one [max length 32000]
- `images` (array of ChatImageInput): Images that go with the question. [at most 8 items]
  - `data` (string, required): The image as base64, or a `data:image/…;base64,…` URL
  - `name` (string): Its file name, shown with it [max length 200]
- `files` (array of ChatFileInput): Data files that go with the question: the model reads a text file's text, and a page written in this chat keeps a copy. With the images, at most 20 MB. [at most 8 items]
  - `data` (string, required): Standard base64, or a data: URL
  - `name` (string, required): With its extension. The name a page reads it by [max length 200]
- `model` (string): For this message and the next ones
- `mode` ("chat" | "ask"): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
- `team` (string)
- `stream` (boolean) [default true]

### Responses

- `200` The answer: an event stream, or with stream false the stored question and answer (text/event-stream, ChatStreamChunk)
  - `id` (string)
  - `object` ("chat.completion.chunk")
  - `created` (integer)
  - `model` (string | null): The model that runs
  - `choices` (array of object)
    - `index` (integer)
    - `delta` (object)
      - `role` (string)
      - `content` (string)
    - `finish_reason` (string | null)
  - `usage` (object)
    - `prompt_tokens` (integer)
    - `completion_tokens` (integer)
    - `total_tokens` (integer)
  - `nexus` (object)
    - `session` (ChatSession): A chat session, private to its author unless shared as an artifact.
      - `id` (string, required)
      - `title` (string, required): The first question until you rename it
      - `mode` ("chat" | "ask", required): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
      - `model` (string, required): The model asked for: nexus/auto by default
      - `lastModel` (string): The model that ran last
      - `team` (string): The team its spend is attributed to
      - `archived` (boolean, required)
      - `webSearch` (boolean): Whether the model may search the web in this session (default false)
      - `messageCount` (integer, required)
      - `costUsd` (number, required): The sum of its model calls and of the web searches that returned results, settled in the ledger; a search that fails after the provider billed it is in the ledger, not in this sum
      - `createdAt` (string (date-time), required)
      - `updatedAt` (string (date-time), required)
      - `visibility` ("private" | "shared"): Private (the default) or shared: at least one active artifact
      - `sharing` (ChatSessionSharing): How a shared session is shared: its newest active artifact
        - `artifactId` (string, required)
        - `version` (integer, required)
        - `audience` (ArtifactAudience, required): Who may read an artifact, besides its author: inside the organization, the whole organization, chosen teams (their members and the members of the teams under them) or chosen people; outside it, named people by email (`external`) or anyone with the link (`public`). Readers outside the organization see the kind only.
          - `kind` ("org" | "teams" | "people" | "external" | "public", required)
          - `teams` (array of string, required): Team slugs (kind teams)
          - `people` (array of string, required): Members' emails (kind people); the outsiders with access (kind external). Empty for readers outside the organization.
        - `allowContinue` (boolean, required)
        - `url` (string, required): The link to hand out: a public link (kind public), the fast viewer (kind external), else the artifact in Nexus UI; absolute when the Gateway knows Nexus UI's URL (NEXUS_UI_URL), else a path
        - `path` (string, required): /app/<org>/artifacts/<id>
        - `viewerUrl` (string): The fast viewer: <origin>/a/<id>
        - `publicUrl` (string): Kind public: <origin>/a/<token>
        - `expiresAt` (string (date-time)): Kind public: when the link stops opening
      - `artifacts` (array of ArtifactLink): Every version shared from this session, newest first (revoked ones included)
        - `id` (string, required)
        - `version` (integer, required) [min 1]
        - `status` ("active" | "revoked", required)
        - `audience` ("org" | "teams" | "people" | "external" | "public", required)
        - `createdAt` (string (date-time), required)
        - `revokedAt` (string (date-time))
      - `author` (ArtifactAuthor): You (listed and read sessions)
        - `email` (string)
        - `name` (string)
      - `forkedFrom` (object): The artifact this session continues (POST /v1/artifacts/{id}/continue)
        - `artifactId` (string, required)
        - `version` (integer, required)
        - `title` (string)
    - `question` (ChatSessionMessage)
      - `id` (string, required)
      - `sessionId` (string, required)
      - `role` ("user" | "assistant", required)
      - `content` (string, required): Markdown (a question with images may have none)
      - `status` ("complete" | "failed" | "refused", required): Refused: the policy or budget refused the call (error says why); failed: it broke mid-way (content is what arrived)
      - `mode` ("chat" | "ask"): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
      - `requestedModel` (string)
      - `model` (string): The model that ran
      - `costUsd` (number)
      - `usage` (object)
        - `promptTokens` (integer)
        - `completionTokens` (integer)
      - `citations` (array of ChatCitation)
        - `n` (integer, required): The number the answer cites it by
        - `repo` (string, required): Owner/name
        - `page` (string, required)
        - `slug` (string, required)
        - `section` (string)
        - `path` (string, required): <slug>#<anchor> in the repository's wiki
        - `files` (array of string): Repository files the section names
        - `runId` (string, required): The Nexus Wiki run that wrote the page
      - `error` (object)
        - `code` (string)
        - `message` (string)
        - `status` (integer)
        - `notified` (boolean): A budget refusal told the organization's owners and admins (licensed build). Absent otherwise.
        - `remainingUsdDecimal` (string): A budget refusal's `remainingUsdDecimal`: what was left of that level's budget, as an exact decimal. Absent when the 402 had none.
        - `requestedUsd` (string): A usage-limit refusal's (`usage_limit_reached`) `requestedUsd`: the most the call may cost with Nexus's rate, as an exact decimal. Absent for any other refusal, or when the 402 had none.
        - `remainingUsd` (string): A usage-limit refusal's (`usage_limit_reached`) `remainingUsd`: what this month's usage limit had left, as an exact decimal. Absent for any other refusal, or when the 402 had none.
        - `details` (object): A 402's details, as the live error's `error.nexus` had them, cut to an allow-list: short codes, ways forward, `notified` and decimal dollar amounts. Absent for any other status, when none was kept, and on an answer stored before it.
          - `reason` (string): Why the refusal happened, such as `authentication_required` or `disputed` for `payment_failed`.
          - `level` (string): A budget refusal's level.
          - `freeStart` (string): `cheaper_models_only` when the free start pays for cheaper models only.
          - `next` (array of string): The ways forward, such as `billing` and `own_key`; at most 4.
          - `notified` (boolean): The organization's owners and admins were told.
          - `owedUsd` (string)
          - `unpaidUsd` (string)
          - `remainingUsd` (string)
          - `remainingUsdDecimal` (string)
          - `requestedUsd` (string)
          - `limitUsd` (string)
          - `chargeUsd` (string)
          - `capUsd` (string)
      - `createdAt` (string (date-time), required)
      - `attachments` (array of ChatAttachmentRef): The images attached to a question
        - `id` (string, required)
        - `type` ("image" | "file", required)
        - `mediaType` ("image/png" | "image/jpeg" | "image/gif" | "image/webp" | "text/csv" | "text/tab-separated-values" | "application/json" | "text/plain" | "text/markdown" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", required): An image's from the bytes, not as it was named; a data file's from its extension, checked against the bytes
        - `bytes` (integer, required)
        - `width` (integer)
        - `height` (integer)
        - `name` (string)
      - `page` (ChatPageBlock): A page this answer created or revised through write_page
        - `pageId` (string, required)
        - `version` (integer, required) [min 1]
        - `title` (string, required)
        - `format` ("html" | "md" | "jsx" | "sheet" | "board", required)
      - `skills` (array of ChatSkillBlock): The skills this answer loaded through load_skill, in the order it loaded them. The file stays in the skills store
        - `skillId` (string, required): Skl_… For a library skill, the library skill's id, which getSkill and getSkillVersion also take
        - `name` (string, required): The name the version had when it was served
        - `version` (integer, required): The version served: a personal skill's latest, or a library skill's latest approved version that nobody withdrew [min 1]
        - `scope` ("personal" | "team" | "org"): Where the skill came from: your own skills, a team's library, or the organization's. Left out on an answer stored before skills had a scope: read it as personal
        - `teamId` (string): The team (team_…), for scope team. Map it to the team's name with listTeams
      - `connectors` (array of ChatConnectorBlock): The connector reads this answer ran through read_connector, in order. What they returned is never kept. In a shared artifact, a reader sees only the reads of connectors they may use
        - `connector` (string, required)
        - `operation` (string, required)
        - `input` (object, required)
        - `account` (object): The connection the read ran with: whose it is and the account's name. Absent while the read streams, and on reads kept before it was recorded
          - `scope` ("org" | "team" | "user", required)
          - `name` (string, required)
      - `sources` (array of ChatWebSource): The web pages this answer's searches gave the model, one per URL, in the order they were found. Only the session's author reads them; a shared artifact keeps none
        - `title` (string, required)
        - `url` (string, required)
        - `date` (string): The page's date as the engine gave it, cut as the model read it
        - `query` (string, required): The first query in the turn that found this page
      - `rewound` (boolean): Retained for the author, but excluded from future model context after a conversation rewind.
    - `message` (ChatSessionMessage)
      - `id` (string, required)
      - `sessionId` (string, required)
      - `role` ("user" | "assistant", required)
      - `content` (string, required): Markdown (a question with images may have none)
      - `status` ("complete" | "failed" | "refused", required): Refused: the policy or budget refused the call (error says why); failed: it broke mid-way (content is what arrived)
      - `mode` ("chat" | "ask"): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
      - `requestedModel` (string)
      - `model` (string): The model that ran
      - `costUsd` (number)
      - `usage` (object)
        - `promptTokens` (integer)
        - `completionTokens` (integer)
      - `citations` (array of ChatCitation)
        - `n` (integer, required): The number the answer cites it by
        - `repo` (string, required): Owner/name
        - `page` (string, required)
        - `slug` (string, required)
        - `section` (string)
        - `path` (string, required): <slug>#<anchor> in the repository's wiki
        - `files` (array of string): Repository files the section names
        - `runId` (string, required): The Nexus Wiki run that wrote the page
      - `error` (object)
        - `code` (string)
        - `message` (string)
        - `status` (integer)
        - `notified` (boolean): A budget refusal told the organization's owners and admins (licensed build). Absent otherwise.
        - `remainingUsdDecimal` (string): A budget refusal's `remainingUsdDecimal`: what was left of that level's budget, as an exact decimal. Absent when the 402 had none.
        - `requestedUsd` (string): A usage-limit refusal's (`usage_limit_reached`) `requestedUsd`: the most the call may cost with Nexus's rate, as an exact decimal. Absent for any other refusal, or when the 402 had none.
        - `remainingUsd` (string): A usage-limit refusal's (`usage_limit_reached`) `remainingUsd`: what this month's usage limit had left, as an exact decimal. Absent for any other refusal, or when the 402 had none.
        - `details` (object): A 402's details, as the live error's `error.nexus` had them, cut to an allow-list: short codes, ways forward, `notified` and decimal dollar amounts. Absent for any other status, when none was kept, and on an answer stored before it.
          - `reason` (string): Why the refusal happened, such as `authentication_required` or `disputed` for `payment_failed`.
          - `level` (string): A budget refusal's level.
          - `freeStart` (string): `cheaper_models_only` when the free start pays for cheaper models only.
          - `next` (array of string): The ways forward, such as `billing` and `own_key`; at most 4.
          - `notified` (boolean): The organization's owners and admins were told.
          - `owedUsd` (string)
          - `unpaidUsd` (string)
          - `remainingUsd` (string)
          - `remainingUsdDecimal` (string)
          - `requestedUsd` (string)
          - `limitUsd` (string)
          - `chargeUsd` (string)
          - `capUsd` (string)
      - `createdAt` (string (date-time), required)
      - `attachments` (array of ChatAttachmentRef): The images attached to a question
        - `id` (string, required)
        - `type` ("image" | "file", required)
        - `mediaType` ("image/png" | "image/jpeg" | "image/gif" | "image/webp" | "text/csv" | "text/tab-separated-values" | "application/json" | "text/plain" | "text/markdown" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", required): An image's from the bytes, not as it was named; a data file's from its extension, checked against the bytes
        - `bytes` (integer, required)
        - `width` (integer)
        - `height` (integer)
        - `name` (string)
      - `page` (ChatPageBlock): A page this answer created or revised through write_page
        - `pageId` (string, required)
        - `version` (integer, required) [min 1]
        - `title` (string, required)
        - `format` ("html" | "md" | "jsx" | "sheet" | "board", required)
      - `skills` (array of ChatSkillBlock): The skills this answer loaded through load_skill, in the order it loaded them. The file stays in the skills store
        - `skillId` (string, required): Skl_… For a library skill, the library skill's id, which getSkill and getSkillVersion also take
        - `name` (string, required): The name the version had when it was served
        - `version` (integer, required): The version served: a personal skill's latest, or a library skill's latest approved version that nobody withdrew [min 1]
        - `scope` ("personal" | "team" | "org"): Where the skill came from: your own skills, a team's library, or the organization's. Left out on an answer stored before skills had a scope: read it as personal
        - `teamId` (string): The team (team_…), for scope team. Map it to the team's name with listTeams
      - `connectors` (array of ChatConnectorBlock): The connector reads this answer ran through read_connector, in order. What they returned is never kept. In a shared artifact, a reader sees only the reads of connectors they may use
        - `connector` (string, required)
        - `operation` (string, required)
        - `input` (object, required)
        - `account` (object): The connection the read ran with: whose it is and the account's name. Absent while the read streams, and on reads kept before it was recorded
          - `scope` ("org" | "team" | "user", required)
          - `name` (string, required)
      - `sources` (array of ChatWebSource): The web pages this answer's searches gave the model, one per URL, in the order they were found. Only the session's author reads them; a shared artifact keeps none
        - `title` (string, required)
        - `url` (string, required)
        - `date` (string): The page's date as the engine gave it, cut as the model read it
        - `query` (string, required): The first query in the turn that found this page
      - `rewound` (boolean): Retained for the author, but excluded from future model context after a conversation rewind.
    - `mode` ("chat" | "ask"): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
    - `requested` (string)
    - `citations` (array of ChatCitation)
      - `n` (integer, required): The number the answer cites it by
      - `repo` (string, required): Owner/name
      - `page` (string, required)
      - `slug` (string, required)
      - `section` (string)
      - `path` (string, required): <slug>#<anchor> in the repository's wiki
      - `files` (array of string): Repository files the section names
      - `runId` (string, required): The Nexus Wiki run that wrote the page
    - `no_wiki` (boolean)
    - `tool` (object): A chat tool currently executing
      - `name` ("write_page" | "load_skill" | "describe_connector" | "read_connector" | "web_search", required)
      - `status` ("running", required)
    - `skill` (ChatSkillBlock): A skill load_skill has just read
      - `skillId` (string, required): Skl_… For a library skill, the library skill's id, which getSkill and getSkillVersion also take
      - `name` (string, required): The name the version had when it was served
      - `version` (integer, required): The version served: a personal skill's latest, or a library skill's latest approved version that nobody withdrew [min 1]
      - `scope` ("personal" | "team" | "org"): Where the skill came from: your own skills, a team's library, or the organization's. Left out on an answer stored before skills had a scope: read it as personal
      - `teamId` (string): The team (team_…), for scope team. Map it to the team's name with listTeams
    - `connector` (ChatConnectorBlock): A connector read read_connector is about to run
      - `connector` (string, required)
      - `operation` (string, required)
      - `input` (object, required)
      - `account` (object): The connection the read ran with: whose it is and the account's name. Absent while the read streams, and on reads kept before it was recorded
        - `scope` ("org" | "team" | "user", required)
        - `name` (string, required)
    - `cost_usd` (number)
- `402` The call's maximum cost is more than the budget left (`budget_exceeded`), or the organization has an unpaid Nexus invoice past its grace (`payment_past_due`). The refusal is stored in the session. A `budget_exceeded` refusal carries `notified: true` in its details once Gateway has told the refused person and the organization's owners and admins. The details are a BudgetRefusal: each money figure with its exact decimal twin. (application/json, Error & object)
  - `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.
  - `error` (object)
    - `nexus` (BudgetRefusal): The details (`error.nexus`) of a 402 `budget_exceeded` or `subsidy_exhausted`. Each money figure comes as its number (deprecated) and its exact decimal twin (`requestedUsd`, `requestedUsdDecimal`). A refusal below the person level names only what is left and what was asked, never a limit above the caller. `credit_exhausted` sends `remainingUsd` and `requestedUsd` as decimal strings already, without twins.
      - `level` ("organization" | "team" | "person" | "product"): The level whose limit refused the call (`budget_exceeded`)
      - `period` (string): The period the refusal counted in: `2026-10`, `2026-W44` or `2026-10-21`
      - `resetsAt` (string (date-time)): When the period ends (UTC)
      - `source` ("override" | "default"): Person level only: whether the limit was set for them or is the organization's default per person
      - `limitUsd` (number): Person level only: their monthly limit. Deprecated: read `limitUsdDecimal`, the exact decimal string (root rule 9).
      - `limitUsdDecimal` (string): `limitUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `limitUsd`.
      - `spentUsd` (number): Person level only: what they spent this month. Deprecated: read `spentUsdDecimal`, the exact decimal string (root rule 9).
      - `spentUsdDecimal` (string): `spentUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `spentUsd`.
      - `reservedUsd` (number): Person level only: what their calls in flight hold. Deprecated: read `reservedUsdDecimal`, the exact decimal string (root rule 9).
      - `reservedUsdDecimal` (string): `reservedUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `reservedUsd`.
      - `remainingUsd` (number): Every level, and `subsidy_exhausted`: what is left, never below 0. Deprecated: read `remainingUsdDecimal`, the exact decimal string (root rule 9).
      - `remainingUsdDecimal` (string): `remainingUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `remainingUsd`.
      - `requestedUsd` (number): What the call may cost at most, the amount it asked to hold. Deprecated: read `requestedUsdDecimal`, the exact decimal string (root rule 9).
      - `requestedUsdDecimal` (string): `requestedUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `requestedUsd`.
      - `notified` (boolean): `budget_exceeded`: true once Gateway has told the refused person and the organization's owners and admins
      - `fundedBy` (string): `subsidy_exhausted`: who funds the subsidy (`nexus`)
      - `next` (array of string): `subsidy_exhausted`: what the caller can do next (`billing`, `own_key`)
- `404` No such session among yours (`chat_session_not_found`): someone else's session answers the same. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 402 | `budget_exceeded` | The call's maximum cost is more than the budget left (`budget_exceeded`), or the organization has an unpaid Nexus invoice past its grace (`payment_past_due`). The refusal is stored in the session. A `budget_exceeded` refusal carries `notified: true` in its details once Gateway has told the refused person and the organization's owners and admins. The details are a BudgetRefusal: each money figure with its exact decimal twin. |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such session among yours (`chat_session_not_found`): someone else's session answers the same. |
| 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/chat/sessions/<id>/messages" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "<content>"
  }'
```

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

## Ask code

`POST /v1/chat/ask`

Ask your code alone: a question to your organization's Nexus Wiki, answered and cited as sendChatMessage answers in ask mode. Without `session` it starts an ask-mode session of yours; with one it continues it. It needs `chat.ask`, not `chat.use`, so an agent link that holds it reaches no other chat route. An agent link holds `chat.ask` only when its sign-in asked for it, and it asks as its person: it reads the Wiki pages the person reads and nothing more. An agent link continues only a session it started; any other session is a 404 chat_session_not_found, as someone else's is. Text only: no images, no team, no page or skill tools.

Permission: `chat.ask` (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)

- `content` (string, required): The question [min length 1; max length 32000]
- `session` (string): The ask-mode session to continue (`chs_…`). An agent link continues only a session it started. Omit it to start one. [pattern ^[A-Za-z0-9_-]+$]
- `model` (string): For this question and the next ones in the session
- `stream` (boolean) [default true]

### Responses

- `200` The answer: an event stream, or with stream false the stored question and answer (text/event-stream, ChatStreamChunk)
  - `id` (string)
  - `object` ("chat.completion.chunk")
  - `created` (integer)
  - `model` (string | null): The model that runs
  - `choices` (array of object)
    - `index` (integer)
    - `delta` (object)
      - `role` (string)
      - `content` (string)
    - `finish_reason` (string | null)
  - `usage` (object)
    - `prompt_tokens` (integer)
    - `completion_tokens` (integer)
    - `total_tokens` (integer)
  - `nexus` (object)
    - `session` (ChatSession): A chat session, private to its author unless shared as an artifact.
      - `id` (string, required)
      - `title` (string, required): The first question until you rename it
      - `mode` ("chat" | "ask", required): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
      - `model` (string, required): The model asked for: nexus/auto by default
      - `lastModel` (string): The model that ran last
      - `team` (string): The team its spend is attributed to
      - `archived` (boolean, required)
      - `webSearch` (boolean): Whether the model may search the web in this session (default false)
      - `messageCount` (integer, required)
      - `costUsd` (number, required): The sum of its model calls and of the web searches that returned results, settled in the ledger; a search that fails after the provider billed it is in the ledger, not in this sum
      - `createdAt` (string (date-time), required)
      - `updatedAt` (string (date-time), required)
      - `visibility` ("private" | "shared"): Private (the default) or shared: at least one active artifact
      - `sharing` (ChatSessionSharing): How a shared session is shared: its newest active artifact
        - `artifactId` (string, required)
        - `version` (integer, required)
        - `audience` (ArtifactAudience, required): Who may read an artifact, besides its author: inside the organization, the whole organization, chosen teams (their members and the members of the teams under them) or chosen people; outside it, named people by email (`external`) or anyone with the link (`public`). Readers outside the organization see the kind only.
          - `kind` ("org" | "teams" | "people" | "external" | "public", required)
          - `teams` (array of string, required): Team slugs (kind teams)
          - `people` (array of string, required): Members' emails (kind people); the outsiders with access (kind external). Empty for readers outside the organization.
        - `allowContinue` (boolean, required)
        - `url` (string, required): The link to hand out: a public link (kind public), the fast viewer (kind external), else the artifact in Nexus UI; absolute when the Gateway knows Nexus UI's URL (NEXUS_UI_URL), else a path
        - `path` (string, required): /app/<org>/artifacts/<id>
        - `viewerUrl` (string): The fast viewer: <origin>/a/<id>
        - `publicUrl` (string): Kind public: <origin>/a/<token>
        - `expiresAt` (string (date-time)): Kind public: when the link stops opening
      - `artifacts` (array of ArtifactLink): Every version shared from this session, newest first (revoked ones included)
        - `id` (string, required)
        - `version` (integer, required) [min 1]
        - `status` ("active" | "revoked", required)
        - `audience` ("org" | "teams" | "people" | "external" | "public", required)
        - `createdAt` (string (date-time), required)
        - `revokedAt` (string (date-time))
      - `author` (ArtifactAuthor): You (listed and read sessions)
        - `email` (string)
        - `name` (string)
      - `forkedFrom` (object): The artifact this session continues (POST /v1/artifacts/{id}/continue)
        - `artifactId` (string, required)
        - `version` (integer, required)
        - `title` (string)
    - `question` (ChatSessionMessage)
      - `id` (string, required)
      - `sessionId` (string, required)
      - `role` ("user" | "assistant", required)
      - `content` (string, required): Markdown (a question with images may have none)
      - `status` ("complete" | "failed" | "refused", required): Refused: the policy or budget refused the call (error says why); failed: it broke mid-way (content is what arrived)
      - `mode` ("chat" | "ask"): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
      - `requestedModel` (string)
      - `model` (string): The model that ran
      - `costUsd` (number)
      - `usage` (object)
        - `promptTokens` (integer)
        - `completionTokens` (integer)
      - `citations` (array of ChatCitation)
        - `n` (integer, required): The number the answer cites it by
        - `repo` (string, required): Owner/name
        - `page` (string, required)
        - `slug` (string, required)
        - `section` (string)
        - `path` (string, required): <slug>#<anchor> in the repository's wiki
        - `files` (array of string): Repository files the section names
        - `runId` (string, required): The Nexus Wiki run that wrote the page
      - `error` (object)
        - `code` (string)
        - `message` (string)
        - `status` (integer)
        - `notified` (boolean): A budget refusal told the organization's owners and admins (licensed build). Absent otherwise.
        - `remainingUsdDecimal` (string): A budget refusal's `remainingUsdDecimal`: what was left of that level's budget, as an exact decimal. Absent when the 402 had none.
        - `requestedUsd` (string): A usage-limit refusal's (`usage_limit_reached`) `requestedUsd`: the most the call may cost with Nexus's rate, as an exact decimal. Absent for any other refusal, or when the 402 had none.
        - `remainingUsd` (string): A usage-limit refusal's (`usage_limit_reached`) `remainingUsd`: what this month's usage limit had left, as an exact decimal. Absent for any other refusal, or when the 402 had none.
        - `details` (object): A 402's details, as the live error's `error.nexus` had them, cut to an allow-list: short codes, ways forward, `notified` and decimal dollar amounts. Absent for any other status, when none was kept, and on an answer stored before it.
          - `reason` (string): Why the refusal happened, such as `authentication_required` or `disputed` for `payment_failed`.
          - `level` (string): A budget refusal's level.
          - `freeStart` (string): `cheaper_models_only` when the free start pays for cheaper models only.
          - `next` (array of string): The ways forward, such as `billing` and `own_key`; at most 4.
          - `notified` (boolean): The organization's owners and admins were told.
          - `owedUsd` (string)
          - `unpaidUsd` (string)
          - `remainingUsd` (string)
          - `remainingUsdDecimal` (string)
          - `requestedUsd` (string)
          - `limitUsd` (string)
          - `chargeUsd` (string)
          - `capUsd` (string)
      - `createdAt` (string (date-time), required)
      - `attachments` (array of ChatAttachmentRef): The images attached to a question
        - `id` (string, required)
        - `type` ("image" | "file", required)
        - `mediaType` ("image/png" | "image/jpeg" | "image/gif" | "image/webp" | "text/csv" | "text/tab-separated-values" | "application/json" | "text/plain" | "text/markdown" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", required): An image's from the bytes, not as it was named; a data file's from its extension, checked against the bytes
        - `bytes` (integer, required)
        - `width` (integer)
        - `height` (integer)
        - `name` (string)
      - `page` (ChatPageBlock): A page this answer created or revised through write_page
        - `pageId` (string, required)
        - `version` (integer, required) [min 1]
        - `title` (string, required)
        - `format` ("html" | "md" | "jsx" | "sheet" | "board", required)
      - `skills` (array of ChatSkillBlock): The skills this answer loaded through load_skill, in the order it loaded them. The file stays in the skills store
        - `skillId` (string, required): Skl_… For a library skill, the library skill's id, which getSkill and getSkillVersion also take
        - `name` (string, required): The name the version had when it was served
        - `version` (integer, required): The version served: a personal skill's latest, or a library skill's latest approved version that nobody withdrew [min 1]
        - `scope` ("personal" | "team" | "org"): Where the skill came from: your own skills, a team's library, or the organization's. Left out on an answer stored before skills had a scope: read it as personal
        - `teamId` (string): The team (team_…), for scope team. Map it to the team's name with listTeams
      - `connectors` (array of ChatConnectorBlock): The connector reads this answer ran through read_connector, in order. What they returned is never kept. In a shared artifact, a reader sees only the reads of connectors they may use
        - `connector` (string, required)
        - `operation` (string, required)
        - `input` (object, required)
        - `account` (object): The connection the read ran with: whose it is and the account's name. Absent while the read streams, and on reads kept before it was recorded
          - `scope` ("org" | "team" | "user", required)
          - `name` (string, required)
      - `sources` (array of ChatWebSource): The web pages this answer's searches gave the model, one per URL, in the order they were found. Only the session's author reads them; a shared artifact keeps none
        - `title` (string, required)
        - `url` (string, required)
        - `date` (string): The page's date as the engine gave it, cut as the model read it
        - `query` (string, required): The first query in the turn that found this page
      - `rewound` (boolean): Retained for the author, but excluded from future model context after a conversation rewind.
    - `message` (ChatSessionMessage)
      - `id` (string, required)
      - `sessionId` (string, required)
      - `role` ("user" | "assistant", required)
      - `content` (string, required): Markdown (a question with images may have none)
      - `status` ("complete" | "failed" | "refused", required): Refused: the policy or budget refused the call (error says why); failed: it broke mid-way (content is what arrived)
      - `mode` ("chat" | "ask"): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
      - `requestedModel` (string)
      - `model` (string): The model that ran
      - `costUsd` (number)
      - `usage` (object)
        - `promptTokens` (integer)
        - `completionTokens` (integer)
      - `citations` (array of ChatCitation)
        - `n` (integer, required): The number the answer cites it by
        - `repo` (string, required): Owner/name
        - `page` (string, required)
        - `slug` (string, required)
        - `section` (string)
        - `path` (string, required): <slug>#<anchor> in the repository's wiki
        - `files` (array of string): Repository files the section names
        - `runId` (string, required): The Nexus Wiki run that wrote the page
      - `error` (object)
        - `code` (string)
        - `message` (string)
        - `status` (integer)
        - `notified` (boolean): A budget refusal told the organization's owners and admins (licensed build). Absent otherwise.
        - `remainingUsdDecimal` (string): A budget refusal's `remainingUsdDecimal`: what was left of that level's budget, as an exact decimal. Absent when the 402 had none.
        - `requestedUsd` (string): A usage-limit refusal's (`usage_limit_reached`) `requestedUsd`: the most the call may cost with Nexus's rate, as an exact decimal. Absent for any other refusal, or when the 402 had none.
        - `remainingUsd` (string): A usage-limit refusal's (`usage_limit_reached`) `remainingUsd`: what this month's usage limit had left, as an exact decimal. Absent for any other refusal, or when the 402 had none.
        - `details` (object): A 402's details, as the live error's `error.nexus` had them, cut to an allow-list: short codes, ways forward, `notified` and decimal dollar amounts. Absent for any other status, when none was kept, and on an answer stored before it.
          - `reason` (string): Why the refusal happened, such as `authentication_required` or `disputed` for `payment_failed`.
          - `level` (string): A budget refusal's level.
          - `freeStart` (string): `cheaper_models_only` when the free start pays for cheaper models only.
          - `next` (array of string): The ways forward, such as `billing` and `own_key`; at most 4.
          - `notified` (boolean): The organization's owners and admins were told.
          - `owedUsd` (string)
          - `unpaidUsd` (string)
          - `remainingUsd` (string)
          - `remainingUsdDecimal` (string)
          - `requestedUsd` (string)
          - `limitUsd` (string)
          - `chargeUsd` (string)
          - `capUsd` (string)
      - `createdAt` (string (date-time), required)
      - `attachments` (array of ChatAttachmentRef): The images attached to a question
        - `id` (string, required)
        - `type` ("image" | "file", required)
        - `mediaType` ("image/png" | "image/jpeg" | "image/gif" | "image/webp" | "text/csv" | "text/tab-separated-values" | "application/json" | "text/plain" | "text/markdown" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", required): An image's from the bytes, not as it was named; a data file's from its extension, checked against the bytes
        - `bytes` (integer, required)
        - `width` (integer)
        - `height` (integer)
        - `name` (string)
      - `page` (ChatPageBlock): A page this answer created or revised through write_page
        - `pageId` (string, required)
        - `version` (integer, required) [min 1]
        - `title` (string, required)
        - `format` ("html" | "md" | "jsx" | "sheet" | "board", required)
      - `skills` (array of ChatSkillBlock): The skills this answer loaded through load_skill, in the order it loaded them. The file stays in the skills store
        - `skillId` (string, required): Skl_… For a library skill, the library skill's id, which getSkill and getSkillVersion also take
        - `name` (string, required): The name the version had when it was served
        - `version` (integer, required): The version served: a personal skill's latest, or a library skill's latest approved version that nobody withdrew [min 1]
        - `scope` ("personal" | "team" | "org"): Where the skill came from: your own skills, a team's library, or the organization's. Left out on an answer stored before skills had a scope: read it as personal
        - `teamId` (string): The team (team_…), for scope team. Map it to the team's name with listTeams
      - `connectors` (array of ChatConnectorBlock): The connector reads this answer ran through read_connector, in order. What they returned is never kept. In a shared artifact, a reader sees only the reads of connectors they may use
        - `connector` (string, required)
        - `operation` (string, required)
        - `input` (object, required)
        - `account` (object): The connection the read ran with: whose it is and the account's name. Absent while the read streams, and on reads kept before it was recorded
          - `scope` ("org" | "team" | "user", required)
          - `name` (string, required)
      - `sources` (array of ChatWebSource): The web pages this answer's searches gave the model, one per URL, in the order they were found. Only the session's author reads them; a shared artifact keeps none
        - `title` (string, required)
        - `url` (string, required)
        - `date` (string): The page's date as the engine gave it, cut as the model read it
        - `query` (string, required): The first query in the turn that found this page
      - `rewound` (boolean): Retained for the author, but excluded from future model context after a conversation rewind.
    - `mode` ("chat" | "ask"): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
    - `requested` (string)
    - `citations` (array of ChatCitation)
      - `n` (integer, required): The number the answer cites it by
      - `repo` (string, required): Owner/name
      - `page` (string, required)
      - `slug` (string, required)
      - `section` (string)
      - `path` (string, required): <slug>#<anchor> in the repository's wiki
      - `files` (array of string): Repository files the section names
      - `runId` (string, required): The Nexus Wiki run that wrote the page
    - `no_wiki` (boolean)
    - `tool` (object): A chat tool currently executing
      - `name` ("write_page" | "load_skill" | "describe_connector" | "read_connector" | "web_search", required)
      - `status` ("running", required)
    - `skill` (ChatSkillBlock): A skill load_skill has just read
      - `skillId` (string, required): Skl_… For a library skill, the library skill's id, which getSkill and getSkillVersion also take
      - `name` (string, required): The name the version had when it was served
      - `version` (integer, required): The version served: a personal skill's latest, or a library skill's latest approved version that nobody withdrew [min 1]
      - `scope` ("personal" | "team" | "org"): Where the skill came from: your own skills, a team's library, or the organization's. Left out on an answer stored before skills had a scope: read it as personal
      - `teamId` (string): The team (team_…), for scope team. Map it to the team's name with listTeams
    - `connector` (ChatConnectorBlock): A connector read read_connector is about to run
      - `connector` (string, required)
      - `operation` (string, required)
      - `input` (object, required)
      - `account` (object): The connection the read ran with: whose it is and the account's name. Absent while the read streams, and on reads kept before it was recorded
        - `scope` ("org" | "team" | "user", required)
        - `name` (string, required)
    - `cost_usd` (number)
- `402` The call's maximum cost is more than the budget left (`budget_exceeded`), or the organization has an unpaid Nexus invoice past its grace (`payment_past_due`). The refusal is stored in the session. A `budget_exceeded` refusal carries `notified: true` in its details once Gateway has told the refused person and the organization's owners and admins. The details are a BudgetRefusal: each money figure with its exact decimal twin. (application/json, Error & object)
  - `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.
  - `error` (object)
    - `nexus` (BudgetRefusal): The details (`error.nexus`) of a 402 `budget_exceeded` or `subsidy_exhausted`. Each money figure comes as its number (deprecated) and its exact decimal twin (`requestedUsd`, `requestedUsdDecimal`). A refusal below the person level names only what is left and what was asked, never a limit above the caller. `credit_exhausted` sends `remainingUsd` and `requestedUsd` as decimal strings already, without twins.
      - `level` ("organization" | "team" | "person" | "product"): The level whose limit refused the call (`budget_exceeded`)
      - `period` (string): The period the refusal counted in: `2026-10`, `2026-W44` or `2026-10-21`
      - `resetsAt` (string (date-time)): When the period ends (UTC)
      - `source` ("override" | "default"): Person level only: whether the limit was set for them or is the organization's default per person
      - `limitUsd` (number): Person level only: their monthly limit. Deprecated: read `limitUsdDecimal`, the exact decimal string (root rule 9).
      - `limitUsdDecimal` (string): `limitUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `limitUsd`.
      - `spentUsd` (number): Person level only: what they spent this month. Deprecated: read `spentUsdDecimal`, the exact decimal string (root rule 9).
      - `spentUsdDecimal` (string): `spentUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `spentUsd`.
      - `reservedUsd` (number): Person level only: what their calls in flight hold. Deprecated: read `reservedUsdDecimal`, the exact decimal string (root rule 9).
      - `reservedUsdDecimal` (string): `reservedUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `reservedUsd`.
      - `remainingUsd` (number): Every level, and `subsidy_exhausted`: what is left, never below 0. Deprecated: read `remainingUsdDecimal`, the exact decimal string (root rule 9).
      - `remainingUsdDecimal` (string): `remainingUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `remainingUsd`.
      - `requestedUsd` (number): What the call may cost at most, the amount it asked to hold. Deprecated: read `requestedUsdDecimal`, the exact decimal string (root rule 9).
      - `requestedUsdDecimal` (string): `requestedUsd` as an exact decimal string in US dollars with six decimals (`"12.245000"`), from the micro-dollars. Prefer it to `requestedUsd`.
      - `notified` (boolean): `budget_exceeded`: true once Gateway has told the refused person and the organization's owners and admins
      - `fundedBy` (string): `subsidy_exhausted`: who funds the subsidy (`nexus`)
      - `next` (array of string): `subsidy_exhausted`: what the caller can do next (`billing`, `own_key`)
- `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 |
| 402 | `budget_exceeded` | The call's maximum cost is more than the budget left (`budget_exceeded`), or the organization has an unpaid Nexus invoice past its grace (`payment_past_due`). The refusal is stored in the session. A `budget_exceeded` refusal carries `notified: true` in its details once Gateway has told the refused person and the organization's owners and admins. The details are a BudgetRefusal: each money figure with its exact decimal twin. |
| 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/chat/ask" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "<content>"
  }'
```

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

## Ask web

`POST /v1/chat/web`

Web search alone: a text question answered with your organization's web search, as sendChatMessage answers in a chat with webSearch on. Without `session` it starts a chat session of yours with webSearch on; with one it continues it. The turn offers the web_search tool and no other: no page, skill or connector tool. The organization's webSearch.* settings apply, maxPerTurn included. While search is off it is a 403 web_search_off, and while webSearch.requireZdr or a domain rule is set a 403 web_search_unenforced; both name the setting in error.nexus.setting, and no session is made. It needs `chat.web`, not `chat.use`, so an agent link that holds it reaches no other chat route. An agent link holds `chat.web` only when its sign-in asked for it, and it searches as its person, on its person's budget. An agent link continues only a session it started; any other session is a 404 chat_session_not_found, as someone else's is. Text only: no images and no team. When no model the policy allows can search, the answer comes without a search and `sources` is absent.

Permission: `chat.web` (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)

- `content` (string, required): The question [min length 1; max length 32000]
- `session` (string): The web session to continue (`chs_…`): a chat session with webSearch on. An agent link continues only a session it started. Omit it to start one. [pattern ^[A-Za-z0-9_-]+$]
- `model` (string): For this question and the next ones in the session
- `stream` (boolean) [default true]

### Responses

- `200` The answer: an event stream, or with stream false the stored question and answer, with the answer's sources (text/event-stream, ChatStreamChunk)
  - `id` (string)
  - `object` ("chat.completion.chunk")
  - `created` (integer)
  - `model` (string | null): The model that runs
  - `choices` (array of object)
    - `index` (integer)
    - `delta` (object)
      - `role` (string)
      - `content` (string)
    - `finish_reason` (string | null)
  - `usage` (object)
    - `prompt_tokens` (integer)
    - `completion_tokens` (integer)
    - `total_tokens` (integer)
  - `nexus` (object)
    - `session` (ChatSession): A chat session, private to its author unless shared as an artifact.
      - `id` (string, required)
      - `title` (string, required): The first question until you rename it
      - `mode` ("chat" | "ask", required): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
      - `model` (string, required): The model asked for: nexus/auto by default
      - `lastModel` (string): The model that ran last
      - `team` (string): The team its spend is attributed to
      - `archived` (boolean, required)
      - `webSearch` (boolean): Whether the model may search the web in this session (default false)
      - `messageCount` (integer, required)
      - `costUsd` (number, required): The sum of its model calls and of the web searches that returned results, settled in the ledger; a search that fails after the provider billed it is in the ledger, not in this sum
      - `createdAt` (string (date-time), required)
      - `updatedAt` (string (date-time), required)
      - `visibility` ("private" | "shared"): Private (the default) or shared: at least one active artifact
      - `sharing` (ChatSessionSharing): How a shared session is shared: its newest active artifact
        - `artifactId` (string, required)
        - `version` (integer, required)
        - `audience` (ArtifactAudience, required): Who may read an artifact, besides its author: inside the organization, the whole organization, chosen teams (their members and the members of the teams under them) or chosen people; outside it, named people by email (`external`) or anyone with the link (`public`). Readers outside the organization see the kind only.
          - `kind` ("org" | "teams" | "people" | "external" | "public", required)
          - `teams` (array of string, required): Team slugs (kind teams)
          - `people` (array of string, required): Members' emails (kind people); the outsiders with access (kind external). Empty for readers outside the organization.
        - `allowContinue` (boolean, required)
        - `url` (string, required): The link to hand out: a public link (kind public), the fast viewer (kind external), else the artifact in Nexus UI; absolute when the Gateway knows Nexus UI's URL (NEXUS_UI_URL), else a path
        - `path` (string, required): /app/<org>/artifacts/<id>
        - `viewerUrl` (string): The fast viewer: <origin>/a/<id>
        - `publicUrl` (string): Kind public: <origin>/a/<token>
        - `expiresAt` (string (date-time)): Kind public: when the link stops opening
      - `artifacts` (array of ArtifactLink): Every version shared from this session, newest first (revoked ones included)
        - `id` (string, required)
        - `version` (integer, required) [min 1]
        - `status` ("active" | "revoked", required)
        - `audience` ("org" | "teams" | "people" | "external" | "public", required)
        - `createdAt` (string (date-time), required)
        - `revokedAt` (string (date-time))
      - `author` (ArtifactAuthor): You (listed and read sessions)
        - `email` (string)
        - `name` (string)
      - `forkedFrom` (object): The artifact this session continues (POST /v1/artifacts/{id}/continue)
        - `artifactId` (string, required)
        - `version` (integer, required)
        - `title` (string)
    - `question` (ChatSessionMessage)
      - `id` (string, required)
      - `sessionId` (string, required)
      - `role` ("user" | "assistant", required)
      - `content` (string, required): Markdown (a question with images may have none)
      - `status` ("complete" | "failed" | "refused", required): Refused: the policy or budget refused the call (error says why); failed: it broke mid-way (content is what arrived)
      - `mode` ("chat" | "ask"): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
      - `requestedModel` (string)
      - `model` (string): The model that ran
      - `costUsd` (number)
      - `usage` (object)
        - `promptTokens` (integer)
        - `completionTokens` (integer)
      - `citations` (array of ChatCitation)
        - `n` (integer, required): The number the answer cites it by
        - `repo` (string, required): Owner/name
        - `page` (string, required)
        - `slug` (string, required)
        - `section` (string)
        - `path` (string, required): <slug>#<anchor> in the repository's wiki
        - `files` (array of string): Repository files the section names
        - `runId` (string, required): The Nexus Wiki run that wrote the page
      - `error` (object)
        - `code` (string)
        - `message` (string)
        - `status` (integer)
        - `notified` (boolean): A budget refusal told the organization's owners and admins (licensed build). Absent otherwise.
        - `remainingUsdDecimal` (string): A budget refusal's `remainingUsdDecimal`: what was left of that level's budget, as an exact decimal. Absent when the 402 had none.
        - `requestedUsd` (string): A usage-limit refusal's (`usage_limit_reached`) `requestedUsd`: the most the call may cost with Nexus's rate, as an exact decimal. Absent for any other refusal, or when the 402 had none.
        - `remainingUsd` (string): A usage-limit refusal's (`usage_limit_reached`) `remainingUsd`: what this month's usage limit had left, as an exact decimal. Absent for any other refusal, or when the 402 had none.
        - `details` (object): A 402's details, as the live error's `error.nexus` had them, cut to an allow-list: short codes, ways forward, `notified` and decimal dollar amounts. Absent for any other status, when none was kept, and on an answer stored before it.
          - `reason` (string): Why the refusal happened, such as `authentication_required` or `disputed` for `payment_failed`.
          - `level` (string): A budget refusal's level.
          - `freeStart` (string): `cheaper_models_only` when the free start pays for cheaper models only.
          - `next` (array of string): The ways forward, such as `billing` and `own_key`; at most 4.
          - `notified` (boolean): The organization's owners and admins were told.
          - `owedUsd` (string)
          - `unpaidUsd` (string)
          - `remainingUsd` (string)
          - `remainingUsdDecimal` (string)
          - `requestedUsd` (string)
          - `limitUsd` (string)
          - `chargeUsd` (string)
          - `capUsd` (string)
      - `createdAt` (string (date-time), required)
      - `attachments` (array of ChatAttachmentRef): The images attached to a question
        - `id` (string, required)
        - `type` ("image" | "file", required)
        - `mediaType` ("image/png" | "image/jpeg" | "image/gif" | "image/webp" | "text/csv" | "text/tab-separated-values" | "application/json" | "text/plain" | "text/markdown" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", required): An image's from the bytes, not as it was named; a data file's from its extension, checked against the bytes
        - `bytes` (integer, required)
        - `width` (integer)
        - `height` (integer)
        - `name` (string)
      - `page` (ChatPageBlock): A page this answer created or revised through write_page
        - `pageId` (string, required)
        - `version` (integer, required) [min 1]
        - `title` (string, required)
        - `format` ("html" | "md" | "jsx" | "sheet" | "board", required)
      - `skills` (array of ChatSkillBlock): The skills this answer loaded through load_skill, in the order it loaded them. The file stays in the skills store
        - `skillId` (string, required): Skl_… For a library skill, the library skill's id, which getSkill and getSkillVersion also take
        - `name` (string, required): The name the version had when it was served
        - `version` (integer, required): The version served: a personal skill's latest, or a library skill's latest approved version that nobody withdrew [min 1]
        - `scope` ("personal" | "team" | "org"): Where the skill came from: your own skills, a team's library, or the organization's. Left out on an answer stored before skills had a scope: read it as personal
        - `teamId` (string): The team (team_…), for scope team. Map it to the team's name with listTeams
      - `connectors` (array of ChatConnectorBlock): The connector reads this answer ran through read_connector, in order. What they returned is never kept. In a shared artifact, a reader sees only the reads of connectors they may use
        - `connector` (string, required)
        - `operation` (string, required)
        - `input` (object, required)
        - `account` (object): The connection the read ran with: whose it is and the account's name. Absent while the read streams, and on reads kept before it was recorded
          - `scope` ("org" | "team" | "user", required)
          - `name` (string, required)
      - `sources` (array of ChatWebSource): The web pages this answer's searches gave the model, one per URL, in the order they were found. Only the session's author reads them; a shared artifact keeps none
        - `title` (string, required)
        - `url` (string, required)
        - `date` (string): The page's date as the engine gave it, cut as the model read it
        - `query` (string, required): The first query in the turn that found this page
      - `rewound` (boolean): Retained for the author, but excluded from future model context after a conversation rewind.
    - `message` (ChatSessionMessage)
      - `id` (string, required)
      - `sessionId` (string, required)
      - `role` ("user" | "assistant", required)
      - `content` (string, required): Markdown (a question with images may have none)
      - `status` ("complete" | "failed" | "refused", required): Refused: the policy or budget refused the call (error says why); failed: it broke mid-way (content is what arrived)
      - `mode` ("chat" | "ask"): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
      - `requestedModel` (string)
      - `model` (string): The model that ran
      - `costUsd` (number)
      - `usage` (object)
        - `promptTokens` (integer)
        - `completionTokens` (integer)
      - `citations` (array of ChatCitation)
        - `n` (integer, required): The number the answer cites it by
        - `repo` (string, required): Owner/name
        - `page` (string, required)
        - `slug` (string, required)
        - `section` (string)
        - `path` (string, required): <slug>#<anchor> in the repository's wiki
        - `files` (array of string): Repository files the section names
        - `runId` (string, required): The Nexus Wiki run that wrote the page
      - `error` (object)
        - `code` (string)
        - `message` (string)
        - `status` (integer)
        - `notified` (boolean): A budget refusal told the organization's owners and admins (licensed build). Absent otherwise.
        - `remainingUsdDecimal` (string): A budget refusal's `remainingUsdDecimal`: what was left of that level's budget, as an exact decimal. Absent when the 402 had none.
        - `requestedUsd` (string): A usage-limit refusal's (`usage_limit_reached`) `requestedUsd`: the most the call may cost with Nexus's rate, as an exact decimal. Absent for any other refusal, or when the 402 had none.
        - `remainingUsd` (string): A usage-limit refusal's (`usage_limit_reached`) `remainingUsd`: what this month's usage limit had left, as an exact decimal. Absent for any other refusal, or when the 402 had none.
        - `details` (object): A 402's details, as the live error's `error.nexus` had them, cut to an allow-list: short codes, ways forward, `notified` and decimal dollar amounts. Absent for any other status, when none was kept, and on an answer stored before it.
          - `reason` (string): Why the refusal happened, such as `authentication_required` or `disputed` for `payment_failed`.
          - `level` (string): A budget refusal's level.
          - `freeStart` (string): `cheaper_models_only` when the free start pays for cheaper models only.
          - `next` (array of string): The ways forward, such as `billing` and `own_key`; at most 4.
          - `notified` (boolean): The organization's owners and admins were told.
          - `owedUsd` (string)
          - `unpaidUsd` (string)
          - `remainingUsd` (string)
          - `remainingUsdDecimal` (string)
          - `requestedUsd` (string)
          - `limitUsd` (string)
          - `chargeUsd` (string)
          - `capUsd` (string)
      - `createdAt` (string (date-time), required)
      - `attachments` (array of ChatAttachmentRef): The images attached to a question
        - `id` (string, required)
        - `type` ("image" | "file", required)
        - `mediaType` ("image/png" | "image/jpeg" | "image/gif" | "image/webp" | "text/csv" | "text/tab-separated-values" | "application/json" | "text/plain" | "text/markdown" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", required): An image's from the bytes, not as it was named; a data file's from its extension, checked against the bytes
        - `bytes` (integer, required)
        - `width` (integer)
        - `height` (integer)
        - `name` (string)
      - `page` (ChatPageBlock): A page this answer created or revised through write_page
        - `pageId` (string, required)
        - `version` (integer, required) [min 1]
        - `title` (string, required)
        - `format` ("html" | "md" | "jsx" | "sheet" | "board", required)
      - `skills` (array of ChatSkillBlock): The skills this answer loaded through load_skill, in the order it loaded them. The file stays in the skills store
        - `skillId` (string, required): Skl_… For a library skill, the library skill's id, which getSkill and getSkillVersion also take
        - `name` (string, required): The name the version had when it was served
        - `version` (integer, required): The version served: a personal skill's latest, or a library skill's latest approved version that nobody withdrew [min 1]
        - `scope` ("personal" | "team" | "org"): Where the skill came from: your own skills, a team's library, or the organization's. Left out on an answer stored before skills had a scope: read it as personal
        - `teamId` (string): The team (team_…), for scope team. Map it to the team's name with listTeams
      - `connectors` (array of ChatConnectorBlock): The connector reads this answer ran through read_connector, in order. What they returned is never kept. In a shared artifact, a reader sees only the reads of connectors they may use
        - `connector` (string, required)
        - `operation` (string, required)
        - `input` (object, required)
        - `account` (object): The connection the read ran with: whose it is and the account's name. Absent while the read streams, and on reads kept before it was recorded
          - `scope` ("org" | "team" | "user", required)
          - `name` (string, required)
      - `sources` (array of ChatWebSource): The web pages this answer's searches gave the model, one per URL, in the order they were found. Only the session's author reads them; a shared artifact keeps none
        - `title` (string, required)
        - `url` (string, required)
        - `date` (string): The page's date as the engine gave it, cut as the model read it
        - `query` (string, required): The first query in the turn that found this page
      - `rewound` (boolean): Retained for the author, but excluded from future model context after a conversation rewind.
    - `mode` ("chat" | "ask"): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
    - `requested` (string)
    - `citations` (array of ChatCitation)
      - `n` (integer, required): The number the answer cites it by
      - `repo` (string, required): Owner/name
      - `page` (string, required)
      - `slug` (string, required)
      - `section` (string)
      - `path` (string, required): <slug>#<anchor> in the repository's wiki
      - `files` (array of string): Repository files the section names
      - `runId` (string, required): The Nexus Wiki run that wrote the page
    - `no_wiki` (boolean)
    - `tool` (object): A chat tool currently executing
      - `name` ("write_page" | "load_skill" | "describe_connector" | "read_connector" | "web_search", required)
      - `status` ("running", required)
    - `skill` (ChatSkillBlock): A skill load_skill has just read
      - `skillId` (string, required): Skl_… For a library skill, the library skill's id, which getSkill and getSkillVersion also take
      - `name` (string, required): The name the version had when it was served
      - `version` (integer, required): The version served: a personal skill's latest, or a library skill's latest approved version that nobody withdrew [min 1]
      - `scope` ("personal" | "team" | "org"): Where the skill came from: your own skills, a team's library, or the organization's. Left out on an answer stored before skills had a scope: read it as personal
      - `teamId` (string): The team (team_…), for scope team. Map it to the team's name with listTeams
    - `connector` (ChatConnectorBlock): A connector read read_connector is about to run
      - `connector` (string, required)
      - `operation` (string, required)
      - `input` (object, required)
      - `account` (object): The connection the read ran with: whose it is and the account's name. Absent while the read streams, and on reads kept before it was recorded
        - `scope` ("org" | "team" | "user", required)
        - `name` (string, required)
    - `cost_usd` (number)
- `402` The call's maximum cost is more than the budget left (`budget_exceeded`), or the organization has an unpaid Nexus invoice past its grace (`payment_past_due`). The refusal is stored in the session. A `budget_exceeded` refusal carries `notified: true` in its details once Gateway has told the refused person and the organization's owners and admins. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 402 | `budget_exceeded` | The call's maximum cost is more than the budget left (`budget_exceeded`), or the organization has an unpaid Nexus invoice past its grace (`payment_past_due`). The refusal is stored in the session. A `budget_exceeded` refusal carries `notified: true` in its details once Gateway has told the refused person and the organization's owners and admins. |
| 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/chat/web" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "<content>"
  }'
```

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

## Get chat attachment

`GET /v1/chat/sessions/{id}/attachments/{attachmentId}`

An image attached to a question in one of your sessions, with its bytes as base64 (`data:<mediaType>;base64,<data>` shows it). Someone else's session, or an image not in it, is a 404 (chat_session_not_found, chat_attachment_not_found).

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

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The session's id (`chs_…`) |
| `attachmentId` | path | string | yes | The image's id (`cha_…`), from the message's `attachments` |

### Responses

- `200` The image (application/json, ChatAttachment)
  - `id` (string, required)
  - `sessionId` (string, required)
  - `messageId` (string, required)
  - `mediaType` ("image/png" | "image/jpeg" | "image/gif" | "image/webp" | "text/csv" | "text/tab-separated-values" | "application/json" | "text/plain" | "text/markdown" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", required)
  - `bytes` (integer, required)
  - `width` (integer)
  - `height` (integer)
  - `name` (string)
  - `data` (string, required): Standard base64
  - `createdAt` (string (date-time), required)
- `404` No such session among yours (`chat_session_not_found`), or no such image in it (`chat_attachment_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.

### 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 session among yours (`chat_session_not_found`), or no such image in it (`chat_attachment_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 |

### Example

```sh
curl "$NEXUS_URL/v1/chat/sessions/<id>/attachments/<attachmentId>" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Rewind chat session

`POST /v1/chat/sessions/{id}/rewind`

Rewind before one active user message. Original messages remain saved. Running replies return 409.

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

### Parameters

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

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

- `messageId` (string, required) [min length 1]

### Responses

- `200` OK (application/json, ChatSessionDetail)
  - `id` (string, required)
  - `title` (string, required): The first question until you rename it
  - `mode` ("chat" | "ask", required): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
  - `model` (string, required): The model asked for: nexus/auto by default
  - `lastModel` (string): The model that ran last
  - `team` (string): The team its spend is attributed to
  - `archived` (boolean, required)
  - `webSearch` (boolean): Whether the model may search the web in this session (default false)
  - `messageCount` (integer, required)
  - `costUsd` (number, required): The sum of its model calls and of the web searches that returned results, settled in the ledger; a search that fails after the provider billed it is in the ledger, not in this sum
  - `createdAt` (string (date-time), required)
  - `updatedAt` (string (date-time), required)
  - `visibility` ("private" | "shared"): Private (the default) or shared: at least one active artifact
  - `sharing` (ChatSessionSharing): How a shared session is shared: its newest active artifact
    - `artifactId` (string, required)
    - `version` (integer, required)
    - `audience` (ArtifactAudience, required): Who may read an artifact, besides its author: inside the organization, the whole organization, chosen teams (their members and the members of the teams under them) or chosen people; outside it, named people by email (`external`) or anyone with the link (`public`). Readers outside the organization see the kind only.
      - `kind` ("org" | "teams" | "people" | "external" | "public", required)
      - `teams` (array of string, required): Team slugs (kind teams)
      - `people` (array of string, required): Members' emails (kind people); the outsiders with access (kind external). Empty for readers outside the organization.
    - `allowContinue` (boolean, required)
    - `url` (string, required): The link to hand out: a public link (kind public), the fast viewer (kind external), else the artifact in Nexus UI; absolute when the Gateway knows Nexus UI's URL (NEXUS_UI_URL), else a path
    - `path` (string, required): /app/<org>/artifacts/<id>
    - `viewerUrl` (string): The fast viewer: <origin>/a/<id>
    - `publicUrl` (string): Kind public: <origin>/a/<token>
    - `expiresAt` (string (date-time)): Kind public: when the link stops opening
  - `artifacts` (array of ArtifactLink): Every version shared from this session, newest first (revoked ones included)
    - `id` (string, required)
    - `version` (integer, required) [min 1]
    - `status` ("active" | "revoked", required)
    - `audience` ("org" | "teams" | "people" | "external" | "public", required)
    - `createdAt` (string (date-time), required)
    - `revokedAt` (string (date-time))
  - `author` (ArtifactAuthor): You (listed and read sessions)
    - `email` (string)
    - `name` (string)
  - `forkedFrom` (object): The artifact this session continues (POST /v1/artifacts/{id}/continue)
    - `artifactId` (string, required)
    - `version` (integer, required)
    - `title` (string)
  - `messages` (array of ChatSessionMessage, required)
    - `id` (string, required)
    - `sessionId` (string, required)
    - `role` ("user" | "assistant", required)
    - `content` (string, required): Markdown (a question with images may have none)
    - `status` ("complete" | "failed" | "refused", required): Refused: the policy or budget refused the call (error says why); failed: it broke mid-way (content is what arrived)
    - `mode` ("chat" | "ask"): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
    - `requestedModel` (string)
    - `model` (string): The model that ran
    - `costUsd` (number)
    - `usage` (object)
      - `promptTokens` (integer)
      - `completionTokens` (integer)
    - `citations` (array of ChatCitation)
      - `n` (integer, required): The number the answer cites it by
      - `repo` (string, required): Owner/name
      - `page` (string, required)
      - `slug` (string, required)
      - `section` (string)
      - `path` (string, required): <slug>#<anchor> in the repository's wiki
      - `files` (array of string): Repository files the section names
      - `runId` (string, required): The Nexus Wiki run that wrote the page
    - `error` (object)
      - `code` (string)
      - `message` (string)
      - `status` (integer)
      - `notified` (boolean): A budget refusal told the organization's owners and admins (licensed build). Absent otherwise.
      - `remainingUsdDecimal` (string): A budget refusal's `remainingUsdDecimal`: what was left of that level's budget, as an exact decimal. Absent when the 402 had none.
      - `requestedUsd` (string): A usage-limit refusal's (`usage_limit_reached`) `requestedUsd`: the most the call may cost with Nexus's rate, as an exact decimal. Absent for any other refusal, or when the 402 had none.
      - `remainingUsd` (string): A usage-limit refusal's (`usage_limit_reached`) `remainingUsd`: what this month's usage limit had left, as an exact decimal. Absent for any other refusal, or when the 402 had none.
      - `details` (object): A 402's details, as the live error's `error.nexus` had them, cut to an allow-list: short codes, ways forward, `notified` and decimal dollar amounts. Absent for any other status, when none was kept, and on an answer stored before it.
        - `reason` (string): Why the refusal happened, such as `authentication_required` or `disputed` for `payment_failed`.
        - `level` (string): A budget refusal's level.
        - `freeStart` (string): `cheaper_models_only` when the free start pays for cheaper models only.
        - `next` (array of string): The ways forward, such as `billing` and `own_key`; at most 4.
        - `notified` (boolean): The organization's owners and admins were told.
        - `owedUsd` (string)
        - `unpaidUsd` (string)
        - `remainingUsd` (string)
        - `remainingUsdDecimal` (string)
        - `requestedUsd` (string)
        - `limitUsd` (string)
        - `chargeUsd` (string)
        - `capUsd` (string)
    - `createdAt` (string (date-time), required)
    - `attachments` (array of ChatAttachmentRef): The images attached to a question
      - `id` (string, required)
      - `type` ("image" | "file", required)
      - `mediaType` ("image/png" | "image/jpeg" | "image/gif" | "image/webp" | "text/csv" | "text/tab-separated-values" | "application/json" | "text/plain" | "text/markdown" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", required): An image's from the bytes, not as it was named; a data file's from its extension, checked against the bytes
      - `bytes` (integer, required)
      - `width` (integer)
      - `height` (integer)
      - `name` (string)
    - `page` (ChatPageBlock): A page this answer created or revised through write_page
      - `pageId` (string, required)
      - `version` (integer, required) [min 1]
      - `title` (string, required)
      - `format` ("html" | "md" | "jsx" | "sheet" | "board", required)
    - `skills` (array of ChatSkillBlock): The skills this answer loaded through load_skill, in the order it loaded them. The file stays in the skills store
      - `skillId` (string, required): Skl_… For a library skill, the library skill's id, which getSkill and getSkillVersion also take
      - `name` (string, required): The name the version had when it was served
      - `version` (integer, required): The version served: a personal skill's latest, or a library skill's latest approved version that nobody withdrew [min 1]
      - `scope` ("personal" | "team" | "org"): Where the skill came from: your own skills, a team's library, or the organization's. Left out on an answer stored before skills had a scope: read it as personal
      - `teamId` (string): The team (team_…), for scope team. Map it to the team's name with listTeams
    - `connectors` (array of ChatConnectorBlock): The connector reads this answer ran through read_connector, in order. What they returned is never kept. In a shared artifact, a reader sees only the reads of connectors they may use
      - `connector` (string, required)
      - `operation` (string, required)
      - `input` (object, required)
      - `account` (object): The connection the read ran with: whose it is and the account's name. Absent while the read streams, and on reads kept before it was recorded
        - `scope` ("org" | "team" | "user", required)
        - `name` (string, required)
    - `sources` (array of ChatWebSource): The web pages this answer's searches gave the model, one per URL, in the order they were found. Only the session's author reads them; a shared artifact keeps none
      - `title` (string, required)
      - `url` (string, required)
      - `date` (string): The page's date as the engine gave it, cut as the model read it
      - `query` (string, required): The first query in the turn that found this page
    - `rewound` (boolean): Retained for the author, but excluded from future model context after a conversation rewind.
- `404` No such session among yours (`chat_session_not_found`): someone else's session answers the same. (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` An answer is still running (`chat_session_busy`), or the message is no longer part of the conversation (`chat_message_inactive`). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such session among yours (`chat_session_not_found`): someone else's session answers the same. |
| 409 |  | An answer is still running (`chat_session_busy`), or the message is no longer part of the conversation (`chat_message_inactive`). |
| 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/chat/sessions/<id>/rewind" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messageId": "<messageId>"
  }'
```

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

## Suggest chat message

`POST /v1/chat/sessions/{id}/suggest`

Suggest the message the person is most likely to send next. The call reads the session's cached prompt; nothing is stored.

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

### Parameters

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

### Responses

- `200` OK. `suggestion` is null when the model offers none. It is also null, and no model is called, when the session's last message is not a complete answer or the organization turned `chatSuggestions` off. (application/json, ChatSuggestion)
  - `suggestion` (string | null, required): The suggested message, one line of at most 120 characters.
  - `model` (string | null, required): The model that wrote it; null when no model was called.
  - `costUsd` (number, required): What the call cost. The session's `costUsd` does not count it; the ledger does.
- `404` No such session among yours (`chat_session_not_found`): someone else's session answers the same. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such session among yours (`chat_session_not_found`): someone else's session answers the same. |
| 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/chat/sessions/<id>/suggest" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

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

## Get guest chat

`GET /v1/guest/chat`

Guest chat for a signed-out visitor: whether this guest may send a round now, its rounds, and the model that answers.

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

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `X-Nexus-Guest` | header | string (uuid) | yes | The browser's guest id: a random UUID it keeps (in localStorage). Its rounds count under it. |

### Responses

- `200` OK (application/json, GuestChatStatus)
  - `enabled` (boolean, required): Whether a round from this guest id and address is within the rounds, the output tokens and the address's rounds now
  - `rounds_used` (integer, required): The rounds this guest id has used [min 0]
  - `rounds_limit` (integer, required): The rounds a guest id gets [min 0]
  - `model` (string, required): The display name of the model that answers every guest round, such as `DeepSeek V4 Flash 0731`
- `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 |
| --- | --- | --- |
| 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). |

### Example

```sh
curl "$NEXUS_URL/v1/guest/chat"
```

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

## Send guest chat message

`POST /v1/guest/chat/messages`

One guest chat round: the answer streams as server-sent events, as sendChatMessage streams it, on the guest model, billed to the guest organization. Nothing of the chat is stored.

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

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `X-Nexus-Guest` | header | string (uuid) | yes | The browser's guest id: a random UUID it keeps (in localStorage). Its rounds count under it. |

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

- `messages` (array of GuestChatMessage, required): The conversation, oldest first; the last one the guest's (`user`). 32,000 characters in all at most. [at most 20 items]
  - `role` ("user" | "assistant", required)
  - `content` (string, required) [min length 1]
- `turnstile` (string, required): The Cloudflare Turnstile widget's token [min length 1; max length 2048]

### Responses

- `200` The answer, as an event stream (text/event-stream, ChatStreamChunk)
  - `id` (string)
  - `object` ("chat.completion.chunk")
  - `created` (integer)
  - `model` (string | null): The model that runs
  - `choices` (array of object)
    - `index` (integer)
    - `delta` (object)
      - `role` (string)
      - `content` (string)
    - `finish_reason` (string | null)
  - `usage` (object)
    - `prompt_tokens` (integer)
    - `completion_tokens` (integer)
    - `total_tokens` (integer)
  - `nexus` (object)
    - `session` (ChatSession): A chat session, private to its author unless shared as an artifact.
      - `id` (string, required)
      - `title` (string, required): The first question until you rename it
      - `mode` ("chat" | "ask", required): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
      - `model` (string, required): The model asked for: nexus/auto by default
      - `lastModel` (string): The model that ran last
      - `team` (string): The team its spend is attributed to
      - `archived` (boolean, required)
      - `webSearch` (boolean): Whether the model may search the web in this session (default false)
      - `messageCount` (integer, required)
      - `costUsd` (number, required): The sum of its model calls and of the web searches that returned results, settled in the ledger; a search that fails after the provider billed it is in the ledger, not in this sum
      - `createdAt` (string (date-time), required)
      - `updatedAt` (string (date-time), required)
      - `visibility` ("private" | "shared"): Private (the default) or shared: at least one active artifact
      - `sharing` (ChatSessionSharing): How a shared session is shared: its newest active artifact
        - `artifactId` (string, required)
        - `version` (integer, required)
        - `audience` (ArtifactAudience, required): Who may read an artifact, besides its author: inside the organization, the whole organization, chosen teams (their members and the members of the teams under them) or chosen people; outside it, named people by email (`external`) or anyone with the link (`public`). Readers outside the organization see the kind only.
          - `kind` ("org" | "teams" | "people" | "external" | "public", required)
          - `teams` (array of string, required): Team slugs (kind teams)
          - `people` (array of string, required): Members' emails (kind people); the outsiders with access (kind external). Empty for readers outside the organization.
        - `allowContinue` (boolean, required)
        - `url` (string, required): The link to hand out: a public link (kind public), the fast viewer (kind external), else the artifact in Nexus UI; absolute when the Gateway knows Nexus UI's URL (NEXUS_UI_URL), else a path
        - `path` (string, required): /app/<org>/artifacts/<id>
        - `viewerUrl` (string): The fast viewer: <origin>/a/<id>
        - `publicUrl` (string): Kind public: <origin>/a/<token>
        - `expiresAt` (string (date-time)): Kind public: when the link stops opening
      - `artifacts` (array of ArtifactLink): Every version shared from this session, newest first (revoked ones included)
        - `id` (string, required)
        - `version` (integer, required) [min 1]
        - `status` ("active" | "revoked", required)
        - `audience` ("org" | "teams" | "people" | "external" | "public", required)
        - `createdAt` (string (date-time), required)
        - `revokedAt` (string (date-time))
      - `author` (ArtifactAuthor): You (listed and read sessions)
        - `email` (string)
        - `name` (string)
      - `forkedFrom` (object): The artifact this session continues (POST /v1/artifacts/{id}/continue)
        - `artifactId` (string, required)
        - `version` (integer, required)
        - `title` (string)
    - `question` (ChatSessionMessage)
      - `id` (string, required)
      - `sessionId` (string, required)
      - `role` ("user" | "assistant", required)
      - `content` (string, required): Markdown (a question with images may have none)
      - `status` ("complete" | "failed" | "refused", required): Refused: the policy or budget refused the call (error says why); failed: it broke mid-way (content is what arrived)
      - `mode` ("chat" | "ask"): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
      - `requestedModel` (string)
      - `model` (string): The model that ran
      - `costUsd` (number)
      - `usage` (object)
        - `promptTokens` (integer)
        - `completionTokens` (integer)
      - `citations` (array of ChatCitation)
        - `n` (integer, required): The number the answer cites it by
        - `repo` (string, required): Owner/name
        - `page` (string, required)
        - `slug` (string, required)
        - `section` (string)
        - `path` (string, required): <slug>#<anchor> in the repository's wiki
        - `files` (array of string): Repository files the section names
        - `runId` (string, required): The Nexus Wiki run that wrote the page
      - `error` (object)
        - `code` (string)
        - `message` (string)
        - `status` (integer)
        - `notified` (boolean): A budget refusal told the organization's owners and admins (licensed build). Absent otherwise.
        - `remainingUsdDecimal` (string): A budget refusal's `remainingUsdDecimal`: what was left of that level's budget, as an exact decimal. Absent when the 402 had none.
        - `requestedUsd` (string): A usage-limit refusal's (`usage_limit_reached`) `requestedUsd`: the most the call may cost with Nexus's rate, as an exact decimal. Absent for any other refusal, or when the 402 had none.
        - `remainingUsd` (string): A usage-limit refusal's (`usage_limit_reached`) `remainingUsd`: what this month's usage limit had left, as an exact decimal. Absent for any other refusal, or when the 402 had none.
        - `details` (object): A 402's details, as the live error's `error.nexus` had them, cut to an allow-list: short codes, ways forward, `notified` and decimal dollar amounts. Absent for any other status, when none was kept, and on an answer stored before it.
          - `reason` (string): Why the refusal happened, such as `authentication_required` or `disputed` for `payment_failed`.
          - `level` (string): A budget refusal's level.
          - `freeStart` (string): `cheaper_models_only` when the free start pays for cheaper models only.
          - `next` (array of string): The ways forward, such as `billing` and `own_key`; at most 4.
          - `notified` (boolean): The organization's owners and admins were told.
          - `owedUsd` (string)
          - `unpaidUsd` (string)
          - `remainingUsd` (string)
          - `remainingUsdDecimal` (string)
          - `requestedUsd` (string)
          - `limitUsd` (string)
          - `chargeUsd` (string)
          - `capUsd` (string)
      - `createdAt` (string (date-time), required)
      - `attachments` (array of ChatAttachmentRef): The images attached to a question
        - `id` (string, required)
        - `type` ("image" | "file", required)
        - `mediaType` ("image/png" | "image/jpeg" | "image/gif" | "image/webp" | "text/csv" | "text/tab-separated-values" | "application/json" | "text/plain" | "text/markdown" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", required): An image's from the bytes, not as it was named; a data file's from its extension, checked against the bytes
        - `bytes` (integer, required)
        - `width` (integer)
        - `height` (integer)
        - `name` (string)
      - `page` (ChatPageBlock): A page this answer created or revised through write_page
        - `pageId` (string, required)
        - `version` (integer, required) [min 1]
        - `title` (string, required)
        - `format` ("html" | "md" | "jsx" | "sheet" | "board", required)
      - `skills` (array of ChatSkillBlock): The skills this answer loaded through load_skill, in the order it loaded them. The file stays in the skills store
        - `skillId` (string, required): Skl_… For a library skill, the library skill's id, which getSkill and getSkillVersion also take
        - `name` (string, required): The name the version had when it was served
        - `version` (integer, required): The version served: a personal skill's latest, or a library skill's latest approved version that nobody withdrew [min 1]
        - `scope` ("personal" | "team" | "org"): Where the skill came from: your own skills, a team's library, or the organization's. Left out on an answer stored before skills had a scope: read it as personal
        - `teamId` (string): The team (team_…), for scope team. Map it to the team's name with listTeams
      - `connectors` (array of ChatConnectorBlock): The connector reads this answer ran through read_connector, in order. What they returned is never kept. In a shared artifact, a reader sees only the reads of connectors they may use
        - `connector` (string, required)
        - `operation` (string, required)
        - `input` (object, required)
        - `account` (object): The connection the read ran with: whose it is and the account's name. Absent while the read streams, and on reads kept before it was recorded
          - `scope` ("org" | "team" | "user", required)
          - `name` (string, required)
      - `sources` (array of ChatWebSource): The web pages this answer's searches gave the model, one per URL, in the order they were found. Only the session's author reads them; a shared artifact keeps none
        - `title` (string, required)
        - `url` (string, required)
        - `date` (string): The page's date as the engine gave it, cut as the model read it
        - `query` (string, required): The first query in the turn that found this page
      - `rewound` (boolean): Retained for the author, but excluded from future model context after a conversation rewind.
    - `message` (ChatSessionMessage)
      - `id` (string, required)
      - `sessionId` (string, required)
      - `role` ("user" | "assistant", required)
      - `content` (string, required): Markdown (a question with images may have none)
      - `status` ("complete" | "failed" | "refused", required): Refused: the policy or budget refused the call (error says why); failed: it broke mid-way (content is what arrived)
      - `mode` ("chat" | "ask"): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
      - `requestedModel` (string)
      - `model` (string): The model that ran
      - `costUsd` (number)
      - `usage` (object)
        - `promptTokens` (integer)
        - `completionTokens` (integer)
      - `citations` (array of ChatCitation)
        - `n` (integer, required): The number the answer cites it by
        - `repo` (string, required): Owner/name
        - `page` (string, required)
        - `slug` (string, required)
        - `section` (string)
        - `path` (string, required): <slug>#<anchor> in the repository's wiki
        - `files` (array of string): Repository files the section names
        - `runId` (string, required): The Nexus Wiki run that wrote the page
      - `error` (object)
        - `code` (string)
        - `message` (string)
        - `status` (integer)
        - `notified` (boolean): A budget refusal told the organization's owners and admins (licensed build). Absent otherwise.
        - `remainingUsdDecimal` (string): A budget refusal's `remainingUsdDecimal`: what was left of that level's budget, as an exact decimal. Absent when the 402 had none.
        - `requestedUsd` (string): A usage-limit refusal's (`usage_limit_reached`) `requestedUsd`: the most the call may cost with Nexus's rate, as an exact decimal. Absent for any other refusal, or when the 402 had none.
        - `remainingUsd` (string): A usage-limit refusal's (`usage_limit_reached`) `remainingUsd`: what this month's usage limit had left, as an exact decimal. Absent for any other refusal, or when the 402 had none.
        - `details` (object): A 402's details, as the live error's `error.nexus` had them, cut to an allow-list: short codes, ways forward, `notified` and decimal dollar amounts. Absent for any other status, when none was kept, and on an answer stored before it.
          - `reason` (string): Why the refusal happened, such as `authentication_required` or `disputed` for `payment_failed`.
          - `level` (string): A budget refusal's level.
          - `freeStart` (string): `cheaper_models_only` when the free start pays for cheaper models only.
          - `next` (array of string): The ways forward, such as `billing` and `own_key`; at most 4.
          - `notified` (boolean): The organization's owners and admins were told.
          - `owedUsd` (string)
          - `unpaidUsd` (string)
          - `remainingUsd` (string)
          - `remainingUsdDecimal` (string)
          - `requestedUsd` (string)
          - `limitUsd` (string)
          - `chargeUsd` (string)
          - `capUsd` (string)
      - `createdAt` (string (date-time), required)
      - `attachments` (array of ChatAttachmentRef): The images attached to a question
        - `id` (string, required)
        - `type` ("image" | "file", required)
        - `mediaType` ("image/png" | "image/jpeg" | "image/gif" | "image/webp" | "text/csv" | "text/tab-separated-values" | "application/json" | "text/plain" | "text/markdown" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", required): An image's from the bytes, not as it was named; a data file's from its extension, checked against the bytes
        - `bytes` (integer, required)
        - `width` (integer)
        - `height` (integer)
        - `name` (string)
      - `page` (ChatPageBlock): A page this answer created or revised through write_page
        - `pageId` (string, required)
        - `version` (integer, required) [min 1]
        - `title` (string, required)
        - `format` ("html" | "md" | "jsx" | "sheet" | "board", required)
      - `skills` (array of ChatSkillBlock): The skills this answer loaded through load_skill, in the order it loaded them. The file stays in the skills store
        - `skillId` (string, required): Skl_… For a library skill, the library skill's id, which getSkill and getSkillVersion also take
        - `name` (string, required): The name the version had when it was served
        - `version` (integer, required): The version served: a personal skill's latest, or a library skill's latest approved version that nobody withdrew [min 1]
        - `scope` ("personal" | "team" | "org"): Where the skill came from: your own skills, a team's library, or the organization's. Left out on an answer stored before skills had a scope: read it as personal
        - `teamId` (string): The team (team_…), for scope team. Map it to the team's name with listTeams
      - `connectors` (array of ChatConnectorBlock): The connector reads this answer ran through read_connector, in order. What they returned is never kept. In a shared artifact, a reader sees only the reads of connectors they may use
        - `connector` (string, required)
        - `operation` (string, required)
        - `input` (object, required)
        - `account` (object): The connection the read ran with: whose it is and the account's name. Absent while the read streams, and on reads kept before it was recorded
          - `scope` ("org" | "team" | "user", required)
          - `name` (string, required)
      - `sources` (array of ChatWebSource): The web pages this answer's searches gave the model, one per URL, in the order they were found. Only the session's author reads them; a shared artifact keeps none
        - `title` (string, required)
        - `url` (string, required)
        - `date` (string): The page's date as the engine gave it, cut as the model read it
        - `query` (string, required): The first query in the turn that found this page
      - `rewound` (boolean): Retained for the author, but excluded from future model context after a conversation rewind.
    - `mode` ("chat" | "ask"): `chat` with any model you may use; `ask` (Ask your code) answers from your organization's Nexus Wiki, citing its pages
    - `requested` (string)
    - `citations` (array of ChatCitation)
      - `n` (integer, required): The number the answer cites it by
      - `repo` (string, required): Owner/name
      - `page` (string, required)
      - `slug` (string, required)
      - `section` (string)
      - `path` (string, required): <slug>#<anchor> in the repository's wiki
      - `files` (array of string): Repository files the section names
      - `runId` (string, required): The Nexus Wiki run that wrote the page
    - `no_wiki` (boolean)
    - `tool` (object): A chat tool currently executing
      - `name` ("write_page" | "load_skill" | "describe_connector" | "read_connector" | "web_search", required)
      - `status` ("running", required)
    - `skill` (ChatSkillBlock): A skill load_skill has just read
      - `skillId` (string, required): Skl_… For a library skill, the library skill's id, which getSkill and getSkillVersion also take
      - `name` (string, required): The name the version had when it was served
      - `version` (integer, required): The version served: a personal skill's latest, or a library skill's latest approved version that nobody withdrew [min 1]
      - `scope` ("personal" | "team" | "org"): Where the skill came from: your own skills, a team's library, or the organization's. Left out on an answer stored before skills had a scope: read it as personal
      - `teamId` (string): The team (team_…), for scope team. Map it to the team's name with listTeams
    - `connector` (ChatConnectorBlock): A connector read read_connector is about to run
      - `connector` (string, required)
      - `operation` (string, required)
      - `input` (object, required)
      - `account` (object): The connection the read ran with: whose it is and the account's name. Absent while the read streams, and on reads kept before it was recorded
        - `scope` ("org" | "team" | "user", required)
        - `name` (string, required)
    - `cost_usd` (number)
- `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 |
| 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). |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/guest/chat/messages" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {
        "role": "user",
        "content": "<content>"
      }
    ],
    "turnstile": "<turnstile>"
  }'
```

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