# LLM Margin authentication

## Public estimation
POST /api/estimate and the Streamable HTTP MCP endpoint /mcp are public and stateless. They do not save quote inputs. No credentials are needed. Rate limit: 120 public agent requests per IP per minute. A 429 means retry after one minute.

## Private quote access with OAuth 2.1
Authorization server: https://llmmargin.com
Metadata: https://llmmargin.com/.well-known/oauth-authorization-server
Protected resource: https://llmmargin.com/agent
Resource metadata: https://llmmargin.com/.well-known/oauth-protected-resource
Authorize: https://llmmargin.com/authorize
Token: https://llmmargin.com/oauth/token
Dynamic client registration: https://llmmargin.com/oauth/register
Private MCP: https://llmmargin.com/agent/mcp

Use authorization_code with PKCE S256, a random state value, and resource=https://llmmargin.com/agent. Native clients may use loopback HTTP redirects; remote redirects must be HTTPS. Clients can use registration or HTTPS Client ID Metadata Documents. The user signs in with their email code on our website and explicitly approves the requested scopes. Never collect their email code or browser cookie in an agent.

Scopes: quotes:read reads private quotes; quotes:write creates and updates drafts and includes read access; offline_access requests a refresh token. Access tokens expire after one hour. Refresh tokens expire after 30 days. Send Authorization: Bearer TOKEN to /agent/quotes or /agent/mcp. Keep tokens secret. Users can revoke connections from /account. Rate limit: 60 private agent requests per user per minute.

## Ownership, payments, and exports
Tokens only access the approving user's quotes. Updates require the current revision; stale writes return 409. Export requires an active Pro plan or a confirmed $29 purchase for that quote; otherwise 402. Agents cannot initiate checkout or pay. The user reviews /quote/{id} and pays through Stripe. Client proposal HTML is printable to PDF; CSV is internal and includes costs. Nothing is emailed to a client automatically.

Browser cookie routes under /api/quotes are for the first-party website; third-party agents must use OAuth, not copied cookies. OAuth tokens do not grant billing access or permit changing account identity.
