# OsApi

> Agents' calls to Railway, Neon, Supabase, Render, Vercel and GitHub are checked on your computer; dangerous ones wait for your approval.

Source: https://osevel.com/docs/products/osapi/

OsApi checks the calls an AI agent makes to these services before they leave your computer.
Reads and everyday changes go through. A call that could delete a database, its backups or a
repository, reveal a secret, or give someone access waits for you.

- [What it protects against](#what-it-protects-against)
- [Set up](#set-up)
- [How it works](#how-it-works)
- [Keys OsApi cannot see](#keys-osapi-cannot-see)
- [When a call is held](#when-a-call-is-held)
- [The OsApi page](#the-osapi-page)
- [Changing what is asked](#changing-what-is-asked)
- [Records](#records)
- [Modes](#modes)
- [With the other Os products](#with-the-other-os-products)
- [Limits](#limits)

## What it protects against

- **The dangerous call that is not SQL.** An agent with a provider token can delete a project,
  a volume or a branch through the provider's API. No database rule sees that call.
- **A token with every permission.** An account-wide token found in a file lets an agent do
  anything the account can. With OsApi the agent holds a stand-in, and each call is read first.
- **No stop before the damage.** Most infrastructure deletes cannot be undone. OsApi does not
  undo; it holds the call before it is sent.

## Set up

OsApi is part of the CLI and of [OsVault](https://osevel.com/docs/products/osvault/). It has no install step of its own.

1. Install the CLI and link this computer to your vault (see [OsVault](https://osevel.com/docs/products/osvault/#set-up)):

   ```bash
   npm i -g @osevel/cli
   ```

2. Save the provider's key in a vault. Neon (`napi_…`), Supabase Management (`sbp_…`), Vercel
   (`vcp_…`, `vca_…`), Render (`rnd_…`) and GitHub tokens are locked to their API when you save
   them. A Railway token is a plain UUID: lock it to `backboard.railway.com` yourself, in the
   "Only sent to" field.
3. Run the agent's commands with the vault's environment:

   ```bash
   osevel vault run -- railway up
   ```

4. For approvals an agent cannot give itself, install the Osevel service (daemon mode, macOS
   and Linux; see [security](https://osevel.com/docs/security/model/#two-modes-unisolated-and-daemon)). With it, the checks,
   the held calls, your rules and the records live in the service's own folder, out of the
   agent's reach. Without it, they live in your own Osevel folder, which an agent running as you
   could change.

## How it works

OsApi runs inside the OsVault run proxy. It sees a call only when the agent uses a key that
OsVault holds **locked**: the agent has a stand-in (`osv_ph_…`), and the proxy puts the real key
in on the way out, after OsApi has decided.

Each provider has a catalogue: its hosts, and every operation with a class. A REST call maps to
an operation by method and path, a GraphQL call to one operation per field, an MCP call by its
tool name. With several operations in one call, the strictest decides.

| Class     | Meaning                                                                           | What happens               |
| --------- | --------------------------------------------------------------------------------- | -------------------------- |
| `read`    | Changes nothing                                                                   | Through, recorded          |
| `change`  | Changes something that can be changed back                                        | Through, recorded          |
| `danger`  | Deletes data, backups, environments or access; reveals a secret; cannot be undone | Held for a person          |
| `unknown` | Not in the catalogue                                                              | Writes held, reads through |

The catalogues were checked against each provider's published API documents and its MCP server,
not with test accounts.

Some everyday calls are held too, because they reveal secrets, run SQL outside
[OsBase](https://osevel.com/docs/products/osbase/), or can overwrite values. Examples: `railway variables` and `railway run`
(they read variables), `vercel env pull`, SQL and migrations through the Supabase or Neon MCP
tools, reading Render environment variables, GitHub branch protection and Actions secrets. You
approve each one, or let one named operation through with a rule (below).

A call that is too large to show you whole (more than 20 held operations, or a body too large
to read) is refused instead of held: you approve only what you can see.

## Keys OsApi cannot see

A key in a `.env` file or in a CLI's own login file goes around OsApi. When the proxy sees a
covered service reached without a locked key, it records that (`unprotected`).

```bash
osevel api scan
```

lists the provider keys an agent could read and use without OsApi seeing the calls: `.env`
files, shell profiles, the environment, the CLIs' own sign-ins, git and npm credentials. For
each it says what the key can reach, as far as its format tells, and what to do. It never
prints a key, sends nothing and changes nothing. `--dir <path>` reads another folder; `--json`
prints JSON. It does not look in the system keychain.

## When a call is held

The agent is told the call was held and the hold's id. The call is not sent. You then:

- **In the panel**: Inbox → _API calls waiting_ → _Review and allow_ or _Refuse_. The review shows
  everything the call would send; you confirm with your passkey (and your phone, if enrolled).
- **At the terminal**:

```bash
sudo /opt/osevel/bin/osevel api holds
```

```bash
sudo /opt/osevel/bin/osevel api approve hold_0123456789abcdef01
```

```bash
sudo /opt/osevel/bin/osevel api deny hold_0123456789abcdef01
```

(without `sudo` and with plain `osevel` when the Osevel service is not installed). `approve`
and `deny` need an interactive terminal and a typed code; no flag skips it. `holds --all` also
lists the calls already decided.

Type the launcher's full path, not `sudo osevel`: the short form finds `node` through your
`PATH`, which an agent running as you can change to run its own code as root (see
[security.md](https://osevel.com/docs/security/model/#two-modes-unisolated-and-daemon)).

An approval lets the agent send **exactly that call once**, within 15 minutes. It is bound to
the service, the vault, environment and key, the method, the path, the query and the body. A
held call waits 15 minutes, then expires.

At most 200 calls wait at once, 20 per key and 10 per run. When the list is full the agent is
told to stop and tell you.

## The OsApi page

The panel's home shows an OsApi card once your bridge runs it. Its page lists the calls waiting
for you, services an agent reached without a locked key, the latest decisions and your rules.
The rules are read-only there; they are changed at the terminal.

## Changing what is asked

```bash
sudo /opt/osevel/bin/osevel api policy
```

lists your rules. Ask before more (`*`, `github.*` or one operation):

```bash
sudo /opt/osevel/bin/osevel api policy ask github.* --environment production
```

Ask before deploys, jobs, functions and workflows in production runs:

```bash
sudo /opt/osevel/bin/osevel api policy preset production-deploys
```

Let one dangerous operation through without asking (one operation at a time, optionally for one
resource or environment; a person types a code). Deleting data or backups and restoring over data
always ask, whatever the rules say, and so do calls that are not in the catalogue:

```bash
sudo /opt/osevel/bin/osevel api policy allow neon.branch.delete --resource br-preview-123
```

A rule for an environment applies to runs of that vault environment; an account-wide key kept in
another environment can still reach production, so prefer `--resource` for anything that lets a
call through. Where a rule that asks and a rule that allows both match, asking wins.

Remove a rule by its number with `sudo /opt/osevel/bin/osevel api policy remove <n>`. Every
change is recorded. If the rules file cannot be read, every catalogued call asks until it is
fixed.

Run without `sudo` while the service is installed, these commands say that they changed only
your own user's runs.

## Records

Every decision is written to a hash-chained record: the service, the call, how it was sorted
and what happened. No body and no key. Decisions are never dropped; in a flood only the calls
that went through are counted instead of listed.

Check that the records were not changed:

```bash
sudo /opt/osevel/bin/osevel api verify
```

It exits with code 4 when the chain is broken. The outside anchor for these records is
[OsBrain](https://osevel.com/docs/products/osbrain/)'s ledger, whose latest line is sealed in the cloud.

## Modes

OsApi holds by default. `OSEVEL_API=watch` (in the Osevel service's environment, or for one run)
lets every call through and only records what would have been held.

## With the other Os products

- [OsVault](https://osevel.com/docs/products/osvault/) holds the keys and runs the proxy OsApi lives in. No locked key, no
  check.
- [OsBrain](https://osevel.com/docs/products/osbrain/) judges every OsApi operation once more against your cross-product
  rules, lists held calls next to database approvals (`osevel brain holds`), and records your
  answers in its sealed ledger.
- [OsBase](https://osevel.com/docs/products/osbase/) guards the SQL; OsApi guards the provider's API around the database.
- [OsBox](https://osevel.com/docs/products/osbox/) signs in to remote MCP servers and keeps their tokens in the service.

## Limits

- **Only calls made with a locked key are checked.** Run `osevel api scan` to find the others.
- **A key is locked to one host.** The same key used on another host of the provider (its MCP
  host, for example) is not checked there.
- **Deploys and code go through.** A deploy, a job, an Edge Function or a workflow counts as a
  `change`, but the code it runs can read the same secrets whose direct read is held. The
  `production-deploys` preset holds them for production.
- **Setting one variable is a `change`**, although it can overwrite a value. Replacing all and
  deleting are `danger`.
- **Reads that are not in the catalogue go through.** Only unknown writes are held.
- **MCP tools are classed by name.** A tool that takes a `method` or `replace` argument is
  classed by its usual use.
- **Git over HTTPS is not read.** A force push is not a REST call and is not held.
- **Without the Osevel service**, an agent running as you can choose the run's environment,
  rewrite the held calls and records, or answer the approval prompt through a terminal it opens.
  Real approvals need the service, where deciding needs `sudo` or your passkey.
- **OsApi does not undo.** It takes no safety copy before an approved delete.
- **Not built:** agents that run in someone else's cloud, rules from `osevel.yaml`, editing
  rules in the panel, and asking a provider what a key really reaches.

Related: [OsVault](https://osevel.com/docs/products/osvault/), [OsBrain](https://osevel.com/docs/products/osbrain/), [OsBase](https://osevel.com/docs/products/osbase/), [OsBox](https://osevel.com/docs/products/osbox/),
[security model](https://osevel.com/docs/security/model/).
