# Connectors

> Connector reads and module writes with a standing Policy grant, shared by every module.

## Connectors

`GET /v1/connectors`

The connectors Gateway offers, their operations, and whether each is usable by the caller. A connector reaches an outside service by name, such as `linear`, `github`, `jira`, `slack` or `notion`: issues and tickets, pull requests, messages, mail, calendars, docs and files. Check it before you say a named service is unavailable.

Permission: `connectors.use` (Every member, module keys).

### Responses

- `200` OK (application/json, object)
  - `connectors` (array of object)
    - `stage` ("preview" | "released"): How far it is along its release: production offers only released connectors, a preview Gateway both
    - `offered` (boolean): Whether this Gateway offers it. No one uses one it does not offer: a call answers 403 connector_not_offered
    - `usable` (boolean | null): Whether the organization made it available to the caller (GET /v1/policies/connectors); null when it could not be read; false for one this Gateway does not offer
    - `connects` (array of "user" | "org"): Whose connections it runs with: a person's own (user), the organization's (org); empty when it resolves its own credential. A call takes an optional `account` when it is not empty.
    - `form` (object | null): The fields POST /v1/connections/{connector} takes, as a JSON Schema whose secret fields carry `x-nexus-secret: true`; null when it does not connect with a key
    - `oauth` (boolean): Whether it connects with OAuth on this gateway (POST /v1/connections/{connector}/oauth)
    - `offline_input` (object): Only on a gateway that reads this connector's offline test data (NEXUS_CONNECTORS=mock): the form's fields that test data accepts. POST them to /v1/connections/{connector} with the `scope` that `connects` admits: `user` or `org`. A secret field holds a placeholder, never a key. Absent when the connector calls its vendor.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

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

### Example

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

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

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

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

## Describe connector

`GET /v1/connectors/{name}`

One connector by its service's name (`linear` for Linear issues and tickets) and its operations, each with its `effect` (`read` or `mutate`) and its `request` schema, and whether the caller may use it (`usable`). It answers for every connector; readConnector and writeConnector run only one the organization made available to the caller. 404 when no connector has this name.

Permission: `connectors.use` (Every member, module keys).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `name` | path | string | yes | The connector, as `GET /v1/connectors` lists it (`github`, `jira`) |

### Responses

- `200` OK (application/json, object)
  - `name` (string)
  - `description` (string)
  - `stage` ("preview" | "released"): How far it is along its release: production offers only released connectors, a preview Gateway both
  - `offered` (boolean): Whether this Gateway offers it. No one uses one it does not offer: a call answers 403 connector_not_offered
  - `usable` (boolean | null): Whether the organization made it available to the caller (GET /v1/policies/connectors); null when it could not be read; false for one this Gateway does not offer
  - `connects` (array of "user" | "org"): Whose connections it runs with: a person's own (user), the organization's (org); empty when it resolves its own credential. A call takes an optional `account` when it is not empty.
  - `form` (object | null): The fields POST /v1/connections/{connector} takes, as a JSON Schema whose secret fields carry `x-nexus-secret: true`; null when it does not connect with a key
  - `oauth` (boolean): Whether it connects with OAuth on this gateway (POST /v1/connections/{connector}/oauth)
  - `operations` (array of object)
    - `name` (string)
    - `summary` (string)
    - `effect` ("read" | "mutate")
    - `request` (object): The JSON schema of the operation's parameters.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

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

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

## Write connector

`POST /v1/connectors/{name}/{operation}`

Run one connector operation, a read or a change. A change runs only for a module holding a write grant for it (PUT /v1/policies/grants/{product}/{capability}); a person's change is refused with 403 `write_not_granted` until people get write scopes. A chat agent's link writes only with the approval record the person confirmed for exactly this call, named in `x-nexus-approval`, while the organization has chat writes on: else 403 `write_not_granted` (no record), `approval_invalid` or `chat_writes_off`. The record is used by the call, once. Every change attempt and every scoped read is audited as `connector.write`. `github/pull_merge` squash-merges only at `expected_head_sha` and only when branch protection allows it, never past it: 400 `merge_method_refused`, 409 `head_changed`, `not_mergeable` or `pull_not_open`. `github/pull_edit` and `pull_reviewers` change only an open pull request (409 `pull_not_open`), and GitHub's refusal of a reviewer is 422 `reviewer_refused`. `github/pull_state` closes or reopens and never merges: 409 `pull_merged`, 422 `not_reopenable`. `github/pull_labels` adds only a label the repository has: 404 `label_unknown`. A runner's change inside a native session names the session and its fencing token (`x-nexus-cloud-session`, `x-nexus-fencing-token`): 400 `invalid_session_fence` without both, 404 `session_not_found` for a session that is not yours, 409 `session_ended` for an ended one, and 409 `lost_runner` when another runner took the session; nothing is called, and the refusal is audited. A change that names no fence while its credential holds a native session's live runner lease is refused with 409 `fence_required` (`error.nexus.session` names the session) when the server requires the fence; nothing is called, and the refusal is audited. When the server asks for write scopes on demand (NEXUS_CONNECTOR_WRITE_CONSENT), a change on an OAuth connection that holds none of the connector's write scopes is refused with 403 `write_consent_required`; nothing is called. `error.nexus` names the `connector`, the `account`, the `scopes` the change needs, and the `consent` call that asks for them (POST /v1/connections/{connector}/oauth with `access: write`). A change sent with `Idempotency-Key` carries a hidden marker in the body it writes (`github/issue_comment`, `pull_review`, `issue_create`). When GitHub got the write but its answer was lost, the 502 says `error.nexus.outcome: unknown` and the key is kept: a retry with the same key reads the target for the marker, answers what it found as a replay, or writes once. A retry that cannot read the target is 502 `reconciliation_failed` and writes nothing. Send an `Idempotency-Key` with every change. While the Gateway enforces connector write keys (off by default), a change without one is 428 `idempotency_key_required`, and nothing is called. A read never needs one.

