Official Rust client for the Hydrafetch web data API.
Turn any URL into clean Markdown or schema-shaped JSON. Async, typed, built on reqwest and serde. Rust 1.88+.
cargo add hydrafetchuse hydrafetch::Client;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let hf = Client::from_env()?;
let page = hf.scrape("https://example.com/article", None).await?;
println!("{}", page.markdown.unwrap_or_default());
Ok(())
}Copy your key from app.hydrafetch.com. Client::from_env() reads HYDRAFETCH_API_KEY; Client::new("hf_...") takes one directly.
The client is cheap to clone and safe to share across tasks.
use hydrafetch::{Format, ScrapeOptions};
let page = hf.scrape("https://example.com/article", Some(ScrapeOptions {
formats: Some(vec![Format::Markdown, Format::Links]),
only_main_content: Some(true),
prefer_structure: Some(true),
block_ads: Some(true),
max_age: Some(3_600_000),
..Default::default()
})).await?;Option structs implement Default, so fill in what you need and spread the rest. Fields are snake_case in Rust and serialise to the camelCase the API expects.
| Format | Field | Contains |
|---|---|---|
Format::Markdown |
markdown |
clean Markdown, the default |
Format::Html |
html |
rendered HTML |
Format::RawHtml |
raw_html |
the untouched response body |
Format::Links |
links |
every link on the page |
Format::Structured |
structured |
the page's own JSON-LD and microdata |
Format::Summary |
summary |
a short summary |
Format::Json |
json |
schema-shaped JSON |
Format::Brand |
— | the site's brand record |
Every field on ScrapeResult is an Option, because only the formats you request are populated. hf.markdown(url) returns the String directly.
use hydrafetch::ExtractOptions;
use serde_json::json;
let out = hf.extract(
&["https://example.com/product/1", "https://example.com/product/2"],
Some(ExtractOptions {
schema: Some(json!({
"type": "object",
"properties": {
"name": { "type": "string" },
"price_usd": { "type": "number" }
}
})),
..Default::default()
}),
).await?;
for item in out.results {
println!("{} {:?}", item.url, item.data);
}Set prompt instead of, or alongside, schema to describe the fields in plain language.
Sites that price or stock by delivery area serve a different page for each area. Set location to fetch as if from a country and language, and headers to send the cookie that picks the store or area, the same options scrape takes.
let out = hf
.extract(
&["https://shop.example/search?q=ghee"],
Some(ExtractOptions {
prompt: Some("every product with its size and price".into()),
location: Some(Location { country: Some("in".into()), ..Default::default() }),
headers: Some([("Cookie".to_string(), "store_id=42".to_string())].into()),
..Default::default()
}),
)
.await?;map lists a site's URLs for one credit without fetching any page.
use hydrafetch::MapOptions;
let m = hf.map("https://example.com", Some(MapOptions {
limit: Some(1000),
..Default::default()
})).await?;
let docs: Vec<&str> = m.links.iter()
.map(|link| link.url.as_str())
.filter(|url| url.contains("/docs/"))
.collect();batch and crawl submit a job, poll its progress until it finishes, then collect every page.
use hydrafetch::{BatchOptions, Format, ScrapeOptions};
let job = hf.batch(&docs, Some(BatchOptions {
scrape_options: Some(ScrapeOptions {
formats: Some(vec![Format::Markdown]),
..Default::default()
}),
..Default::default()
}), None).await?;
for page in job.pages {
let len = page.data.and_then(|d| d.markdown).map(|m| m.len());
println!("{} {:?}", page.url, len);
}Set a webhook and use start_crawl or start_batch to return immediately instead of polling.
use hydrafetch::CrawlOptions;
let id = hf.start_crawl("https://example.com", Some(CrawlOptions {
limit: Some(500),
max_depth: Some(3),
include_paths: Some(vec!["/docs".into()]),
webhook: Some("https://your.app/hooks/hydrafetch".into()),
..Default::default()
})).await?;use hydrafetch::SearchOptions;
let res = hf.search("post-quantum TLS adoption", Some(SearchOptions {
limit: Some(5),
scrape_results: Some(true),
..Default::default()
})).await?;
for r in res.results {
println!("{:?} {}", r.title, r.url);
}Find recent news articles about anything, newest first, each with its outlet and publish time:
use hydrafetch::NewsOptions;
let news = hf.news("acme raises funding", Some(NewsOptions {
time_range: Some("week".into()),
limit: Some(10),
..Default::default()
})).await?;
for article in &news.results {
println!("{} {} {}", article.published_at, article.title, article.url);
}A news search costs 1 credit, and one that finds nothing is free. Set scrape_results: Some(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:
use hydrafetch::SearchJobsOptions;
let jobs = hf.search_jobs("data engineer", Some(SearchJobsOptions {
location: Some("Berlin".into()),
posted_within_days: Some(14),
limit: Some(20),
..Default::default()
})).await?;
for job in &jobs {
println!("{} {} {}", job.title, job.domain, job.first_seen_at);
}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:
let changes = hf.hiring_changes(&["acme.com"], "2026-10-01T00:00:00Z", None).await?;
println!("{} opened, {} closed", changes[0].totals.opened, changes[0].totals.closed);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:
use hydrafetch::{CompanyResolveHints, CompanySearchOptions};
if let Some(found) = hf.enrich_company("stripe.com").await? {
let c = &found.company;
println!("{:?} {:?} {:?}", c.name, c.industry_group, c.headquarters.country);
}
hf.enrich_company_by_linkedin("https://www.linkedin.com/company/stripe/").await?;
let page = hf.search_companies(Some(CompanySearchOptions {
query: Some("payroll".into()),
countries: Some(vec!["DE".into(), "AT".into()]),
industry_groups: Some(vec!["Software Development".into()]),
employee_count_buckets: Some(vec!["11-50".into(), "51-200".into()]),
founded_year_min: Some(2015),
include_total: Some(true),
..Default::default()
})).await?;
for c in &page.results {
println!("{} {:?}", c.domain, c.name);
}
let candidates = hf.resolve_company("Stripe", Some(CompanyResolveHints {
country: Some("US".into()),
..Default::default()
})).await?;
for c in &candidates {
println!("{} {} {:?}", c.company.domain, c.score, c.matched_on);
}enrich_company returns None for a company we cannot find. enriching is true when 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:
let mut cursor = None;
loop {
let page = hf.search_companies(Some(CompanySearchOptions {
since: Some("2026-11-01".into()),
limit: Some(100),
cursor: cursor.take(),
..Default::default()
})).await?;
save(&page.results);
match page.next_cursor {
Some(next) => cursor = Some(next),
None => break,
}
}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.
use hydrafetch::{MonitorInput, MonitorPage, MonitorSchedule, MonitorTarget};
let monitor = hf
.create_monitor(&MonitorInput {
name: "Competitors".into(),
schedule: MonitorSchedule { every: "1h".into() },
targets: vec![
MonitorTarget::pages(["https://acme.com/pricing"]).goal("a plan gets cheaper"),
MonitorTarget::site("https://acme.com/blog"),
MonitorTarget::search("acme funding"),
],
..MonitorInput::default()
})
.await?;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:
let checks = hf.list_monitor_checks(&monitor.id, MonitorPage { limit: Some(1), offset: None }).await?;
let check = hf.get_monitor_check(&monitor.id, &checks[0].id).await?;
for change in &check.changes {
println!("{:?} {}", change.status, change.url);
}
hf.run_monitor(&monitor.id).await?; // check now, outside the scheduleA 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.
use hydrafetch::LogoOptions;
hf.brand("stripe.com").await?; // logos, colours, fonts, socials
hf.logo("stripe.com", Some(LogoOptions { theme: Some("dark".into()), kind: None })).await?;
hf.styleguide("stripe.com").await?; // computed design system
hf.styleguide_with("https://stripe.com/pricing", StyleguideOptions { max_age: Some(0) }).await?; // 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.
use hydrafetch::{RateResultInput, Rating};
hf.scrape("https://stripe.com/pricing", None).await?;
let mut rating = RateResultInput::for_request(hf.last_request_id().unwrap(), Rating::Bad);
rating.reasons = vec!["missing_content".into()];
rating.note = Some("The enterprise tier is missing".into());
hf.rate_result(rating).await?;
hf.rate_result(RateResultInput::for_url("https://stripe.com/pricing", Rating::Good)).await?;Reasons are missing_content, wrong_content, blocked, slow, formatting and other.
All failures are hydrafetch::Error.
match hf.scrape(url, None).await {
Ok(page) => handle(page),
Err(e) if e.is_auth() => refresh_key(),
Err(e) if e.is_out_of_credits() => top_up(),
Err(e) if e.is_invalid_request() => report(&e),
Err(e) if e.is_retryable() => enqueue(url, e.retry_after()),
Err(e) if e.is_timeout() => return Err(e.into()),
Err(e) => {
eprintln!("{} {:?} {:?}", e.code(), e.status(), e.request_id());
return Err(e.into());
}
}| 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 returns the error at once and e.retry_after() gives the seconds to wait before asking again. A job the client is following survives a dropped connection while it polls. 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.
use std::time::Duration;
let hf = Client::builder()
.api_key("hf_...")
.base_url("https://api.hydrafetch.com")
.timeout(Duration::from_secs(120))
.max_retries(2)
.build()?;| Method | Returns | Credits |
|---|---|---|
scrape(url, Option<ScrapeOptions>) |
ScrapeResult |
1 |
markdown(url) |
String |
1 |
map(url, Option<MapOptions>) |
MapResult |
1 |
search(query, Option<SearchOptions>) |
SearchResult |
1 + 1 per scraped result |
news(query, Option<NewsOptions>) |
NewsResult |
1 + 1 per article read; free when empty |
search_jobs(query, Option<SearchJobsOptions>) |
Vec<OpenJob> |
1 per 10 jobs |
hiring_changes(domains, since, Option<HiringChangesOptions>) |
Vec<CompanyHiringChanges> |
1 per company with jobs |
enrich_company(domain), enrich_company_by_linkedin(url) |
Option<CompanyData>, None when not found |
5 per company found |
search_companies(Option<CompanySearchOptions>) |
CompanySearchPage (results, next_cursor, total) |
1 per company returned |
resolve_company(name, Option<CompanyResolveHints>) |
Vec<CompanyCandidate>, best first |
1 when it returns a candidate |
extract(urls, Option<ExtractOptions>) |
ExtractResult |
5 per URL |
brand(domain) |
serde_json::Value |
5 |
logo(domain, Option<LogoOptions>) |
serde_json::Value |
1 |
styleguide(domain_or_url), styleguide_with(domain_or_url, options) |
serde_json::Value |
10 |
screenshot(url, Option<ScreenshotOptions>) |
ScreenshotResult |
5 |
images(url) |
ImagesResult |
1 |
crawl(url, opts, wait), batch(urls, opts, wait) |
Job |
1 per page |
start_crawl, start_batch |
String |
1 per page |
submit_batch(urls, options) |
BatchAccepted (batch_id, status, invalid_urls) |
1 per page |
crawl_status(id), batch_status(id); crawl_status_page(id, page), batch_status_page(id, page) to choose offset and limit |
Job, up to 500 pages; follow next_offset, or limit 0 for progress only |
free |
cancel_crawl(id), cancel_batch(id) |
Job |
free, pages not yet read are not charged |
create_monitor(&input), update_monitor(id, &changes) |
Monitor |
free; checks are charged as they run |
list_monitors(page), get_monitor(id) |
Vec<Monitor>, Monitor |
free |
run_monitor(id) |
MonitorCheckSummary |
as a scheduled check |
list_monitor_checks(id, page), get_monitor_check(id, check_id) |
Vec<MonitorCheckSummary>, MonitorCheck |
free |
delete_monitor(id) |
() |
free |
rate_result(input) |
RateResultResponse |
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 in
job.pages, and each entry holds the page under.data, sojob.pages[0].data.markdown. - Per-page options for crawl and batch belong in
scrape_options. 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. prefer_structureis off by default. Turn it on when headings, lists and tables matter; leave it off for raw article text.Nonefields are omitted from the request rather than serialised as null.- 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
- API reference on docs.rs
- OpenAPI specification
- Other clients: Node · Python · Go · Ruby · PHP
MIT