# Sheet SQL & Multi-Tab XLSX Engine API (v1.0.0)

> Run real SQLite JOINs and window functions over messy CSV/JSON tables and export styled multi-tab .xlsx workbooks in milliseconds.

Ephemeral SQLite analytics sandbox for multi-table CSV/TSV and JSON datasets (JOINs, CTEs, window functions, automatic currency coercion) plus zero-dependency OpenXML multi-sheet .xlsx workbook generation.

## Why Agents Use This API Instead of DIY
Eliminates spinning up Python/pandas/openpyxl sandboxes, avoids LLM arithmetic hallucinations on large CSVs, strips '$1,250.50' currency strings automatically, and emits genuine frozen-header Excel formulas.

## Connection & Payment (x402 Default + Optional Bearer API Key)
- **MCP Server (Streamable HTTP):** `https://sheet-sql.apikeg.com/mcp` (Registry ID: `com.apikeg/sheet-sql` — `initialize`, `tools/list`, `resources/*`, and `prompts/*` are free)
- **OpenAPI 3.1 Spec:** [openapi.json](https://sheet-sql.apikeg.com/openapi.json)
- **Full Schema & Examples:** [llms-full.txt](https://sheet-sql.apikeg.com/llms-full.txt)
- **RFC 9727 API Catalog:** [.well-known/api-catalog](https://sheet-sql.apikeg.com/.well-known/api-catalog)
- **x402 Bazaar Manifest:** [.well-known/x402.json](https://sheet-sql.apikeg.com/.well-known/x402.json)
- **MCP Discovery Manifest:** [.well-known/mcp.json](https://sheet-sql.apikeg.com/.well-known/mcp.json)
- **A2A Agent Card:** [.well-known/agent-card.json](https://sheet-sql.apikeg.com/.well-known/agent-card.json)
- **Primary Payment (Zero Signup):** Cloudflare Monetization Gateway (`HTTP 402` / `x402` v2 with USDC on Base).
- **Optional Monthly API Key:** Pass `Authorization: Bearer ak_live_...` ($5 / $20 / $50 monthly per-product Stripe plans at [apikeg.com/account](https://apikeg.com/account)).
- **Free Preflight:** Append `?dry_run=true` (or header `X-Dry-Run: true`) to validate any request payload at `$0.00` cost.

## Tools & REST Endpoints
- [`query_tabular_data`](https://sheet-sql.apikeg.com/tools/query-tabular-data.md) (`POST https://sheet-sql.apikeg.com/v1/query-tabular-data`) — $0.002 base (up to $0.01 max $0.002 base + $0.001 per 1,000 total input rows (capped at $0.01), x402 variable settlement): Ingests 1–10 named RFC 4180 CSV/TSV or JSON row-array datasets into an ephemeral zero-retention SQLite sandbox, coerces currency columns (e.g. '$1,250.50' -> 1250.5), runs read-only SQL (JOIN, GROUP BY, CTEs, window functions), and returns typed rows, Markdown preview, inferred schemas, and optional .xlsx export.
- [`build_xlsx_workbook`](https://sheet-sql.apikeg.com/tools/build-xlsx-workbook.md) (`POST https://sheet-sql.apikeg.com/v1/build-xlsx-workbook`) — $0.003 USD per multi-sheet .xlsx workbook generation (x402 instant micropayment): Compiles 1–20 structured JSON datasets into a genuine Office Open XML (.xlsx) workbook with bold shaded headers, frozen top rows, auto-sized columns, numeric formatting, formula-injection protection, and live Excel summary formulas (SUM, AVERAGE, MIN, MAX, COUNT).

## Instant MCP Configuration
```json
{
  "mcpServers": {
    "sheet-sql": {
      "type": "streamable-http",
      "url": "https://sheet-sql.apikeg.com/mcp"
    }
  }
}
```

## Common Agent Use Cases
- run SQL query on CSV and JSON files MCP tool
- join multiple CSV tables with SQLite window functions API
- generate multi-sheet Excel xlsx workbook with SUM formulas without Python
- clean currency columns $1,250.50 and aggregate revenue CSV API
- convert JSON data to styled Excel spreadsheet API
