# Audit log

> The append-only audit log: who changed what, through which credential, from which surface, before and after.

## List audit events

`GET /v1/audit`

The audit log, newest first: everything for owners and admins, a lead's teams (and those under them), else your own actions.

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

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `since` | query | string | no | ISO time, or relative: 30m, 24h, 7d, 2w |
| `until` | query | string | no | ISO time, or relative |
| `action` | query | string | no | An action, a comma-separated list, or a prefix ending in * (team.*) |
| `actor` | query | string | no | The actor's user id or email |
| `target` | query | string | no | The target's id or slug |
| `team` | query | string | no | A team slug or id: events of that team and every team under it |
| `limit` | query | integer | no | Events per page, 1 to 500 (default 50) |
| `cursor` | query | string | no | NextCursor from the previous page |

### Responses

- `200` OK (application/json, AuditPage)
  - `scope` ("all" | "team" | "own", required)
  - `events` (array of AuditEvent, required)
    - `id` (string, required)
    - `at` (string (date-time), required)
    - `actor` (object, required)
      - `userId` (string)
      - `email` (string): Filled in when the log is read, from the person's user record: a new event stores the actor by user id alone. Absent for an erased person and for an operator in a customer's log.
      - `keyId` (string, required): The credential: a token id, `ui` (Nexus UI's server), a module's scoped key (`scoped:<product>/<capability>/smk_…`), a sandbox session's id (`sbs_…`), an agent link (`agl_…`), `github`, `clerk` or `system`
      - `kind` ("person" | "api_key" | "cli" | "ui" | "module" | "service" | "sandbox" | "operator" | "agent" | "platform" | "system", required)
      - `erased` (boolean): True when the person was erased: no email is shown for them.
    - `surface` ("api" | "cli" | "mcp" | "ui" | "chat" | "webhook" | "system", required)
    - `action` ("org.created" | "org.settings_changed" | "org.recovery_key_changed" | "org.team_key_rotated" | "synced_session.audit_read" | "synced_session.made_private" | "synced_session.made_team_visible" | "cloud_history.break_glass_read" | "devices.recovered" | "org.budget_changed" | "app.cap_changed" | "app.claim_requested" | "app.deleted" | "budget.person_default_changed" | "budget.person_limit_changed" | "budget.team_changed" | "budget.product_changed" | "budget.limit_manager_granted" | "budget.limit_manager_revoked" | "org.owner_transferred" | "org.relinked" | "member.joined" | "member.role_changed" | "member.removed" | "member.recovered" | "account.deleted" | "member.default_team_changed" | "invitation.sent" | "invitation.revoked" | "domain.added" | "domain.removed" | "key.created" | "key.revoked" | "provider_key.added" | "provider_key.replaced" | "provider_key.disabled" | "provider_key.enabled" | "provider_key.removed" | "provider_key.rejected" | "connector_credential.added" | "connector_credential.replaced" | "connector_credential.revoked" | "connector_credential.needs_reconnect" | "vault.master_changed" | "auth.device_approved" | "auth.device_denied" | "auth.token_issued" | "auth.token_revoked" | "policy.changed" | "policy.control_set" | "policy.control_cleared" | "team.created" | "team.updated" | "team.moved" | "team.deleted" | "team.member_added" | "team.member_role_changed" | "team.member_removed" | "team.pending_added" | "team.pending_cancelled" | "team.import_applied" | "github.installation_linked" | "github.installation_unlinked" | "github.installation_removed" | "github.repositories_changed" | "chat_workspace.installed" | "chat_workspace.confirmed" | "chat_workspace.revoked" | "chat_workspace.token_refresh_failed" | "chat_channel.bound" | "chat_channel.unbound" | "chat_channel.moved" | "chat_workspace.runtime_read" | "chat_workspace.revoke_refused" | "chat.session_created" | "chat.session_deleted" | "artifact.shared" | "artifact.updated" | "artifact.revoked" | "artifact.continued" | "subsidy.granted" | "subsidy.used" | "subsidy.paid" | "subsidy.expired" | "credit.purchased" | "credit.reversed" | "credit.restored" | "credit.auto_topup_changed" | "artifact.access_changed" | "artifact.access_requested" | "artifact.reported" | "ledger.reservation_released" | "ledger.reservation_settled_late" | "connector_grant.granted" | "connector_grant.revoked" | "connector_availability.changed" | "connector.write" | "connector.write_attempt" | "connector.read" | "chat_write_setting.changed" | "agent_write_setting.changed" | "review_event_setting.changed" | "policy.approval.requested" | "policy.approval.confirmed" | "policy.approval.denied" | "policy.approval.cancelled" | "policy.approval.used" | "page.created" | "page.version_written" | "page.restored" | "page.deleted" | "page.trashed" | "page.restored_from_trash" | "page_query.saved" | "page_query.deleted" | "design_system.saved" | "design_system.default_set" | "design_system.deleted" | "skill.created" | "skill.version_written" | "skill.deleted" | "skill.promotion_requested" | "skill.promotion_approved" | "skill.promotion_refused" | "skill.promotion_withdrawn" | "billing.customer_created" | "billing.customer_deleted" | "billing.payment_method_changed" | "billing.invoice_sent" | "billing.invoice_paid" | "billing.invoice_failed" | "billing.plan_changed" | "billing.plan_change_scheduled" | "billing.after_the_fact_changed" | "billing.usage_charged" | "billing.usage_charge_failed" | "billing.payment_disputed" | "billing.dispute_closed" | "observability.exported" | "observability.directory_exported" | "service_account.created" | "service_account.key_created" | "service_account.key_rotated" | "service_account.key_revoked" | "service_account.revoked" | "sandbox_session.started" | "sandbox_session.ended" | "agent_session.started" | "agent_session.ended" | "operator_grant.issued" | "operator_grant.revoked" | "operator.request" | "org.marked" | "person.marked" | "desktop.revocations_changed" | "staff.person_viewed" | "staff.list_viewed" | "agent.linked" | "agent.unlinked" | "agent.memory_written" | "agent.memory_deleted" | "agent.memory_cleared" | "agent.profile_created" | "agent.profile_updated" | "agent.profile_deleted" | "project.created" | "project.updated" | "project.archived" | "project.moved_to_org" | "project.repo_added" | "project.repo_removed" | "project.member_set" | "project.member_removed" | "secret.set" | "secret.deleted" | "project.setup_saved" | "subscription.changed" | "subscription.status_changed" | "referral.recorded" | "referral.reward_voided" | "invite.created" | "invite.revoked" | "invite.approved" | "platform_role.granted" | "platform_role.revoked" | "schedule.upserted" | "schedule.paused" | "schedule.resumed" | "schedule.deleted", required): Stable and dotted
    - `target` (object, required)
      - `type` (string, required)
      - `id` (string, required)
      - `slug` (string)
    - `before` (any): The record before the change (credentials redacted)
    - `after` (any): The record after the change (credentials redacted)
    - `requestId` (string): The request's x-request-id
    - `metadata` (object)
  - `nextCursor` (string)
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

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

### Example

```sh
curl "$NEXUS_URL/v1/audit" \
  -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.audit({ since: "7d", action: "team.*" });
```

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

## Export audit events

`GET /v1/audit/export.csv`

Every matching audit event you may read, newest first, streamed as CSV (owners, admins and team leads).

Permission: `audit.export` (Owner, Admin, Team lead).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `since` | query | string | no | ISO time, or relative: 30m, 24h, 7d, 2w |
| `until` | query | string | no | ISO time, or relative |
| `action` | query | string | no | An action, a comma-separated list, or a prefix ending in * (team.*) |
| `actor` | query | string | no | The actor's user id or email |
| `target` | query | string | no | The target's id or slug |
| `team` | query | string | no | A team slug or id: events of that team and every team under it |

### Responses

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

### Errors

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

### Example

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

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

const core = createCoreClient({ baseUrl: process.env.NEXUS_URL!, apiKey: process.env.NEXUS_API_KEY });
const result = await core.auditCsv({ since: "30d" });
```

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