# AI Structured Data Extractor: URL to JSON (`opstoolkit/ai-structured-extractor`) Actor

Turn web pages or text into structured JSON without selectors. Give URLs and the fields you want, a JSON Schema or a sentence. Get one validated row per page, or a list from listing pages. Numbers as numbers, missing as null. About $0.005 per page all in.

- **URL**: https://apify.com/opstoolkit/ai-structured-extractor.md
- **Developed by:** [Elio Saliba](https://apify.com/opstoolkit) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $4.00 / 1,000 page extracteds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## AI Structured Data Extractor: URL to JSON

Give it page URLs, or text you already have, and say what you want out of them. You get one JSON row per page: typed values, checked against your schema, with every field marked as found on the page, inferred, or missing.

You say what you want in one of three ways: a field list ("title, price as a number, in stock yes or no"), a JSON Schema, or a plain sentence. For category pages and directories, switch to list mode and get an array of records from one page.

**$0.004 per page, plus the AI model's cost, about $0.005 in all.** A page that cannot be read, or whose JSON stays invalid after one retry, costs nothing.

### Who it is for

- People who would otherwise write a Cheerio or Playwright scraper for each site.
- AI agent builders who need "URL in, JSON out" as one tool call.
- Sales-ops and research teams that pull the same fields from 200 similar pages: pricing pages, job posts, product specs, company pages.
- Anyone with markdown, text or HTML from another Actor who wants it as rows.

### How it works

1. It checks the site's `robots.txt`. A page that robots.txt disallows is skipped.
2. It fetches the page with a plain HTTP request, removes navigation, footers and banners, and turns the main content into text with tables kept.
3. It cuts the text to your page size limit (6,000 tokens by default) and sends it to the model with your schema.
4. It checks the answer against the schema. If the JSON is broken or the types are wrong, it asks once more, quoting what was wrong.
5. It compares each value with the page text. A value that appears on the page is `found`. A value the model produced from the page but that is not written there (a date it reformatted, a yes/no) is `inferred`. A value the page does not state is `null` and `missing`.

Everything runs through Apify's AI proxy. You do not need an OpenAI or Google key.

### Use it from an AI agent

In Claude, ChatGPT or Cursor, add the Apify MCP server (https://mcp.apify.com) and ask the agent to run this Actor. It takes URLs plus `fields` (a list like `price: number`), a `schema`, or `instructions` in plain English, so the agent can fill it from your sentence.

Example prompt: "Use the Apify Actor opstoolkit/ai-structured-extractor on these 5 product page URLs and return title, price as a number and whether it is in stock."

### Input

| Field | What it does |
|---|---|
| `urls` | Pages to read. |
| `texts` | Text or HTML you already have, one entry per page. Nothing is fetched. |
| `datasetId` and `field` | Read the text from an Apify dataset, for example the output of [Website to Markdown](https://apify.com/opstoolkit/website-to-markdown-rag). A `url` field in the row is copied to the output. |
| `fields` | One per line: `name` or `name: type`. Types: string, number, integer, boolean, date, url, email, list. Add a hint after a dash: `price: number - price in GBP`. |
| `schema` | A JSON Schema, for nested objects, enums and descriptions. Wins over `fields`. |
| `instructions` | Plain English. With no fields and no schema, the model picks the keys from this text. |
| `mode` | `single` (one record per page, the default) or `list` (an `items` array per page). |
| `model` | GPT-4.1 nano (default), Gemini 3.1 Flash-Lite or GPT-5 mini. `customModel` takes any other OpenRouter model ID that Apify's proxy allows. |
| `maxTokensPerPage` | Longer pages are cut here. Default 6,000. |
| `maxPages` | Upper limit for pages read in one run. Default 100. |

```json
{
  "urls": [{ "url": "https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html" }],
  "fields": ["title", "price: number - price in GBP", "in_stock: boolean", "upc"]
}
```

With a JSON Schema and list mode:

```json
{
  "urls": [{ "url": "https://books.toscrape.com/catalogue/category/books/poetry_23/index.html" }],
  "mode": "list",
  "schema": {
    "type": "object",
    "properties": {
      "title": { "type": "string" },
      "price": { "type": "number", "description": "Price in GBP" },
      "detail_url": { "type": "string" }
    },
    "required": ["title", "price"]
  }
}
```

A field the page does not state comes back as `null`. That means `required` in your schema means "the key is there", not "the page must have it", so a missing value never makes the whole row fail.

### Output

One row per page.

```json
{
  "url": "https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html",
  "status": "ok",
  "data": {
    "title": "A Light in the Attic",
    "price": 51.77,
    "in_stock": true,
    "upc": "a897fe39b1053632"
  },
  "fieldStatus": { "title": "found", "price": "found", "in_stock": "inferred", "upc": "found" },
  "valid": true,
  "reason": null,
  "model": "openai/gpt-4.1-nano",
  "tokensIn": 1150,
  "tokensOut": 38,
  "charged": "item-extracted"
}
```

| Column | Notes |
|---|---|
| `status` | `ok`, or the reason the page gave nothing: see below. |
| `data` | The record, or `null`. In list mode the rows have `items` and `itemCount` instead, and `fieldStatus` counts found, inferred and missing per field. |
| `fieldStatus` | `found`, `inferred` or `missing` for each field. Check `inferred` values before you rely on them. |
| `valid` | The answer passed your schema. |
| `reason` | A note: which fields were missing, that the page was cut, that a list may be incomplete. |
| `tokensIn`, `tokensOut`, `aiCostUsd`, `aiCalls` | What the model used for this page, including the retry. |
| `charged` | The event charged for this row, or `null` when the row was free. |

The key-value store holds a `SUMMARY` with counts per status, total tokens and the model cost the proxy reported.

#### Status values

All of these are free rows.

| Status | Meaning |
|---|---|
| `robots_disallowed` | The site's robots.txt does not allow this page. |
| `needs_browser` | The page is built by JavaScript, so a plain fetch finds almost no text. |
| `login_required` | The page asks for a login. |
| `blocked` | The site refused the request (403, 429) or showed a bot check. These are not bypassed. |
| `not_found`, `fetch_failed`, `invalid_url`, `unsupported_type` | The page is gone, unreachable, not a web address, or not a web page (a PDF, for example). |
| `empty_page` | The page has almost no text. |
| `no_match` | The model found none of your fields on the page. |
| `invalid_output` | The model's JSON was still invalid after one retry. `rawReply` shows the start of it. |
| `ai_error` | The model call failed, for example no credit left. |
| `skipped_max_cost` | Not run, because your max cost per run was reached. |

For `needs_browser` pages, render them with a browser Actor, then pass the HTML in `texts`.

### Pricing

| Event | Price | When |
|---|---|---|
| Item extracted | $0.004 | One URL or HTML page that returned valid JSON with at least one field found |
| Text extracted | $0.002 | One pasted text or dataset row that did the same |

The AI model's cost is billed to your Apify account separately, at the model's own price, as usage of Apify's OpenRouter Actor. At the default model's list price (GPT-4.1 nano, $0.10 per million input tokens and $0.40 per million output tokens), a page at the 6,000-token limit costs about $0.0008. A typical product page is 1,500 tokens and costs about $0.0003. So a page costs about $0.005 in total on a paid plan. Free-plan accounts pay 10 times the model cost, which makes it about $0.012.

The max cost per run you set covers this Actor's charges. It does not cover the model usage. A run stops before it starts a page it cannot charge for, so you do not pay model cost for rows you would not receive.

### Limits

- It fetches plain HTML. Pages that need JavaScript, a login or a CAPTCHA come back as a free row that says so.
- The model can get a value wrong. `fieldStatus` flags values that are not written on the page, and the prompt tells the model to return `null` instead of guessing. For anything that matters, spot check a sample.
- If Apify's proxy refuses one of the three listed models, the run switches to the next listed one and says so in the log. A model ID you type in `customModel` is never swapped.
- One answer is capped at 2,048 tokens by Apify's AI proxy. In list mode the Actor asks for the rest in follow-up calls, up to 4 more. Very long lists come back with a note that they may be incomplete.
- Text beyond `maxTokensPerPage` is not read. The row says so.
- Requests to one website are spaced at least half a second apart, and a `Crawl-delay` in robots.txt is respected up to 10 seconds. There are no proxies and no anti-bot measures.
- You are responsible for having the right to process the content of the pages you give it. The Actor does not filter personal data out of pages.

### Works well with

- [Website to Markdown for AI](https://apify.com/opstoolkit/website-to-markdown-rag) and [Document to Markdown for AI](https://apify.com/opstoolkit/document-to-markdown-rag): crawl a site or convert PDFs, then set `datasetId` to that dataset and `field` to `markdown` to get one record per page or file.
- [Image and PDF OCR](https://apify.com/opstoolkit/image-pdf-ocr): read scans and photos first, then set `field` to `text` to extract invoice or form fields.
- [Audio and Podcast Transcriber](https://apify.com/opstoolkit/audio-podcast-transcriber): transcribe episodes, then set `field` to `text` and ask for pull quotes and topics.
- [Dataset Cleaner](https://apify.com/opstoolkit/dataset-cleaner): clean the extracted rows. Turn on "Flatten nested objects" so `data.price` becomes a column, then dedupe and fix dates.

Questions or a page it gets wrong? Open an issue on the Actor page with the URL and the fields you asked for.

# Changelog

This Actor's version history is a separate document: https://apify.com/opstoolkit/ai-structured-extractor/changelog.md

# Actor input Schema

## `urls` (type: `array`):

Pages to read, as a list of objects with a url key. Example: \[{"url": "https://example.com/product/42"}]. Each page is fetched with a plain HTTP request after checking robots.txt. Pages that need a login or a browser come back as a free row that says why. Give at least one of urls, texts or datasetId. Up to 2,000 per run.

## `texts` (type: `array`):

Optional. Text, markdown or HTML you already have, one string per page. Example: \["<h1>Acme Pro</h1><p>Price: $49</p>"]. Nothing is fetched. Billed as 'text extracted'. Use this for pages that need a browser: render them elsewhere, then paste the HTML here.

## `datasetId` (type: `string`):

Optional. The ID of an Apify dataset whose rows hold the text, for example the output of Website to Markdown or Image and PDF OCR. Example: "aBcDeFgHiJkLmNoPq". Needs 'Field with the text' too. Rows read are capped by Max pages.

## `field` (type: `string`):

Name of the dataset field that holds the text, markdown or HTML. Example: markdown (Website to Markdown output) or text (OCR output). Required with datasetId, ignored otherwise. If the row also has a url field, it is copied to the output.

## `fields` (type: `array`):

The fields you want back, one per item: a name, or name: type, with an optional hint after a dash. Types: string, number, integer, boolean, date, url, email, list. Example: \["title", "price: number - price in GBP", "in_stock: boolean"]. Ignored when you give a JSON Schema. If you give neither, write instructions and the model picks the keys.

## `schema` (type: `object`):

A JSON Schema object, used instead of the field list when you need nested objects, enums or per-field descriptions. Example: {"type":"object","properties":{"title":{"type":"string"},"price":{"type":"number"}},"required":\["title"]}. The model's answer is checked against it. Fields the page does not state come back as null, so 'required' means the key is present, not that the page had it.

## `instructions` (type: `string`):

Optional plain English guidance for the model. Example: "Only the main product, not the related ones. Prices in USD." With no fields and no schema, the model picks the keys from this text, so describe what you want, for example "company name, founding year and headquarters city".

## `mode` (type: `string`):

single: one record per page (product page, article, company page). list: a list of records from one page (category page, table, directory), returned as an items array in the row. Default: single.

## `model` (type: `string`):

Model that reads the page, one of openai/gpt-4.1-nano (default, cheapest, fine for clearly labelled pages), google/gemini-3.1-flash-lite (messy pages), openai/gpt-5-mini (best accuracy). All run through Apify's AI proxy and the model cost is billed to your Apify account at cost. Replaced by customModel when that is set.

## `customModel` (type: `string`):

Optional, advanced. Any model ID from openrouter.ai/models, for example x-ai/grok-4.3. It replaces the AI model choice above. Apify's proxy only allows models with zero data retention, so some IDs are refused and the run fails with a message. Leave empty to use the AI model setting.

## `maxTokensPerPage` (type: `integer`):

Longest page text sent to the model, in tokens (about 4 characters each). A whole number from 500 to 60000. Longer pages are cut here, the content after the cut is not read, and the row says so. Raise it for long pages, lower it to spend less. Default: 6000.

## `maxPages` (type: `integer`):

Most URLs, texts and dataset rows read in this run. A whole number from 1 to 2000, for example 50. The rest are skipped, with a warning in the log. Default: 100.

## `maxConcurrency` (type: `integer`):

How many pages are processed at the same time. A whole number from 1 to 20. Requests to one website are still spaced at least half a second apart. Default: 5.

## `includeLinks` (type: `boolean`):

When true, link addresses stay in the page text so the model can return URLs (needed for url fields and detail links in list mode). Set false to send fewer tokens when you need no links. Default: true.

## Actor input object example

```json
{
  "urls": [
    {
      "url": "https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html"
    }
  ],
  "fields": [
    "title",
    "price: number - price in GBP",
    "in_stock: boolean",
    "upc"
  ],
  "mode": "single",
  "model": "openai/gpt-4.1-nano",
  "maxTokensPerPage": 6000,
  "maxPages": 100,
  "maxConcurrency": 5,
  "includeLinks": true
}
```

# Actor output Schema

## `rows` (type: `string`):

No description

## `summary` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "urls": [
        {
            "url": "https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html"
        }
    ],
    "fields": [
        "title",
        "price: number - price in GBP",
        "in_stock: boolean",
        "upc"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("opstoolkit/ai-structured-extractor").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "urls": [{ "url": "https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html" }],
    "fields": [
        "title",
        "price: number - price in GBP",
        "in_stock: boolean",
        "upc",
    ],
}

# Run the Actor and wait for it to finish
run = client.actor("opstoolkit/ai-structured-extractor").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "urls": [
    {
      "url": "https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html"
    }
  ],
  "fields": [
    "title",
    "price: number - price in GBP",
    "in_stock: boolean",
    "upc"
  ]
}' |
apify call opstoolkit/ai-structured-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,opstoolkit/ai-structured-extractor"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/zVRBx4TY4fPVXurzt/builds/LdGDTqr0RIWPlvMNW/openapi.json
