# POST /extract-json: $0.03 per call

AI structured extraction: give a URL (web page, PDF, Word, Excel...) or text plus your own JSON Schema, get back JSON that fits it. POST {"url": "...", "schema": {"type": "object", "properties": {...}}, "instructions": "optional"}. Great for prices, contacts, specs, events, invoices and tables. Uses Llama 3.3 70B in JSON mode. Up to 40,000 characters of source; failures are not charged.

- **Price:** $0.03 in USDC, the same on Base, Solana, Polygon, Arbitrum. Failed calls are never charged.
- **Free trial:** no, paid only (it uses a paid AI model or data source, or costs more than the trial covers). Other ways to pay: x402 or [prepaid credits](/credits).
- **Answers cached for:** 1 hour(s)
- **Data sources:** the web; Workers AI (metered)
- **Lane:** Documents & web ([OpenAPI](/openapi/documents.json))
- **Live health:** [status page](/status)

## Free sample

See an answer for the demo input first, free (no payment, 10 a minute): [https://aayatai.com/sample/extract-json](/sample/extract-json). It is a stored real answer when we have one, otherwise an example marked `"kind": "illustrative"`.

```bash
curl "https://aayatai.com/sample/extract-json"
```

## 1. See the price (free)

Call it without paying: you get `402 Payment Required` and a `PAYMENT-REQUIRED` header with the exact price and where to pay.

```bash
curl -i -X POST https://aayatai.com/extract-json -H "content-type: application/json" -d '{"url":"https://example.com","schema":{"type":"object","properties":{"title":{"type":"string"},"purpose":{"type":"string"}},"required":["title"]}}'
```

## 2. Pay and call (TypeScript)

```bash
npm install @x402/fetch @x402/evm viem
```

```ts
import { wrapFetchWithPaymentFromConfig } from "@x402/fetch";
import { ExactEvmScheme } from "@x402/evm";
import { privateKeyToAccount } from "viem/accounts";

// A wallet used only by your agent, holding a little USDC on Base.
const account = privateKeyToAccount(process.env.WALLET_PRIVATE_KEY as `0x${string}`);
const pay = wrapFetchWithPaymentFromConfig(fetch, {
  schemes: [{ network: "eip155:8453", client: new ExactEvmScheme(account) }],
});

const res = await pay("https://aayatai.com/extract-json", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({"url":"https://example.com","schema":{"type":"object","properties":{"title":{"type":"string"},"purpose":{"type":"string"}},"required":["title"]}}),
});
console.log(await res.json());
```

## 3. Or as an MCP tool

```ts
// MCP server: https://aayatai.com/mcp (Streamable HTTP). With the x402 MCP client (see /start):
const result = await client.callTool("extract-json", {"url":"https://example.com","schema":{"type":"object","properties":{"title":{"type":"string"},"purpose":{"type":"string"}},"required":["title"]}});
```

## Inputs

- `url` (string): Page or document to read (use this or text).
- `text` (string): Text to read (use this or url).
- `schema` **(required)** (object): JSON Schema describing the JSON you want back.
- `instructions` (string): Extra guidance, e.g. 'prices in GBP, ignore ads'.

Bad inputs are rejected with HTTP 400 before any payment is asked for.

## Example answer

```json
{
  "data": {
    "title": "Example Domain",
    "purpose": "Reserved for use in documentation examples."
  },
  "model": "@cf/meta/llama-3.3-70b-instruct-fp8-fast",
  "source": {
    "url": "https://example.com/",
    "title": "Example Domain",
    "chars": 230,
    "truncated": false
  }
}
```

## Related

- [GET /markdown](/services/markdown) ($0.005): Turn any document URL into clean Markdown for LLMs: web pages, PDFs, Word (.docx), Excel (.xlsx/.xls), OpenDocument, CSV, XML and plain text, up to 10 MB.
- [GET /markdown/rendered](/services/markdown-rendered) ($0.02): Read JavaScript-heavy web pages (single-page apps, React/Vue sites, dashboards) as clean Markdown: the page is loaded in a real headless browser, scripts run, t
- [GET /extract](/services/extract) ($0.005): Fetch any public web page and get back clean Markdown, the page title and all links as JSON.

New here? [Getting started in 60 seconds](/start). All services: [Aayat AI](/).