# SchemaMedic — deterministic data normalization for agents

**Production API:** https://schema-medic-eclipselio.onrender.com
**OpenAPI:** https://schema-medic-eclipselio.onrender.com/openapi.json
**x402 manifest:** https://schema-medic-eclipselio.onrender.com/.well-known/x402
**Price:** $0.02 native USDC per complete request, Base mainnet (eip155:8453).
**Free preview:** https://schema-medic-eclipselio.onrender.com/v1/preview

## When to use
Use when a buyer-controlled input of up to 120,000 characters is CSV, TSV, JSON, or JSONL and needs a deterministic conversion to JSON, CSV or JSONL; whitespace trimming; exact duplicate-row removal; duplicate-header disambiguation; completely empty row removal; row-count reporting and output SHA-256 digest. The service does not invent missing values, enforce types, perform AI reasoning or store data intentionally.

## API contract
POST JSON to `/v1/preview` (free first 3 output rows) or `/v1/normalize` (full, x402 payment required).

Request:
```json
{"format":"csv","output":"json","input":"name,city\nAda,Athens\nAda,Athens\nBob,Patras","dedupe":true,"trim":true,"dropEmpty":true}
```

Response (after normalizing):
```json
{"ok":true,"input_format":"csv","output_format":"json","columns":["name","city"],"input_rows":3,"output_rows":2,"duplicates_removed":1,"empty_rows_removed":0,"column_mismatches":0,"content":"[{\"name\":\"Ada\",\"city\":\"Athens\"},{\"name\":\"Bob\",\"city\":\"Patras\"}]","output_sha256":"64-char lowercase sha256"}
```
This example SHA-256 field is descriptive, not a literal output.

On a valid **unpaid** request, the paid route returns HTTP 402 with an x402 V2 PAYMENT-REQUIRED challenge containing the price, recipient and Base USDC asset. The caller must decide whether to pay. A compatible client signs its own USDC payment authorization and resubmits the **identical** body with a PAYMENT-SIGNATURE header. Never fabricate or reuse signed authorizations, and do not mistake HTTP 402 for a charge.

## Optional paid schema quality audit — $0.05 USDC

POST `/v1/profile` with the same `{"format":"csv","input":"..."}` request and an optional `baseline`:

```json
{"format":"csv","input":"id,amount\n1,20\n1,20\n2,",
 "baseline":{"fields":[{"name":"id","type":"number","required":true},
                       {"name":"amount","type":"number","required":true}]}}
```

The result contains deterministic missing counts, distinct-value counts, duplicate detection, type mixtures, numeric ranges and any baseline column/type drift. It also returns normalized content and its SHA-256. This endpoint returns a $0.05 Base USDC x402 challenge on an unpaid request. Call it only after the buyer approves the price.

## Limits and cautions
Maximum input: 120k characters, 2,000 records, 80 columns. Nested JSON values are serialized for CSV output. Spreadsheet formula-like CSV fields are prefixed with an apostrophe to reduce formula execution risk. Use the free preview before authorizing the paid request. The free-tier server may cold-start. Do not send credentials or personal data. A valid x402 402 quote is **not** proof of a settled sale.
