Official Go client for the Hydrafetch web data API.
Turn any URL into clean Markdown or schema-shaped JSON. Standard library only, no dependencies, Go 1.21+.
go get github.com/Hydrafetch/go-sdkpackage main
import (
"context"
"fmt"
"log"
hydrafetch "github.com/Hydrafetch/go-sdk"
)
func main() {
hf, err := hydrafetch.New("")
if err != nil {
log.Fatal(err)
}
page, err := hf.Scrape(context.Background(), "https://example.com/article", nil)
if err != nil {
log.Fatal(err)
}
fmt.Println(page.Markdown)
}Copy your key from app.hydrafetch.com. Passing an empty string to New falls back to HYDRAFETCH_API_KEY.
Every method takes a context.Context first, so deadlines and cancellation propagate as usual. Options structs are pointers and may be nil.
page, err := hf.Scrape(ctx, "https://example.com/article", &hydrafetch.ScrapeOptions{
Formats: []hydrafetch.Format{hydrafetch.FormatMarkdown, hydrafetch.FormatLinks},
PreferStructure: true,
BlockAds: hydrafetch.Bool(true),
MaxAge: 3_600_000,
})Options that default to on (OnlyMainContent, BlockAds, RemoveBase64Images, IncludeLinks, StoreInCache) are *bool, so leaving one unset keeps the default and hydrafetch.Bool(false) turns it off.
| Format | Field | Contains |
|---|---|---|
FormatMarkdown |
Markdown |
clean Markdown, the default |
FormatHTML |
HTML |
rendered HTML |
FormatRawHTML |
RawHTML |
the untouched response body |
FormatLinks |
Links |
every link on the page |
FormatStructured |
Structured |
the page's own JSON-LD and microdata |
FormatSummary |
Summary |
a short summary |
FormatJSON |
JSON |
schema-shaped JSON |
FormatBrand |
— | the site's brand record |
Only the formats you request are populated. hf.Markdown(ctx, url) returns the string directly.
out, err := hf.Extract(ctx,
[]string{"https://example.com/product/1", "https://example.com/product/2"},
&hydrafetch.ExtractOptions{
Schema: map[string]any{
"type": "object",
"properties": map[string]any{
"name": map[string]any{"type": "string"},
"price_usd": map[string]any{"type": "number"},
},
},
})
for _, item := range out.Results {
fmt.Println(item.URL, item.Data["name"], item.Data["price_usd"])
}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.
out, err := hf.Extract(ctx, []string{"https://shop.example/search?q=ghee"}, &hydrafetch.ExtractOptions{
Prompt: "every product with its size and price",
Location: &hydrafetch.Location{Country: "in"},
Headers: map[string]string{"Cookie": "store_id=42"},
})Map lists a site's URLs for one credit without fetching any page.
m, err := hf.Map(ctx, "https://example.com", &hydrafetch.MapOptions{Limit: 1000})
var docs []string
for _, l := range m.Links {
if strings.Contains(l.URL, "/docs/") {
docs = append(docs, l.URL)
}
}Batch and Crawl submit a job and poll until it finishes.
job, err := hf.Batch(ctx, docs,
&hydrafetch.BatchOptions{
ScrapeOptions: &hydrafetch.ScrapeOptions{
Formats: []hydrafetch.Format{hydrafetch.FormatMarkdown},
},
},
&hydrafetch.WaitOptions{
OnProgress: func(j *hydrafetch.Job) { log.Println(j.Status, j.Completed, "/", j.Total) },
})
for _, page := range job.Pages {
if page.Data != nil {
fmt.Println(page.URL, len(page.Data.Markdown))
}
}Set a Webhook and use StartCrawl or StartBatch to return immediately instead of polling.
id, err := hf.StartCrawl(ctx, "https://example.com", &hydrafetch.CrawlOptions{
Limit: 500,
MaxDepth: 3,
IncludePaths: []string{"/docs"},
Webhook: "https://your.app/hooks/hydrafetch",
})res, err := hf.Search(ctx, "post-quantum TLS adoption", &hydrafetch.SearchOptions{
Limit: 5,
ScrapeResults: true,
})
for _, r := range res.Results {
fmt.Println(r.Title, r.URL)
}Find recent news articles about anything, newest first, each with its outlet and publish time:
news, err := hf.News(ctx, "acme raises funding", &hydrafetch.NewsOptions{TimeRange: "week", Limit: 10})
for _, a := range news.Results {
fmt.Println(a.PublishedAt, a.Title, a.URL)
}A news search costs 1 credit, and one that finds nothing is free. Set 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, err := hf.SearchJobs(ctx, "data engineer", &hydrafetch.SearchJobsOptions{
Location: "Berlin",
PostedWithinDays: 14,
Limit: 20,
})
for _, j := range jobs {
fmt.Println(j.Title, j.Domain, j.FirstSeenAt)
}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:
since := time.Now().AddDate(0, -1, 0)
changes, err := hf.HiringChanges(ctx, []string{"acme.com"}, since, nil)
fmt.Println(changes[0].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, err := hf.EnrichCompany(ctx, "stripe.com")
if found != nil {
fmt.Println(found.Company.Name, found.Company.IndustryGroup, found.Company.Headquarters.Country)
}
found, err = hf.EnrichCompanyByLinkedin(ctx, "https://www.linkedin.com/company/stripe/")
page, err := hf.SearchCompanies(ctx, &hydrafetch.CompanySearchOptions{
Query: "payroll",
Countries: []string{"DE", "AT"},
IndustryGroups: []string{"Software Development"},
EmployeeCountBuckets: []string{"11-50", "51-200"},
FoundedYearMin: 2015,
IncludeTotal: true,
})
for _, c := range page.Results {
fmt.Println(c.Domain, c.Name)
}
candidates, err := hf.ResolveCompany(ctx, "Stripe", &hydrafetch.CompanyResolveHints{Country: "US"})
for _, c := range candidates {
fmt.Println(c.Company.Domain, c.Score, c.MatchedOn)
}EnrichCompany returns nil 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:
opts := &hydrafetch.CompanySearchOptions{Since: "2026-11-01", Limit: 100}
for {
page, err := hf.SearchCompanies(ctx, opts)
if err != nil {
return err
}
save(page.Results)
if page.NextCursor == nil {
break
}
opts.Cursor = *page.NextCursor
}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.
m, err := hf.CreateMonitor(ctx, hydrafetch.MonitorInput{
Name: "Competitors",
Schedule: hydrafetch.MonitorSchedule{Every: "1h"},
Targets: []hydrafetch.MonitorTarget{
{Type: "pages", URLs: []string{"https://acme.com/pricing"}, Goal: "a plan gets cheaper"},
{Type: "site", URL: "https://acme.com/blog"},
{Type: "search", Query: "acme funding"},
},
Webhook: &hydrafetch.MonitorWebhook{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:
checks, _ := hf.ListMonitorChecks(ctx, m.ID, &hydrafetch.MonitorPage{Limit: 1})
check, _ := hf.GetMonitorCheck(ctx, m.ID, checks[0].ID)
for _, c := range check.Changes {
fmt.Println(c.Status, c.URL)
}
hf.RunMonitor(ctx, m.ID) // check now, outside the schedule
hf.UpdateMonitor(ctx, m.ID, hydrafetch.MonitorChanges{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(ctx, "stripe.com") // logos, colours, fonts, socials
hf.Logo(ctx, "stripe.com", &hydrafetch.LogoOptions{Theme: "dark"}) // one asset
hf.Styleguide(ctx, "stripe.com") // computed design system
hf.Styleguide(ctx, "https://stripe.com/pricing") // one pageFor 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.
_, err := hf.Scrape(ctx, "https://stripe.com/pricing", nil)
if err != nil {
log.Fatal(err)
}
_, err = hf.RateResult(ctx, hydrafetch.RateResultInput{
RequestID: hf.LastRequestID(),
Rating: hydrafetch.RatingBad,
Reasons: []string{"missing_content"},
Note: "The enterprise tier is missing",
})
_, err = hf.RateResult(ctx, hydrafetch.RateResultInput{URL: "https://stripe.com/pricing", Rating: hydrafetch.RatingGood})Reasons are missing_content, wrong_content, blocked, slow, formatting and other.
All failures are *hydrafetch.Error. Reach it with errors.As.
page, err := hf.Scrape(ctx, url, nil)
if err != nil {
var apiErr *hydrafetch.Error
if errors.As(err, &apiErr) {
switch {
case apiErr.IsAuth():
return refreshKey()
case apiErr.IsOutOfCredits():
return topUp()
case apiErr.IsInvalidRequest():
return report(apiErr.Message)
case apiErr.IsRetryable():
return enqueue(url, apiErr.RetryAfter)
}
log.Println(apiErr.Code, apiErr.Status, apiErr.RequestID)
}
return err
}| 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 apiErr.RetryAfter holds the seconds to wait before asking again (zero when the response did not say). 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, err := hydrafetch.New("hf_...",
hydrafetch.WithBaseURL("https://api.hydrafetch.com"),
hydrafetch.WithTimeout(120*time.Second),
hydrafetch.WithMaxRetries(2),
hydrafetch.WithHTTPClient(instrumentedClient),
)| Method | Returns | Credits |
|---|---|---|
Scrape(ctx, url, *ScrapeOptions) |
*ScrapeResult |
1 |
Markdown(ctx, url) |
string |
1 |
Map(ctx, url, *MapOptions) |
*MapResult |
1 |
Search(ctx, query, *SearchOptions) |
*SearchResult |
1 + 1 per scraped result |
News(ctx, query, *NewsOptions) |
*NewsResult |
1 + 1 per article read; free when empty |
SearchJobs(ctx, query, *SearchJobsOptions) |
[]OpenJob |
1 per 10 jobs |
HiringChanges(ctx, domains, since, *HiringChangesOptions) |
[]CompanyHiringChanges |
1 per company with jobs |
EnrichCompany(ctx, domain), EnrichCompanyByLinkedin(ctx, url) |
*CompanyData, nil when not found |
5 per company found |
SearchCompanies(ctx, *CompanySearchOptions) |
*CompanySearchPage (Results, NextCursor, Total) |
1 per company returned |
ResolveCompany(ctx, name, *CompanyResolveHints) |
[]CompanyCandidate, best first |
1 when it returns a candidate |
Extract(ctx, urls, *ExtractOptions) |
*ExtractResult |
5 per URL |
Brand(ctx, domain) |
*BrandResult, nil when the domain cannot be resolved |
5 |
Logo(ctx, domain, *LogoOptions) |
*LogoResult, or nil |
1 |
Styleguide(ctx, domainOrURL, opts...) |
*StyleguideResult, or nil |
10 |
Screenshot(ctx, url, *ScreenshotOptions) |
*ScreenshotResult |
5 |
Images(ctx, url) |
*ImagesResult |
1 |
Crawl(ctx, url, *CrawlOptions, *WaitOptions) |
*Job |
1 per page |
Batch(ctx, urls, *BatchOptions, *WaitOptions) |
*Job |
1 per page |
StartCrawl, StartBatch |
string |
1 per page |
SubmitBatch(ctx, urls, opts) |
*BatchAccepted (BatchID, Status, InvalidUrls) |
1 per page |
CrawlStatus(ctx, id), BatchStatus(ctx, id); CrawlStatusPage(ctx, id, page), BatchStatusPage(ctx, id, page) to choose Offset and Limit |
*Job, up to 500 pages; follow NextOffset, or Limit 0 for progress only |
free |
CancelCrawl(ctx, id), CancelBatch(ctx, id) |
*Job |
free, pages not yet read are not charged |
CreateMonitor(ctx, input), UpdateMonitor(ctx, id, changes) |
*Monitor |
free; checks are charged as they run |
ListMonitors(ctx, page), GetMonitor(ctx, id) |
[]Monitor, *Monitor |
free |
RunMonitor(ctx, id) |
*MonitorCheckSummary |
as a scheduled check |
ListMonitorChecks(ctx, id, page), GetMonitorCheck(ctx, id, checkID) |
[]MonitorCheckSummary, *MonitorCheck |
free |
DeleteMonitor(ctx, id) |
error |
free |
RateResult(ctx, in) |
*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. Check fornilfirst. - 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.- Zero-valued option fields are omitted from the request rather than sent, so a partially filled struct behaves as expected.
- 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 · Ruby · Rust · PHP
MIT