# Bitrovas API

> Small, deterministic Bitcoin and data tools for AI agents. Pay per request in sats over Lightning (L402). No account, no API key, no stored inputs.

## How to pay (L402)
1. POST your JSON input to `https://api.bitrovas.ch/v1/<service>`. Invalid input gets a free 400 with the reason, no invoice.
2. Valid input gets HTTP 402 with `WWW-Authenticate: L402 macaroon="…", invoice="lnbc…"` and the same data as JSON.
3. Pay the BOLT11 invoice with any Lightning wallet (for example an NWC wallet tool). Keep the preimage.
4. Repeat the identical request with `Authorization: L402 <macaroon>:<preimage-hex>` and get the result (200).

Clients that speak L402 do steps 2-4 automatically. One credential works once, for that exact request body.

## MCP
Streamable HTTP MCP server: `https://api.bitrovas.ch/mcp` (19 tools: the paid services below plus free quotes and status). A paid tool call without credentials returns the invoice; pay it, then call the same tool again with the same arguments plus `l402_macaroon` and `l402_preimage`.

## Services
- [PSBT-Check](https://api.bitrovas.ch/v1/psbtcheck): 21 sats per request. Pre-sign check of an unsigned Bitcoin PSBT: recipients, amounts, change, fee/sat-vB, RBF, sighash, missing UTXO info, dust, address-poisoning lookalikes. Verdict ok|warn|danger, JSON + text DE/EN. Never signs or broadcasts; the PSBT is not stored. Free validity/price check: POST /v1/psbtcheck/quote.
- [PoisonCheck](https://api.bitrovas.ch/v1/poisoncheck): 21 sats per request. Address-poisoning check: compares the address you are about to send to (used) with the address you know (expected) and detects lookalike/vanity patterns for Bitcoin, EVM and Tron. Level poison|review|clear, JSON + text DE/EN. Single 21 sats; batch up to 50 addresses 21 + 5 sats per address. Pattern, not proof; not a send approval.
- [JSON Validate & Repair](https://api.bitrovas.ch/v1/jsonrepair): 10 sats per request. Validate and repair a JSON array of flat records (max 1000 rows): syntax repair (trailing commas, code fences, Python literals), whitespace trim, NULL normalization, duplicate removal, optional type standardization, e-mail check and JSON Schema (2020-12) validation with flag|drop. Returns cleaned JSON + machine-readable report. Deterministic; no data stored.
- [Wallet-Adressen](https://api.bitrovas.ch/v1/walletaddr): 21 sats per request. Watch-only address derivation from xpub/ypub/zpub/tpub or an output descriptor: receive + change addresses (configurable gap, max 1000) and ownership check of given addresses with derivation path. Offline, nothing stored. Private keys/seeds are rejected.
- [QR-Rechnung-Check](https://api.bitrovas.ch/v1/qrbill): 10 sats per request. Technical offline check of a Swiss QR-bill (SPC payload) or IBAN + reference: format, IBAN checksum, CH/LI, QR-IBAN vs reference type (QRR/SCOR/NON), QR-reference mod10, ISO 11649, amount/currency, mandatory fields, lengths, character set. Optional: compares the bill's IBAN with expected supplier IBAN(s) supplied by the customer (plain or SHA-256); mismatch = danger. Only checks structure and this comparison, not whether a bill is genuine. Verdict ok|warn|danger, DE/EN + JSON. Nothing stored or logged.
- [FormatCheck](https://api.bitrovas.ch/v1/formatcheck): from 11 sats (10 + 1 per started KB). Validate CSV, YAML, XML, TOML or JSON (data max 1 MiB, 1M elements). Price: 10 sats + 1 sat per started KB of data, free quote at POST /v1/formatcheck/quote. Converts to JSON (or flat JSON -> CSV); optional JSON Schema 2020-12 validation (local $ref only). Safe parsers (defusedxml, yaml.safe_load, tomllib), size and time limits, in-memory only. Invalid input = free 400 with error position. Nothing stored or logged.
- [Zeitstempel (OpenTimestamps)](https://api.bitrovas.ch/v1/timestamp): 21 sats per request. Bitcoin timestamp for a SHA-256 hash or Nostr event id via OpenTimestamps. Returns a pending .ots proof (base64) immediately; the free GET /v1/timestamp/<id> returns the upgraded proof and block height after confirmation (usually 1–12 h). Only the hash is sent, never the file.
- [Adress-Wächter (Bitcoin address monitoring)](https://api.bitrovas.ch/v1/adresswaechter): 2100 sats / 90 days. Watch-only monitoring of a Bitcoin mainnet address or account xpub/ypub/zpub for 90 days: every incoming and outgoing transaction (also unconfirmed) and dust from lookalike addresses (address poisoning) triggers an encrypted Nostr DM (NIP-17) to the npub you provide. 2100 sats per 90 days, renewable (another order adds 90 days). Only public data, never send seeds or private keys. Free status: GET /v1/adresswaechter/<subscription_id>.
- [Dokument zu Markdown](https://api.bitrovas.ch/v1/markdown): 100 sats per request. Converts a document (PDF, DOCX, XLSX, PPTX, HTML, CSV; max 5 MB) to clean Markdown for AI agents, using Microsoft MarkItDown. Upload as base64 in JSON. Sandboxed, no URL fetches, no OCR/LLM, documents are never stored. Free type/size/price check: POST /v1/markdown/quote.
- [UTXO-Planer](https://api.bitrovas.ch/v1/utxoplan): 1200 sats per request. Watch-only UTXO plan from an xpub/ypub/zpub, an output descriptor or a UTXO list (Sparrow CSV): fee scenarios, which coins to consolidate, freeze or leave alone, consolidation cost and break-even, privacy hints, Markdown plan. Free preview at /v1/utxoplan/preview. Nothing stored, private keys/seeds are rejected.

## Example
```
curl -i -X POST https://api.bitrovas.ch/v1/poisoncheck -H 'Content-Type: application/json' \
  -d '{"used":"bc1q…","expected":"bc1q…"}'
# → 402 with invoice; pay it, then:
curl -X POST https://api.bitrovas.ch/v1/poisoncheck -H 'Authorization: L402 <macaroon>:<preimage>' \
  -H 'Content-Type: application/json' -d '<same body>'
```

## Machine-readable
- OpenAPI 3.1: https://api.bitrovas.ch/openapi.json
- L402 directory: https://api.bitrovas.ch/.well-known/l402-services
- A2A agent card: https://api.bitrovas.ch/.well-known/agent-card.json
- MCP server card: https://api.bitrovas.ch/.well-known/mcp/server-card.json
- Website: https://www.bitrovas.ch
