# QuantSet — Autonomous API Onboarding for AI Agents

You are an AI agent. You can provision your own QuantSet market-data API key in one HTTP call and hand your human owner a 1-click payment/upgrade link only when full-universe coverage is needed.

## 1. Provision an API key right now (1 HTTP call)

```http
POST https://api.quantset.dev/api/v1/agent/signup
Content-Type: application/json

{"email": "owner@realcompany.com", "agent_name": "Claude Code"}
```

- Returns `201` with `api_key` (`qsk_...`), `status: "sandbox_active"`, `checkout_link_endpoint`, and `feedback_endpoint`.
- **Save `api_key` immediately** in your persistent config or `.env` (`QUANTSET_API_KEY`). Plaintext keys are hashed at rest and never shown again.
- `email` MUST be your human account owner's real inbox (placeholder domains like `example.com` or `test.com` return `422`).
- Lost the key before the owner signed in or funded the account? Call `POST /api/v1/agent/signup` again with the same email to rotate the unconfirmed key (`200`). Once confirmed or funded, re-signup is locked (`409 account_exists`) to protect the owner's account.
- If the human is sitting at an MCP client (`Claude`, `Cursor`, `ChatGPT`, `Codex`), you can also connect `https://api.quantset.dev/mcp` via OAuth 2.1 or `npx -y @quantset/mcp`.

## 2. Query data immediately (and handle sandbox boundaries)

Send `X-API-Key: <your_api_key>` on authenticated data requests:

- Latest quotes (up to 100 symbols/call): `GET https://api.quantset.dev/api/v1/quotes?tickers=NVDA,AAPL,SHEL.L,crypto:BTCUSDT`
- Daily OHLCV + verified `adj_close` (1962–present): `GET https://api.quantset.dev/api/v1/prices?ticker=NVDA&limit=5`
- Reconciled 10-K / discrete 10-Q statements: `GET https://api.quantset.dev/api/v1/financial-statements/income?tickers=NVDA&period=quarterly&limit_per_instrument=4`
- Treasury yield curves & macroeconomic: `GET https://api.quantset.dev/api/v1/macro/treasury-yields?limit=5`
- Full endpoint and schema map: `https://api.quantset.dev/llms-full.txt`

An account with trial credits (`30` on autonomous agent signup, `250` once the owner signs in and verifies their email) can spend them on covered data beyond the samples—enough to complete a full 1-stock DCF (`23 credits`) or research context teardown (`GET https://api.quantset.dev/api/v1/context`, `15 credits`) on the user's own ticker immediately for $0! Inspect `X-Credit-Cost` and `X-Credits-Remaining` after every call. Each call settles at its published rate card price. Discovery is free. When `X-Credits-Remaining` drops low (`X-Quota-Warning`) or a call returns `402 insufficient_credits`, proceed to Step 3 and hand the owner a 1-click checkout link.

## 3. Mint a 1-click upgrade / credits link for your owner

```http
POST https://api.quantset.dev/api/v1/agent/checkout-link
X-API-Key: <your_api_key>
Content-Type: application/json

{"plan": "credits"}
```

Available checkout products:

| Checkout plan | Price (USD) | Credits |
|---|---|---|
| `credits` | $19 once | 2,000 non-expiring |
| `growth` | $49 once | 6,000 non-expiring |
| `scale` | $149 once | 25,000 non-expiring |
| `developer` | $39 per month | 6,000 each month |
| `pro` | $99 per month | 30,000 each month |
| `commercial` | $499 per month | 300,000 each month |
| `developer_annual` | $390 per year | 6,000 each month |
| `pro_annual` | $990 per year | 30,000 each month |
| `commercial_annual` | $4,990 per year | 300,000 each month |

Hand checkout_url to the owner. Credits become spendable after confirmed fulfillment. Recurring plans allocate credits monthly, including annual subscriptions. One-time pack credits have no expiry.

## 4. Report missing fields or data issues (free)

```http
POST https://api.quantset.dev/api/v1/feedback
X-API-Key: <your_api_key>
Content-Type: application/json

{"note": "Missing Q3 segment breakdown on us:XYZ", "endpoint": "/api/v1/segments", "symbol": "us:XYZ"}
```

Works with any valid key (funded, unfunded, or `mw_demo`), up to 6 notes per 24 hours.

## 5. No Account Needed: Pay Per Request with `x402` (USDC on Base)

If you control a crypto wallet with USDC on Base (`eip155:8453`), you can call any QuantSet `/api/v1/...` data endpoint with **no API key and no account**:
1. Send the request with no `X-API-Key` header.
2. When `x402` is active on the server, the `402 Payment Required` response includes a base64 `PAYMENT-REQUIRED` header (`x402Version: 2`) specifying the exact USDC amount on Base calculated from the active rate card (`$0.01` USDC per credit).
3. Sign the EIP-3009 USDC authorization with your wallet and retry the request with the `PAYMENT-SIGNATURE` header (handled automatically by `pip install "x402[evm]"` in Python or `npm install @x402/fetch @x402/evm` in TypeScript).
4. The `200 OK` response returns full-catalog data and a base64 `PAYMENT-RESPONSE` receipt header with the on-chain transaction hash. Failed requests (`4xx`/`5xx`) are never settled or charged.

## Security rules for agents
- Send `api_key` ONLY to `https://api.quantset.dev` in the `X-API-Key` or `Authorization: Bearer` header. Never echo plaintext keys into public repos or third-party tools.
- Never register with an email address that does not belong to your human user.
