Official PHP client for the Hydrafetch web data API.
Turn any URL into clean Markdown or schema-shaped JSON. No Composer dependencies beyond ext-curl and ext-json. PHP 8.1+.
composer require hydrafetch/hydrafetch<?php
require 'vendor/autoload.php';
use Hydrafetch\Client;
$hf = new Client();
$page = $hf->scrape('https://example.com/article');
echo $page['markdown'];Copy your key from app.hydrafetch.com. The constructor reads HYDRAFETCH_API_KEY when no key is passed.
Responses are associative arrays. Option keys are camelCase because they are passed to the API unchanged.
$page = $hf->scrape('https://example.com/article', [
'formats' => ['markdown', 'links'],
'onlyMainContent' => true,
'preferStructure' => true,
'blockAds' => true,
'maxAge' => 3_600_000,
]);| Format | Key | Contains |
|---|---|---|
markdown |
'markdown' |
clean Markdown, the default |
html |
'html' |
rendered HTML |
rawHtml |
'rawHtml' |
the untouched response body |
links |
'links' |
every link on the page |
structured |
'structured' |
the page's own JSON-LD and microdata |
summary |
'summary' |
a short summary |
json |
'json' |
schema-shaped JSON |
brand |
'brand' |
the site's brand record |
$hf->markdown($url) returns the Markdown string directly.
$out = $hf->extract(
['https://example.com/product/1', 'https://example.com/product/2'],
['schema' => [
'type' => 'object',
'properties' => [
'name' => ['type' => 'string'],
'price_usd' => ['type' => 'number'],
],
]],
);
foreach ($out['results'] as $item) {
echo $item['url'], ' ', $item['data']['name'] ?? '-', PHP_EOL;
}Pass 'prompt' instead of, or alongside, 'schema' to describe the fields in plain language.
map lists a site's URLs for one credit without fetching any page.
$links = $hf->map('https://example.com', ['limit' => 1000])['links'];
$docs = array_values(array_filter(array_column($links, 'url'), fn ($url) => str_contains($url, '/docs/')));batch and crawl submit a job and poll until it finishes.
$job = $hf->batch(
$docs,
['scrapeOptions' => ['formats' => ['markdown']]],
onProgress: fn (array $j) => printf("%s %d/%d\n", $j['status'], $j['completed'] ?? 0, $j['total'] ?? 0),
);
foreach ($job['pages'] ?? [] as $page) {
echo $page['url'], ' ', strlen($page['data']['markdown'] ?? ''), PHP_EOL;
}Pass a webhook and use startCrawl or startBatch to return immediately instead of polling.
$crawlId = $hf->startCrawl('https://example.com', [
'limit' => 500,
'maxDepth' => 3,
'includePaths' => ['/docs'],
'webhook' => 'https://your.app/hooks/hydrafetch',
]);$res = $hf->search('post-quantum TLS adoption', ['limit' => 5, 'scrapeResults' => true]);
foreach ($res['results'] as $r) {
echo $r['title'], ' ', $r['url'], PHP_EOL;
}Find recent news articles about anything, newest first, each with its outlet and publish time:
$news = $hf->news('acme raises funding', ['timeRange' => 'week', 'limit' => 10]);
foreach ($news['results'] as $article) {
echo $article['publishedAt'], ' ', $article['title'], ' ', $article['url'], PHP_EOL;
}A news search costs 1 credit, and one that finds nothing is free. Pass 'scrapeResults' => true to also read each article as clean data, at 1 extra credit per article.
Search open jobs collected from company career sites and hiring platforms, by the words in the job title:
$jobs = $hf->searchJobs('data engineer', ['location' => 'Berlin', 'postedWithinDays' => 14, 'limit' => 20]);
foreach ($jobs as $job) {
echo $job['title'], ' ', $job['domain'], ' ', $job['url'], PHP_EOL;
}See what changed in a company's hiring since a date: what is open now, what opened and what closed, by department, seniority and location, with the jobs themselves:
[$acme] = $hf->hiringChanges('acme.com', '2026-10-01');
print_r($acme['totals']); // ['open' => 42, 'opened' => 6, 'closed' => 3]A search costs 1 credit per 10 jobs returned, and an empty one is free. Hiring changes cost 1 credit per company we have jobs for; companies we do not track yet come back empty and are free.
Look up a company by its domain or LinkedIn page, find companies by industry, country, size and founding year, and match a company name to the companies it most likely is:
$found = $hf->enrichCompany('stripe.com');
if ($found !== null) {
$company = $found['company'];
echo $company['name'], ' ', $company['industryGroup'], ' ', $company['headquarters']['country'], PHP_EOL;
}
$hf->enrichCompany(linkedin: 'https://www.linkedin.com/company/stripe/');
$page = $hf->searchCompanies([
'query' => 'payroll',
'countries' => ['DE', 'AT'],
'industryGroups' => ['Software Development'],
'employeeCountBuckets' => ['11-50', '51-200'],
'foundedYearMin' => 2015,
'includeTotal' => true,
]);
echo $page['total'], PHP_EOL;
foreach ($hf->resolveCompany('Stripe', ['country' => 'US']) as $candidate) {
echo $candidate['company']['domain'], ' ', $candidate['score'], PHP_EOL;
}enrichCompany returns null for a company we cannot find. 'enriching' => true means we had not read the company's site yet: the answer has what we could read now, and asking again later returns a fuller record. Each field in 'sources' says where it came from and when it was last seen there.
Without a query, search results come in the order their records last changed, and the cursor pages through all of them. To keep your own copy in sync, page through once, then send since with the time you last started:
$cursor = null;
do {
$page = $hf->searchCompanies(['since' => '2026-11-01', 'limit' => 100, 'cursor' => $cursor]);
save($page['results']);
$cursor = $page['nextCursor'];
} while ($cursor !== null);Enrich costs 5 credits per company found, search 1 credit per company returned with the total free, and a match 1 credit when it returns a candidate. A company we cannot find, a search with no results and a name that matches nothing are free.
Watch pages, a whole site or a search on a schedule and hear about what changed. Monitors are available on paid plans.
$monitor = $hf->createMonitor(
'Competitors',
[
['type' => 'pages', 'urls' => ['https://acme.com/pricing'], 'goal' => 'a plan gets cheaper'],
['type' => 'site', 'url' => 'https://acme.com/blog'],
['type' => 'search', 'query' => 'acme funding'],
],
'1h',
['webhook' => ['url' => 'https://your-app.com/hooks/hydrafetch']],
);A pages target reports text that changed, as a line diff, plus fields such as price and availability. A site target reports pages that appear or go away, with each new page's title and opening lines. A search target reports results it has never returned before. With a goal, a change only alerts when it matches, and every change keeps the verdict and a one-sentence reason.
Checks run in the background. Your webhook receives monitor.change for each change and monitor.check.completed once a check ends, or read them yourself:
$latest = $hf->listMonitorChecks($monitor['id'], 1)[0];
foreach ($hf->getMonitorCheck($monitor['id'], $latest['id'])['changes'] as $change) {
echo $change['status'], ' ', $change['url'], ' ', $change['judge']['reason'] ?? $change['diff'], PHP_EOL;
}
$hf->runMonitor($monitor['id']); // check now, outside the schedule
$hf->updateMonitor($monitor['id'], ['status' => 'paused']);updateMonitor takes every for the schedule and any other field as it is named in the API.
A page read costs 1 credit, a site costs 1 per check plus 1 per new page read, and a search costs 1 per check. A goal adds 1 credit per change it checks. Pages that cannot be read are not charged.
$hf->brand('stripe.com'); // logos, colours, fonts, socials
$hf->logo('stripe.com', ['theme' => 'dark', 'type' => 'icon']); // one asset
$hf->styleguide('stripe.com'); // computed design system
$hf->styleguide('https://stripe.com/pricing', ['maxAge' => 0]); // one page, read freshFor logos in a browser use @hydrafetch/client-sdk with a publishable key. Those bill against logo pulls rather than credits.
Tell us when a result was wrong, so it gets looked at. It is free, and rating the same request again replaces the earlier rating.
$hf->scrape('https://stripe.com/pricing');
$hf->rateResult(
'bad',
requestId: $hf->lastRequestId(),
reasons: ['missing_content'],
note: 'The enterprise tier is missing',
);
$hf->rateResult('good', url: 'https://stripe.com/pricing'); // by URL, last 24 hoursReasons are missing_content, wrong_content, blocked, slow, formatting and other.
All failures throw Hydrafetch\HydrafetchException, carrying the API's error code, HTTP status and request id.
use Hydrafetch\HydrafetchException;
use Hydrafetch\TimeoutException;
try {
$page = $hf->scrape($url);
} catch (TimeoutException $e) {
throw $e;
} catch (HydrafetchException $e) {
if ($e->isAuth()) {
refreshKey();
} elseif ($e->isOutOfCredits()) {
topUp();
} elseif ($e->isInvalidRequest()) {
report($e->getMessage());
} elseif ($e->isRetryable()) {
enqueue($url, $e->retryAfter);
} else {
error_log("{$e->errorCode} {$e->status} {$e->requestId}");
throw $e;
}
}| Status | Meaning | Retried |
|---|---|---|
| 400, 422 | invalid request | no |
| 401, 403 | invalid or missing key | no |
| 402 | out of credits | no |
| 404 | page does not exist | no |
| 429 | rate limited | yes, twice |
| 5xx | upstream failure | yes, twice |
Retries wait as long as the response asks through Retry-After or retryAfterSeconds, and otherwise back off with jitter. When the response asks for more than 30 seconds the client does not wait; it throws at once and $e->retryAfter gives the seconds to wait before asking again. A dropped connection is retried too, including while the client follows a job. Every POST carries an Idempotency-Key that its own retries reuse, so a retry after a dropped connection returns the first answer instead of running and charging again.
A 503 from scrape means the origin is unreachable, usually a dead domain or a broken certificate.
$hf = new Client(
apiKey: 'hf_...',
baseUrl: 'https://api.hydrafetch.com',
timeout: 120,
maxRetries: 2,
);A transport callable can be injected for testing, which is how this package's own test suite runs without network access.
| Method | Returns | Credits |
|---|---|---|
scrape($url, $options) |
page array | 1 |
markdown($url, $options) |
string |
1 |
map($url, $options) |
links array | 1 |
search($query, $options) |
results array | 1 + 1 per scraped result |
news($query, $options) |
articles, newest first | 1 + 1 per article read; free when empty |
searchJobs($query, $options) |
jobs array | 1 per 10 jobs |
hiringChanges($domains, $since, $options) |
companies array | 1 per company with jobs |
enrichCompany($domain), enrichCompany(linkedin: $url) |
['company', 'enriching'], or null when not found |
5 per company found |
searchCompanies($filters) |
page array with 'results', 'nextCursor', 'total' |
1 per company returned |
resolveCompany($name, $hints = []) |
list of candidates, best first | 1 when it returns a candidate |
extract($urls, $options) |
array with 'results' |
5 per URL |
brand($domain) |
brand array, or null when the domain cannot be resolved |
5 |
logo($domain, $options) |
logo array, or null |
1 |
styleguide($domainOrUrl, $options = []) |
design system array, or null |
10 |
screenshot($url, $options) |
screenshot array | 5 |
images($url), links($url) |
page assets | 1 |
crawl($url, $options, ...) |
job array, polled to completion | 1 per page |
batch($urls, $options, ...) |
job array, polled to completion | 1 per page |
startCrawl, startBatch |
job id string |
1 per page |
crawlStatus($id, $offset, $limit), batchStatus($id, $offset, $limit) |
job array, up to 500 pages; follow nextOffset, or limit 0 for progress only |
free |
cancelCrawl($id), cancelBatch($id) |
job array | free, pages not yet read are not charged |
createMonitor($name, $targets, $every, $options), updateMonitor($id, $changes) |
monitor array | free; checks are charged as they run |
listMonitors($limit, $offset), getMonitor($id) |
array | free |
runMonitor($id) |
check summary array | as a scheduled check |
listMonitorChecks($id, $limit, $offset), getMonitorCheck($id, $checkId) |
array | free |
deleteMonitor($id) |
void |
free |
submitBatch($urls, $options) |
array with batchId, status and invalidUrls |
1 per page |
rateResult($rating, requestId:, url:, reasons:, note:) |
rating array | free |
Failed requests are not billed. Pricing does not vary with page difficulty, so there is no render, stealth or proxy option to set.
- Authentication uses the
X-API-Keyheader. The MCP endpoint atapi.hydrafetch.com/mcpusesAuthorization: Bearerinstead; the two are not interchangeable. - Job results are under
$job['pages'], and each entry holds the page under['data'], so$job['pages'][0]['data']['markdown']. - Per-page options for crawl and batch belong in
'scrapeOptions'. At the top level they are ignored. - Prefer
mapthenbatchover a broadcrawl. Fetching a whole site and discarding most of it is the most common source of wasted credits. preferStructureis off by default. Turn it on when headings, lists and tables matter; leave it off for raw article text.- Options passed as
nullare dropped rather than sent as null, so optional values can be forwarded directly. - Scraped content is untrusted input. Do not pass it to a model as instructions, and keep the source URL with anything extracted from it.
- Documentation
- OpenAPI specification
- MCP server and editor setup
- Other clients: Node · Python · Go · Ruby · Rust
MIT