Official Ruby client for the Hydrafetch web data API.
Turn any URL into clean Markdown or schema-shaped JSON. Standard library only, no dependencies, Ruby 3.0+.
gem install hydrafetchOr in a Gemfile:
gem "hydrafetch"require "hydrafetch"
hf = Hydrafetch::Client.new
page = hf.scrape("https://example.com/article")
puts page["markdown"]Copy your key from app.hydrafetch.com. The constructor reads HYDRAFETCH_API_KEY when no key is passed.
Responses are plain hashes with string keys. Option names are camelCase because they are passed to the API unchanged; client options such as poll_interval: and job_timeout: are snake_case.
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" }
}
})
out["results"].each do |item|
puts [item["url"], item.dig("data", "name")].join(" ")
endPass 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 = links.map { |link| link["url"] }.select { |url| url.include?("/docs/") }batch and crawl submit a job and poll until it finishes.
job = hf.batch(docs,
scrapeOptions: { "formats" => ["markdown"] },
on_progress: ->(j) { puts "#{j["status"]} #{j["completed"]}/#{j["total"]}" })
job["pages"].each do |page|
puts [page["url"], page.dig("data", "markdown")&.length].join(" ")
endPass a webhook and use start_crawl or start_batch to return immediately instead of polling.
crawl_id = hf.start_crawl("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)
res["results"].each do |r|
puts [r["title"], r["url"]].join(" ")
puts r.dig("data", "markdown").to_s[0, 500]
endFind recent news articles about anything, newest first, each with its outlet and publish time:
news = hf.news("acme raises funding", timeRange: "week", limit: 10)
news["results"].each { |a| puts "#{a["publishedAt"]} #{a["title"]} #{a["url"]}" }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.search_jobs("data engineer", location: "Berlin", postedWithinDays: 14, limit: 20)
jobs.each { |job| puts "#{job["title"]} #{job["domain"]} #{job["url"]}" }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.hiring_changes("acme.com", "2026-10-01").first
puts 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.enrich_company("stripe.com")
if found
company = found["company"]
puts "#{company["name"]} #{company["industryGroup"]} #{company.dig("headquarters", "country")}"
end
hf.enrich_company(linkedin: "https://www.linkedin.com/company/stripe/")
page = hf.search_companies(
query: "payroll",
countries: %w[DE AT],
industryGroups: ["Software Development"],
employeeCountBuckets: %w[11-50 51-200],
foundedYearMin: 2015,
includeTotal: true
)
puts page["total"]
page["results"].each { |c| puts c["domain"] }
hf.resolve_company("Stripe", country: "US").each do |c|
puts "#{c.dig("company", "domain")} #{c["score"]} #{c["matchedOn"].join(", ")}"
endenrich_company returns nil 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 = nil
loop do
page = hf.search_companies(since: "2026-11-01", limit: 100, cursor: cursor)
save(page["results"])
cursor = page["nextCursor"]
break unless cursor
endEnrich 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.create_monitor(
"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" }
],
every: "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.list_monitor_checks(monitor["id"], limit: 1).first
hf.get_monitor_check(monitor["id"], latest["id"])["changes"].each do |c|
puts [c["status"], c["url"], c.dig("judge", "reason") || c["diff"]].join(" ")
end
hf.run_monitor(monitor["id"]) # check now, outside the schedule
hf.update_monitor(monitor["id"], status: "paused")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.rate_result("bad",
request_id: hf.last_request_id,
reasons: ["missing_content"],
note: "The enterprise tier is missing")
hf.rate_result("good", url: "https://stripe.com/pricing") # by URL, last 24 hoursReasons are missing_content, wrong_content, blocked, slow, formatting and other.
All failures raise Hydrafetch::Error, carrying the API's error code, HTTP status and request id.
begin
page = hf.scrape(url)
rescue Hydrafetch::TimeoutError
raise
rescue Hydrafetch::Error => e
return refresh_key if e.auth?
return top_up if e.out_of_credits?
return report(e.message) if e.invalid_request?
return enqueue(url, e.retry_after) if e.retryable?
warn [e.code, e.status, e.request_id].join(" ")
raise
end| 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 raises at once and e.retry_after gives the seconds to wait before asking again. A dropped connection is retried too, including while the client follows a job, and a job that fails is never started a second time. 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 = Hydrafetch::Client.new("hf_...",
base_url: "https://api.hydrafetch.com",
timeout: 120,
max_retries: 2)| Method | Returns | Credits |
|---|---|---|
scrape(url, **options) |
page hash | 1 |
markdown(url, **options) |
String |
1 |
map(url, **options) |
links hash | 1 |
search(query, **options) |
results hash | 1 + 1 per scraped result |
news(query, **options) |
articles, newest first | 1 + 1 per article read; free when empty |
search_jobs(query, **options) |
array of jobs | 1 per 10 jobs |
hiring_changes(domains, since, **options) |
array of companies | 1 per company with jobs |
enrich_company(domain), enrich_company(linkedin: url) |
{"company", "enriching"}, or nil when not found |
5 per company found |
search_companies(**filters) |
page hash with "results", "nextCursor", "total" |
1 per company returned |
resolve_company(name, **hints) |
array of candidates, best first | 1 when it returns a candidate |
extract(urls, **options) |
hash with "results" |
5 per URL |
brand(domain) |
brand hash | 5 |
logo(domain, **options) |
logo hash | 1 |
styleguide(domain_or_url, **options) |
design system hash | 10 |
screenshot(url, **options) |
screenshot hash | 5 |
images(url), links(url) |
page assets | 1 |
crawl(url, **options) |
job hash, polled to completion | 1 per page |
batch(urls, **options) |
job hash, polled to completion | 1 per page |
start_crawl, start_batch |
job id String |
1 per page |
crawl_status(id, offset:, limit:), batch_status(id, offset:, limit:) |
job hash, up to 500 pages; follow nextOffset, or limit: 0 for progress only |
free |
cancel_crawl(id), cancel_batch(id) |
job hash | free, pages not yet read are not charged |
create_monitor(name, targets, every:, **options), update_monitor(id, **changes) |
monitor hash | free; checks are charged as they run |
list_monitors(limit:, offset:), get_monitor(id) |
array, monitor hash | free |
run_monitor(id) |
check summary hash | as a scheduled check |
list_monitor_checks(id, limit:, offset:), get_monitor_check(id, check_id) |
array, check hash | free |
delete_monitor(id) |
nil |
free |
submit_batch(urls, **options) |
hash with batchId, status and invalidUrls |
1 per page |
rate_result(rating, request_id:, url:, reasons:, note:) |
rating hash | 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"], sojob.dig("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
nilare 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 · Rust · PHP
MIT