# Automation via APIs and CLI

> Operate the control plane without the browser: control plane API keys and their scopes, the HTTP API and its OpenAPI document, the MCP endpoint for agents, and the command line.

Everything you can do in the control plane's pages, a program or an agent can do too, with a **control plane API key**. The key acts as the account that created it, within the scopes it was given, and every change it makes is recorded in the audit log under the key's name.

There are three ways in, all with the same key and the same operations:

| Way in | For | Address |
|---|---|---|
| HTTP API | your own programs, provisioning systems | `https://<control-plane-address>/api/...` |
| MCP endpoint | AI agents and MCP clients | `https://<control-plane-address>/mcp` |
| Command line | a shell | `onprem-ai-ctl api METHOD PATH` |

`<control-plane-address>` is the address you open these pages at, for example `10.0.4.10:3443`.

**Trusting the certificate.** Unless you gave the control plane a certificate from your company's or a public certificate authority, it uses its own. Download its root CA under **Configuration → Security → Certificates (in your control plane)** and hand it to your client: `curl --cacert onprem-ai-root-ca.crt`, `verify="onprem-ai-root-ca.crt"` in Python, or `onprem-ai-ctl login --control-plane-ca-file onprem-ai-root-ca.crt` for the command line. Do not switch certificate checking off. See [Browser Certificate Trust](/en/platform/docs/guides/certificates-and-network/browser-certificate-trust/index.md).

## Create a control plane API key

Open **Settings → MCP access** (the page for every control plane API key, whether a program, an agent or the command line uses it) and choose **Add key**.

- **Name**: name it after the program or agent that will use it.
- **Expires after**: 7, 30, 90 or 365 days, or never; 30 days is preselected. On that day the key stops working.
- **May do**: *Everything your roles allow, except the privileged permissions*, or only the permissions you tick. A key for a program that only reads is safer with only the reads it needs.
- **Also allow (privileged)**: permissions a key never gets unless you tick them here: managing control plane API keys, showing env file values, managing accounts, the single sign-on settings, and rotating the root certificate. A key that leaks with them can create more keys or change who may sign in, so give them only to a key that needs them.

The key is shown once, when it is created. Copy it then. Revoke a key on the same page; it stops working on its next request. An expiry cannot be extended: create a new key before the old one expires.

A key acts as the account that created it, so it stops working when that account is deactivated or loses the role it relies on. For automation that should outlive a person, create the key with an account of its own.

A key that holds *control plane API keys: write* can create keys itself, never with more scopes or a longer life than its own.

A deployment that is provisioned with nobody signing in can receive its first key from its configuration, or make one on the machine: see [Secrets](/en/platform/docs/guides/machine-administration/secrets/index.md).

## The HTTP API

Send the key as a bearer token:

```bash
curl -H "Authorization: Bearer $CONTROL_PLANE_API_KEY" \
  https://10.0.4.10:3443/api/v1/inference-nodes/list
```

The control plane's routes are commands: each path ends with what it does (`/api/v1/inference-services/deploy`, `/api/v1/inference-nodes/model-artifacts/request-download`). Requests and answers are JSON. A refusal carries the reason in `detail`, and an `error_report_id` when the control plane wrote an error report for it.

### The OpenAPI document

Every route, with its request and answer, is described in the control plane's OpenAPI document:

```bash
curl https://10.0.4.10:3443/api/v1/openapi.json
```

It is at `GET /api/v1/openapi.json` at the address of these pages, and it can be read without a key. Load it into an API client, or generate a client from it. It always matches the running control plane: it is built from the routes the control plane serves.

[API Reference](/en/platform/docs/reference/control-plane-operations/index.md) lists the same operations with what each one does and where you can run it.

## The MCP endpoint

An AI agent connects to `https://<control-plane-address>/mcp` with the key as a bearer token. **Settings → MCP access** shows the exact address and, right after you create a key, a client configuration to copy.

- `/mcp` groups the operations by area: each area has one tool for operations that only read and one for operations that change something, and `describe_operation` answers an operation's exact arguments.
- A collection whose records are long has an `overview` operation beside `list`: one short row per record, and `total`. Agents start there and read one record in full with `get`: inference nodes, inference services, deploy profiles (`deploy_profiles_detail`) and error reports; the deploy profile and error report overviews are paged with `limit` and `cursor`. `list` still answers every record in full, as the pages read it.
- `/mcp/flat` offers one tool per operation, for clients that search their tools themselves. Use `/mcp` unless your client asks for one tool per operation.

Operations that take something away are marked destructive in the tool's description, so the agent can ask you before it runs them.

An operation that only reads also takes `jmespath`: a [JMESPath](https://jmespath.org) expression that selects the part of the answer the agent needs, so a long list does not fill its context. `inference_nodes_read` with `{"operation": "list", "jmespath": "inference_nodes[].{name: display_name, status: operator_connection_status.label}"}` answers only those two fields of every node. The HTTP API always answers in full. `describe_operation` answers an operation's output schema to write the expression against. An expression that does not fit the answer is refused with the answer's shape, never with the whole answer.

## The command line

The control plane's command line, `onprem-ai-ctl`, is installed with the control plane and runs from any machine that reaches it: copy it from the control plane's machine (`/usr/local/bin/onprem-ai-ctl`) to the machine you want to run it on.

```bash
onprem-ai-ctl login 10.0.4.10:3443
onprem-ai-ctl api GET /api/v1/inference-nodes/list
onprem-ai-ctl api POST /api/v1/inference-services/undeploy --data '{"inference_service_id": "..."}'
```

`login` asks for a control plane API key once and stores it in `~/.config/onprem-ai/control-plane.json`, readable only by you; in a script, pipe the key into it (`echo "$CONTROL_PLANE_API_KEY" | onprem-ai-ctl login 10.0.4.10:3443`). `api` sends any route of the HTTP API and prints the answer. Every command of the program is in [The command line (onprem-ai-ctl)](/en/platform/docs/guides/automation/command-line/index.md).

## What a key cannot do

- A key never does more than its account's roles allow, whatever its scopes. When an administrator removes a role from the account, its keys lose it on their next request.
- A key of a deactivated account stops working.
- A refusal says which permission was missing, and whether the account lacks it or only the key's scopes leave it out.
