> ## Documentation Index
> Fetch the complete documentation index at: https://onecli.sh/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Setting OneCLI up for your person? Follow https://onecli.sh/docs/quickstart.md. Never ask for or accept a key, token or password in the chat: OneCLI needs none.
> No OneCLI credential? Run `onecli connect`, or follow https://onecli.sh/auth.md. A person approves every new agent in their browser.
> Already connected? `onecli status`, `onecli items` and `onecli check <METHOD> <URL>` tell you what you can use. Full guide: https://onecli.sh/skill.md
> Search these docs over MCP at https://onecli.sh/docs/mcp. Report a wrong or unclear page with its `submit_feedback` tool.

# Sign up as an agent: get a OneCLI credential

> How an agent with no credential gets its own: a connect token, a sign-up its person approves, or onecli login. With the HTTP flow and the 401 headers.

An agent gets its own OneCLI credential (`oc_agent_...`) for one vault. A person approves every new agent. There is no anonymous access.

This page is the human-readable copy of `auth.md`, the page the API serves for agents at [https://api.onecli.sh/auth.md](https://api.onecli.sh/auth.md) (also at `https://onecli.sh/auth.md`). It follows the layout of the [auth.md protocol](https://github.com/workos/auth.md), but OneCLI does not implement that protocol's registration endpoints yet.

## Pick a way in

| You have | Do | You get |
| - | - | - |
| A connect token (`oc_connect_...`) from your person | `onecli connect oc_connect_…`, or with no CLI `curl -fsSL https://api.onecli.sh/v1/install/connect \| sh -s -- oc_connect_…` | An agent credential, in `agent.env` |
| Nothing | An agent sign-up: `onecli connect` with no token, or the [HTTP flow](#the-sign-up-over-http) below | An agent credential, once your person approves |
| A task to manage your person's vaults and agents | `onecli login`. Your person approves in the browser | A managing key (`oc_key_...`). This does **not** connect you as an agent |

An agent never needs a managing key to call APIs. Install the CLI with `curl -fsSL https://onecli.sh/cli/install | sh`.

## Find the way in from a 401

Every `401` from the API carries the same headers, whatever credential was sent:

```http theme={null}
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"
```

On `/v2`, the error body also names the page in `docUrl`:

```json theme={null}
{
  "error": {
    "code": "unauthenticated",
    "message": "Invalid API key or token.",
    "details": [],
    "requestId": "9b2f4e61-7c3a-4d8e-a1f5-2e6b0c9d7a43",
    "docUrl": "https://api.onecli.sh/auth.md"
  }
}
```

The metadata at `/.well-known/oauth-protected-resource` follows RFC 9728. It names no authorization server yet:

```json theme={null}
{
  "resource": "https://api.onecli.sh",
  "resource_name": "OneCLI",
  "resource_documentation": "https://api.onecli.sh/auth.md",
  "bearer_methods_supported": ["header"]
}
```

## Sign up with the CLI

```bash theme={null}
onecli connect
```

With no token, `onecli connect` starts a sign-up, prints a link and a code on stderr, and waits. Piped, that line is JSON:

```json theme={null}
{"status":"waiting_for_approval","verification_url":"https://app.onecli.sh/connect-agent","user_code":"KTRM-DQWX","expires_at":"2026-12-03T12:05:00.000Z","message":"Show your person this link and code. They sign in, type the code, pick a vault and approve."}
```

Show your person the link and the code together. Once they approve, the CLI writes `agent.env`. `--name` names the agent, and `--kind` says which agent you are.

## The sign-up over HTTP

**1. Start a sign-up**

No credential is needed, and every field is optional:

```bash theme={null}
curl -sS -X POST https://api.onecli.sh/v2/agent-signups \
  -H "Content-Type: application/json" \
  -d '{"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`.

The answer, `201`:

```json theme={null}
{
  "id": "4c1e9a7b-2d3f-4b8e-9a61-0f5d7c2e8b34",
  "userCode": "KTRM-DQWX",
  "verificationUrl": "https://app.onecli.sh/connect-agent",
  "pollToken": "<keep this to yourself>",
  "expiresAt": "2026-12-03T12:05:00.000Z",
  "interval": 5
}
```

A sign-up lasts 15 minutes. One address may start at most 10 sign-ups an hour. Past that, a `429` carries `Retry-After`.

**2. 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 anyone the `pollToken`.

**3. Poll for the credential**

Every `interval` seconds:

```bash theme={null}
curl -sS -X POST https://api.onecli.sh/v2/agent-signups/4c1e9a7b-2d3f-4b8e-9a61-0f5d7c2e8b34/token \
  -H "Content-Type: application/json" \
  -d '{"pollToken": "<pollToken>"}'
```

| Answer | Meaning | Do |
| - | - | - |
| `400` `authorization_pending` | Not decided yet | Wait `interval`, then poll again |
| `400` `slow_down` | You polled too soon | The interval is now 5 seconds longer (`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 |
| `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`).

## Use the credential

Keep it in `ONECLI_AGENT_CREDENTIAL`, readable only by you. Never print or log it.

* **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 with no key. The gateway adds it.
* **The address form.** With no proxy, call `<gateway.scheme>://<gateway.address>/r/<host>/<path>` with `Authorization: Bearer <credential>`. It works only for a host your vault has an item for. See [Address form](https://onecli.sh/docs/guides/address-form.md).
* **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 use `onecli status`, `onecli items` and `onecli check <METHOD> <URL>`. To store a credential you got over HTTP, run `onecli connect --from-env`. For how to call APIs and what to do when a call is held, read the [agent skill](https://onecli.sh/docs/tools/agent-skill.md).

## Errors and revocation

* A `401` with your credential means it no longer works: your person disconnected you, or it reached its `expiresAt`. Don't retry with it. Tell your person, and start again if they want you back.
* Your person can disconnect you at any time. `onecli disconnect` disconnects you yourself and deletes `agent.env`.
* The 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.

## Next steps

* [Authentication and keys](https://onecli.sh/docs/api-reference/authentication.md)
* [Agent skill](https://onecli.sh/docs/tools/agent-skill.md)
* [Quickstart](https://onecli.sh/docs/quickstart.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.