# Smolny Authentication Guide (AUTH.md)

> Machine-readable authentication and authorization specification for AI agents, SDKs, CLI, and Hosted MCP on `smolny.tech` / `api.smolny.tech`.

## 1. Authentication Methods

| Method | Best For | Endpoint / Header |
|---|---|---|
| **Agent Device Flow (Zero-Friction)** | Autonomous coding & browser agents | `POST https://api.smolny.tech/v1/auth/agent-signup` |
| **Scoped Bearer API Key** | REST API, Python/JS/Go SDKs, Hosted MCP | `Authorization: Bearer <SMOLNY_PROVIDER_TOKEN>` |
| **Yandex ID OAuth 2.0 + PKCE** | Human dashboard login + 2,000 RUB starter credit | `https://api.smolny.tech/dashboard` |

## 2. Agent Self-Signup (Device Flow)

```bash
curl -fsSL -X POST https://api.smolny.tech/v1/auth/agent-signup \
  -H 'Content-Type: application/json' \
  -d '{"client":"agent","label":"coding-agent"}'
```

Present `verification_url` to the user to approve once via Yandex ID, then poll:

```bash
curl -fsSL "https://api.smolny.tech/v1/auth/agent-signup/<request_id>?poll_token=<poll_token>"
```

## 3. SDK & Hosted MCP Authentication

- **Python (`pip install smolny-provider`):** reads `SMOLNY_PROVIDER_TOKEN` or `SMOLNY_PROVIDER_TOKEN_FILE`.
- **JavaScript / TypeScript (`npm install smolny-provider`):** `new SmolnyClient({ baseUrl: "https://api.smolny.tech", token: process.env.SMOLNY_PROVIDER_TOKEN })`.
- **Hosted MCP (`https://api.smolny.tech/mcp`):** Streamable HTTP JSON-RPC 2.0 with `Authorization: Bearer <SMOLNY_PROVIDER_TOKEN>`.
- **Direct Secrets:** `POST /v1/project/secrets` — AES-256-GCM vault with `allowed_domains`; raw tokens never enter VMs.
