# API overview

> One API for everything in Nexus, the same one the CLI and Nexus UI use.

Everything you can do in Nexus UI or the CLI goes through the Nexus API: organizations, keys, teams, spend, the audit
log, model calls and every product. This reference is generated from the API's own OpenAPI description at each
build, so it lists exactly the endpoints that exist.

## Base URL

The API lives under `/v1` on your Nexus Gateway, for example `https://api.nexus.inc/v1`. The examples use two shell variables:

```sh
export NEXUS_URL=https://api.nexus.inc
export NEXUS_API_KEY=nx_…          # an API key: Nexus UI → Settings → Keys
```

Your Gateway also serves the full description, with every registered product's operations merged in, at
[`GET /v1/openapi.json`](/docs/api/core#openapi).

## Authentication

Send a personal token as `Authorization: Bearer <token>`. See [Authentication](/docs/authentication) for the kinds of
tokens and how to get one. Each endpoint below shows the permission it needs and who has it; the full matrix is on
[Permissions](/docs/concepts/permissions).

## Requests and responses

- Request and response bodies are JSON, except where an endpoint says otherwise (an audit export is CSV; the agent
  gateway streams server-sent events).
- Every answer carries an `x-request-id`; the audit log records it with each change.
- Every write and model call accepts an `Idempotency-Key`, so a retry is applied once. See
  [Idempotency keys](/docs/concepts/idempotency).
- Name the team a call is attributed to with the `x-nexus-team` header. See [Attribution](/docs/concepts/attribution).
- Errors are `{ "error": { "message", "type", "code" } }`. See [Errors](/docs/api/errors).
- Requests are rate-limited per key per minute (`429`).

## Examples

Each endpoint has a curl example and, where the typed client has the call, a TypeScript example using `@nexus/kit`,
the client the CLI and Nexus UI use. `@nexus/kit` is not published to npm yet: coming.

**Try it** on an endpoint opens it in Nexus UI's API Explorer, which sends the request with your key and shows the
answer.

> The API is at version `0.45.0`. MVP: not a stable contract yet. Changes appear here on the day they ship.