Permission: `connectors.use` (Every member, module keys).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `name` | path | string | yes | The connector, as `GET /v1/connectors` lists it (`github`, `jira`) |
| `operation` | path | string | yes | The operation, as `GET /v1/connectors/{name}` lists it |
| `x-nexus-approval` | header | string | no | A chat agent's confirmed approval record for this exact call (`POST /v1/approvals`) |
| `x-nexus-cloud-session` | header | string | no | The native session (`/v1/sessions`) a runner's change is made inside, with `x-nexus-fencing-token`. Send both or neither. |
| `x-nexus-fencing-token` | header | string | no | The fencing token the runner got when it took the session (POST /v1/sessions/{id}/runner). A change whose token is not the session's current one is refused with 409 `lost_runner` before the outside system is called, and audited as `connector.write` with `outcome: denied`. |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

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

object: the provider's own request.

### Responses

- `200` OK (application/json, object)
- `428` Only while the Gateway enforces connector write keys (off by default): a change sent without `Idempotency-Key` (`idempotency_key_required`). Nothing was called. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of 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 | `merge_method_refused` | 400 `merge_method_refused`, 409 `head_changed`, `not_mergeable` or `pull_not_open` |
| 400 | `invalid_session_fence` | 400 `invalid_session_fence` without both, 404 `session_not_found` for a session that is not yours, 409 `session_ended` for an ended one, and 409 `lost_runner` when another runner took the session; nothing is called, and the refusal is audited |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 403 | `write_not_granted` | A change runs only for a module holding a write grant for it (PUT /v1/policies/grants/{product}/{capability}); a person's change is refused with 403 `write_not_granted` until people get write scopes |
| 403 | `write_consent_required` | When the server asks for write scopes on demand (NEXUS_CONNECTOR_WRITE_CONSENT), a change on an OAuth connection that holds none of the connector's write scopes is refused with 403 `write_consent_required`; nothing is called |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 | `label_unknown` | 404 `label_unknown` |
| 404 | `session_not_found` | 400 `invalid_session_fence` without both, 404 `session_not_found` for a session that is not yours, 409 `session_ended` for an ended one, and 409 `lost_runner` when another runner took the session; nothing is called, and the refusal is audited |
| 409 | `head_changed` | 400 `merge_method_refused`, 409 `head_changed`, `not_mergeable` or `pull_not_open` |
| 409 | `pull_not_open` | `github/pull_edit` and `pull_reviewers` change only an open pull request (409 `pull_not_open`), and GitHub's refusal of a reviewer is 422 `reviewer_refused` |
| 409 | `pull_merged` | 409 `pull_merged`, 422 `not_reopenable` |
| 409 | `session_ended` | 400 `invalid_session_fence` without both, 404 `session_not_found` for a session that is not yours, 409 `session_ended` for an ended one, and 409 `lost_runner` when another runner took the session; nothing is called, and the refusal is audited |
| 409 | `lost_runner` | 400 `invalid_session_fence` without both, 404 `session_not_found` for a session that is not yours, 409 `session_ended` for an ended one, and 409 `lost_runner` when another runner took the session; nothing is called, and the refusal is audited |
| 409 | `fence_required` | A change that names no fence while its credential holds a native session's live runner lease is refused with 409 `fence_required` (`error.nexus.session` names the session) when the server requires the fence; nothing is called, and the refusal is audited |
| 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 | `reviewer_refused` | `github/pull_edit` and `pull_reviewers` change only an open pull request (409 `pull_not_open`), and GitHub's refusal of a reviewer is 422 `reviewer_refused` |
| 422 | `not_reopenable` | 409 `pull_merged`, 422 `not_reopenable` |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 428 |  | Only while the Gateway enforces connector write keys (off by default): a change sent without `Idempotency-Key` (`idempotency_key_required`). Nothing was called. |
| 428 | `idempotency_key_required` | While the Gateway enforces connector write keys (off by default), a change without one is 428 `idempotency_key_required`, and nothing is called |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 502 | `reconciliation_failed` | A retry that cannot read the target is 502 `reconciliation_failed` and writes nothing |

### Example

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

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fconnectors%2F%7Bname%7D%2F%7Boperation%7D)

## Read connector

`POST /v1/connectors/{name}/{operation}/read`

Run one connector operation that only reads, as the caller, with the credential the connector resolves for the call. 403 `not_a_read` when the operation changes something (use writeConnector), and 403 `connector_disabled` when the organization has not made the connector available to the caller. A scoped read is audited as `connector.write`. A repeat is safe, so it takes no idempotency key.

Permission: `connectors.use` (Every member, module keys).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `name` | path | string | yes | The connector, as `GET /v1/connectors` lists it (`github`, `jira`) |
| `operation` | path | string | yes | The operation, as `GET /v1/connectors/{name}` lists it |

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

object: the provider's own request.

### Responses

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

### 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 |
| 403 | `not_a_read` | 403 `not_a_read` when the operation changes something (use writeConnector), and 403 `connector_disabled` when the organization has not made the connector available to the caller |
| 403 | `connector_disabled` | 403 `not_a_read` when the operation changes something (use writeConnector), and 403 `connector_disabled` when the organization has not made the connector available to the caller |
| 404 | `not_found` | Nothing matches the path in your organization |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/connectors/Platform/<operation>/read" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fconnectors%2F%7Bname%7D%2F%7Boperation%7D%2Fread)
