# auth.md: get OneCLI access as an agent

You are an agent. This page says how to get your own OneCLI credential.

OneCLI gives agents access to APIs without handing them keys. A person
keeps apps and keys in a vault. You connect to one vault, and the OneCLI
gateway adds the credential to your calls on the way out.

A person approves every new agent in their browser. There is no
anonymous access and no way in without a person.

This page follows the layout of the auth.md protocol
(https://github.com/workos/auth.md). OneCLI does not implement that
protocol's registration endpoints yet. Follow the steps below instead.

## Service

- API: https://api.onecli.sh
- Where your person approves you: https://app.onecli.sh/connect-agent
- Your credential: `oc_agent_...`. It is yours alone. Never print it,
  log it or send it anywhere but OneCLI.
- A managing key (`oc_key_...`) belongs to a person and manages their
  vaults and agents. You never need one to call APIs.
- Docs: https://onecli.sh/docs/llms.txt

## Step 1: discover

A call to the API with no valid credential answers 401 with:

```http
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="OneCLI", resource_metadata="https://api.onecli.sh/.well-known/oauth-protected-resource"
Link: <https://api.onecli.sh/auth.md>; rel="help"
```

`https://api.onecli.sh/.well-known/oauth-protected-resource` (RFC 9728) names no
authorization server yet. Its `resource_documentation` is this page.

## Step 2: pick a way in

1. **Your person gave you a connect command or token** (`oc_connect_...`).
   Run `onecli connect <token>`. With no CLI:
   `curl -fsSL https://api.onecli.sh/v1/install/connect | sh -s -- <token>`.
   You are done: skip to Step 6.
2. **You have nothing.** Start a sign-up: Steps 3 to 5. With the CLI,
   `onecli connect` with no token does Steps 3 to 5 for you.
3. **You act for your person, managing their vaults and agents.** Run
   `onecli login`. Your person approves in the browser, and the CLI keeps
   a managing key. That does not connect you as an agent.

Install the CLI: `curl -fsSL https://onecli.sh/cli/install | sh`.

## Step 3: register

No credential needed. Every field is optional.

```http
POST https://api.onecli.sh/v2/agent-signups
Content-Type: application/json

{"name": "release-bot", "runtime": "linux", "kind": "claude"}
```

- `name`: 1 to 64 characters. Unset: the server picks one.
- `runtime`: `docker`, `linux`, `macos` or `windows`. Default `linux`.
- `kind`: which agent you are, such as `claude`, `codex` or `cursor`.

Answer, 201:

```json
{
  "id": "<sign-up id>",
  "userCode": "KTRM-DQWX",
  "verificationUrl": "https://app.onecli.sh/connect-agent",
  "pollToken": "<keep this to yourself>",
  "expiresAt": "<15 minutes from now>",
  "interval": 5
}
```

At most 10 sign-ups an hour from one address: a 429 carries
`Retry-After`.

## Step 4: your person approves

Show your person `verificationUrl` and `userCode` together, in one
message. They sign in (or create an account), type the code, pick a vault
and approve. Never show them, or anyone, the `pollToken`.

## Step 5: poll

```http
POST https://api.onecli.sh/v2/agent-signups/<id>/token
Content-Type: application/json

{"pollToken": "<pollToken>"}
```

Send it every `interval` seconds until the answer is final:

| Answer | Meaning | Do |
| --- | --- | --- |
| 400 `authorization_pending` | Not decided yet | Wait `interval`, poll again |
| 400 `slow_down` | Too soon | The interval is 5 seconds longer now (`Retry-After`) |
| 400 `access_denied` | Your person said no | Stop. Ask before you start again |
| 400 `expired_token` | The sign-up is over | Start a new one at Step 3 |
| 401 `unauthenticated` | Wrong id or poll token | Stop |
| 200 | You are connected | Keep `credential`. It is shown once |

The 200 answer holds your agent (`id`, `name`, `vaultId`, `expiresAt`),
your `credential` and `gateway` (`address` and `scheme`).

## Step 6: use your credential

Keep it in `ONECLI_AGENT_CREDENTIAL`, readable only by you.

- **The proxy.** Set `HTTPS_PROXY` to
  `<gateway.scheme>://x:<credential>@<gateway.address>` and trust the
  OneCLI certificate from `https://api.onecli.sh/v1/gateway/ca`. Call APIs at their
  normal addresses and send no key: the gateway adds it.
- **The address form.** With no proxy, call
  `<gateway.scheme>://<gateway.address>/r/<host>/<path>` with
  `Authorization: Bearer <credential>`. Only for a host your vault has
  an item for.
- **What you can use.** `GET /v2/agents/me`, `GET /v2/agents/me/items`
  and `POST /v2/agents/me/check`, with `Authorization: Bearer <credential>`.

With the CLI, `onecli connect` writes all of this to `agent.env`. Then
`onecli status`, `onecli items` and `onecli check <METHOD> <URL>`.
How to call APIs, and what to do when a call is held: https://api.onecli.sh/v2/skill

## Errors and revocation

- A 401 with your credential means it no longer works: your person
  disconnected you, or it reached its `expiresAt`. Do not retry with it.
  Tell your person, and start again at Step 2 if they want you back.
- Your person can disconnect you at any time. `onecli disconnect`
  disconnects you yourself and deletes `agent.env`.
- Your credential does not refresh. With no `expiresAt`, it works until
  you are disconnected.

## Not supported yet

- The auth.md registration types `identity_assertion` (ID-JAG),
  `service_auth` and `anonymous`.
- An OAuth authorization server and token endpoint for agents.
