> For the complete documentation index, see [llms.txt](https://wiki.crosswatch.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.crosswatch.app/crosswatch/advanced-and-api/api-reference/api-foundations.md).

# API foundations

Base URLs, sessions, response conventions, and version endpoints.

Use these endpoints to verify an instance and establish an authenticated session.

### Base URL

CrossWatch serves its API from the instance URL. Routes are not versioned.

```
http://localhost:8787
https://crosswatch.example.com
```

Use HTTPS outside a trusted network.

### Authentication

When application authentication is enabled, most `/api/*` routes require a signed-in session or an API token. Browser sessions use the HTTP-only `cw_auth` cookie.

| Method | Endpoint                      | Purpose                                   |
| ------ | ----------------------------- | ----------------------------------------- |
| `GET`  | `/api/health`                 | Return liveness and readiness.            |
| `GET`  | `/healthz`                    | Container health alias.                   |
| `GET`  | `/api/app-auth/status`        | Return authentication and session status. |
| `POST` | `/api/app-auth/login`         | Create a local session.                   |
| `POST` | `/api/app-auth/logout`        | End the current session.                  |
| `POST` | `/api/app-auth/logout-all`    | End every session.                        |
| `POST` | `/api/app-auth/logout-others` | End all other sessions.                   |
| `POST` | `/api/app-auth/credentials`   | Configure local credentials.              |

```bash
BASE_URL="http://localhost:8787"
curl -sS -c cookies.txt \
  -H "Content-Type: application/json" \
  -d '{"username":"admin","password":"replace-me","remember_me":true}' \
  "$BASE_URL/api/app-auth/login"
```

If the account uses two-factor authentication, include `"totp_code":"123456"` in the login body with the current authenticator code. A login that needs a code returns HTTP `401` with `requires_2fa: true`.

For scripts, create an API token using the [CLI](https://wiki.crosswatch.app/crosswatch/command-line-interface-cli.md#tokens). Send it as `Authorization: Bearer <token>` or `X-CW-Token: <token>`. It follows the token owner's access permissions; a Monitor token has restricted read access.

```bash
curl -sS -H "Authorization: Bearer $CW_TOKEN" "$BASE_URL/api/app-auth/tokens/whoami"
```

Set `CW_TOKEN` to your token before running the command. It does not need a browser cookie.

### Common responses

Check both the HTTP status and response body. Some operational endpoints return `200` with `ok: false`.

```json
{"ok": true}
```

FastAPI validation failures return a `detail` array. Webhook behavior differs and is documented separately.

### Version information

| Method | Endpoint             | Purpose                             |
| ------ | -------------------- | ----------------------------------- |
| `GET`  | `/api/version`       | Return the application version.     |
| `GET`  | `/api/version/check` | Check the configured update source. |
| `GET`  | `/api/update`        | Return update information.          |

The application does not expose interactive Swagger/ReDoc pages or an OpenAPI schema endpoint. Use these reference pages and the CLI command help for supported operations.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://wiki.crosswatch.app/crosswatch/advanced-and-api/api-reference/api-foundations.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
