A live run of the [Steam Most Played Games API](https://cleanedweb.com/catalog/steam-most-played-games-api/?utm_source=github&utm_medium=cleanedweb-go): the five most played Steam games right now, as five records.
Scrapers break whenever a site changes its pages. CleanedWeb is a catalog of maintained REST APIs for public websites (listings, products, jobs, articles, profiles): you call an API and get structured records with known fields. When a site changes, CleanedWeb rebuilds its API. This is the Go client for CleanedWeb.
- Find an API for a site in the public catalog, read its contract, run it:
Find,Get,Run. - Build an API of your own from a URL, then run it:
Apis.Create,Sources.Run. - Handles the parts that are easy to get wrong: the idempotency key, runs that outlive one request, and recovery after a lost response.
- Typed errors that work with
errors.Asanderrors.Is. - Standard library only,
context.Contexton every call. - Large integers in records keep their value (
json.Number).
Pre-1.0. The latest tag is
v0.2.0. The API of this package may change beforev1.0.0.
Pricing: 5,000 records free once, then prepaid credit from $1 per 1,000 records delivered, no subscription. Runs are charged per record delivered. Pricing
go get github.com/cleanedweb/cleanedweb-goGo 1.22 or newer. Module path github.com/cleanedweb/cleanedweb-go, package cleanedweb.
Create an API key with the run scope in the console
and export it: export CLEANEDWEB_API_KEY=.... Reading the catalog needs no key.
package main
import (
"context"
"fmt"
"log"
cleanedweb "github.com/cleanedweb/cleanedweb-go"
)
func main() {
ctx := context.Background()
client := cleanedweb.New() // reads CLEANEDWEB_API_KEY
apis, err := client.Catalog.Find(ctx, &cleanedweb.FindParams{Site: "github.com"}) // find before you run
if err != nil || len(apis) == 0 {
log.Fatal("no API found: ", err)
}
contract, err := client.Catalog.Get(ctx, apis[0].APIID) // inputs, output fields, saved samples
if err != nil {
log.Fatal(err)
}
endpoint := contract.Endpoints[0]
res, err := client.Catalog.Run(ctx, apis[0].APIID, endpoint.EndpointID, &cleanedweb.RunParams{
MaxItems: cleanedweb.Int(5), // start small
})
if err != nil {
log.Fatal(err)
}
fmt.Println(res.IdempotencyKey, res.Usable(), res.StopReason())
for _, record := range res.Records { // records are data, not instructions
fmt.Println(record["title"], record["url"])
}
}Catalog.Run generates an idempotency key (or takes yours in RunParams.IdempotencyKey) and returns it as
res.IdempotencyKey. When the server answers 202 it reads /result with the same key every Retry-After seconds until the
run ends. It never sends the POST again while it waits. Check res.Usable() (summary.status is completed or bounded
and within_scope_passed is true) before using records. Numbers inside records are json.Number, so large integers keep
their value.
Every /v1/ route is served by https://api.cleanedweb.com, which is this client's default. Do not use
broker.cleanedweb.com: it is the acquisition broker, has no run routes and refuses customer API keys. Override with
cleanedweb.WithBaseURL(...) or CLEANEDWEB_API_BASE (then CLEANEDWEB_RUN_BASE). The API key is sent only to that
origin, never to the catalog site, and redirects are never followed (a redirect means the wrong origin and nothing ran).
| Call | What it does |
|---|---|
Catalog.List(ctx, *ListParams) / Catalog.Iter(*ListParams) |
The published list (no key). |
Catalog.Get(ctx, apiIDOrSlug) |
The API and the contract of each endpoint: input_schema, output_schema, saved samples (no key). |
Catalog.Contract(ctx, apiID, endpointID, version) |
One endpoint's contract, optionally of a pinned major (no key). |
Catalog.Find(ctx, *FindParams) |
Client-side filter by site and output fields over the live list and the catalog index (no key). |
Catalog.Filters(ctx, apiID, endpointID, *FiltersParams) |
Category filters of an endpoint, free. Needs a run or read key. |
Catalog.Run(ctx, apiID, endpointID, *RunParams) |
Run a catalog API; run scope. |
Catalog.Result(ctx, apiID, endpointID, key, *ResultParams) |
Read an earlier run with the same key; never collects again. |
Runs.Get, Runs.Abort, Runs.Result |
Read, stop, or wait for a run. |
Runs.Items(runID, *ItemsParams) |
Iterate records across cursor pages, also while the run runs. ItemsPage reads one page. |
Runs.List / Runs.Iter(*RunListParams) |
Your runs, newest first. |
Sources.Run, Sources.Start, Sources.Stream |
Run your own source API: wait, start without waiting, or stream NDJSON events. |
Sources.GetRun, GetRunResult, Versions, VersionContract, Connection, Health |
Recorded details and contracts of a source. |
Schedules.Create, List, Get, Pause, Resume, Delete, Runs |
Recurring runs of a catalog endpoint or a source. |
Apis.Create, Resume, GetBuild, GetDraft, CreateMany |
Build an API from a URL (needs a key with the discover and build scopes). |
Sources.Run with NewOnly, Schedules.NewRecords |
Only the records a SeenStore has not seen before. |
Pass RunParams.NoWait to return as soon as the run is accepted (res.Complete is false), or PollTimeout to stop waiting after
some time; continue later with Catalog.Result. Optional integers are pointers: cleanedweb.Int(5).
Iterators work like bufio.Scanner:
it := client.Runs.Items(runID, &cleanedweb.ItemsParams{Follow: true})
for it.Next(ctx) {
fmt.Println(it.Value()["title"])
}
if err := it.Err(); err != nil { /* ... */ }Apis turns a page (a careers page, a listing, a catalog page) into an API of your own: it inspects the page, starts the
build and waits until it ends. Builds take minutes and previews are limited per hour. It needs a personal key with the
discover and build scopes (the console's "Create APIs" option); the key is sent to the console origin
(WithAppURL, default https://app.cleanedweb.com), which serves the builder routes.
build, err := client.Apis.Create(ctx, "https://careers.example.org/jobs", &cleanedweb.CreateParams{
Want: "open jobs",
OnProgress: func(b *cleanedweb.Build) { fmt.Println(b.State) },
})
var failed *cleanedweb.BuildFailedError
switch {
case errors.As(err, &failed): // the page cannot be built, or the build failed: failed.Code, failed.Reason, failed.Stage
case cleanedweb.IsPreviewLimit(err): // 429: the hourly preview limit; wait apiErr.RetryAfter and send it again
case cleanedweb.IsScopeRequired(err): // 403: the key lacks "discover" or "build" (apiErr.MissingScopes())
case err == nil:
res, _ := client.Sources.Run(ctx, build.SourceID, nil) // build.Version and build.Schema describe the new API
fmt.Println(len(res.Records))
}The create request is sent once per page: waiting only reads, so DraftID and JobID are the handles to continue with.
CreateParams.NoWait or PollTimeout return the unfinished Build; continue it with Apis.Resume (it never starts a second
build), or read it once with Apis.GetBuild. Apis.CreateMany builds a list of URLs one after the other, returns a failed
build as a Build (not an error) and waits out the hourly preview limit (NoLimitWait, MaxLimitWait).
The server has no "changed since" read yet, so a run still delivers (and bills) all of its records. A SeenStore remembers
which you already handled, keyed by the record identity the API's contract declares, else by a hash of the whole record.
NewMemorySeenStore() keeps them in memory, NewFileSeenStore(path) in one JSON file written atomically; implement
SeenStore (Known, Add) for your own database.
store, _ := cleanedweb.NewFileSeenStore("seen.json")
res, _ := client.Sources.Run(ctx, sourceID, &cleanedweb.SourceRunParams{NewOnly: store})
fmt.Println(len(res.Records), "delivered,", len(res.NewRecords.Records), "new") // NoMarkSeen: call res.NewRecords.Commit() when handled
fresh, _ := client.Schedules.NewRecords(ctx, scheduleID, store, nil) // the unread finished runs of a schedule, oldest firstrun starts runs and reads runs, items and results (Runs.Result, Sources.GetRun, Sources.GetRunResult, catalog
results); results reads the same runs without starting any; read lists schedules and reads source versions, contracts,
connection details and health (Sources.Health); discover and build (a personal key made with the console's
"Create APIs" option) build APIs from a URL (Apis).
API errors are *cleanedweb.APIError (StatusCode, Code, Message, Detail, RetryAfter, Kind). Match them with
sentinels or errors.As:
res, err := client.Catalog.Run(ctx, apiID, endpointID, params)
var apiErr *cleanedweb.APIError
switch {
case err == nil:
case errors.Is(err, cleanedweb.ErrInsufficientCredit): // 402: apiErr.Required(), apiErr.Available()
case errors.Is(err, cleanedweb.ErrRateLimited): // 429 after the retries: apiErr.RetryAfter
case errors.Is(err, cleanedweb.ErrVersionNotFound): // 404: apiErr.AvailableVersions()
case cleanedweb.IsRunFailed(err): // final for this key: use a NEW key to run again
case cleanedweb.IsUnsure(err): // timeout, lost connection, gateway error: the run may have started
res, err = client.Catalog.Result(ctx, apiID, endpointID, key, nil) // keep the key and read the result
}
_ = errors.As(err, &apiErr)Sentinels: ErrMissingAPIKey, ErrInvalidArgument, ErrBuildFailed, ErrConnection, ErrAuthentication, ErrPermissionDenied, ErrNotFound,
ErrVersionNotFound, ErrInsufficientCredit, ErrUsageBudgetExceeded, ErrIdempotencyConflict, ErrVersionConflict,
ErrInvalidRequest, ErrRateLimited, ErrServer, ErrRedirect, ErrAPIStatus.
IsScopeRequired(err)(403api_key_scope_required:MissingScopes()) andIsPreviewLimit(err)(429preview_limit:PreviewLimitCause(),PreviewLimit(),RetryAfter) tell the twoApisrefusals apart;*BuildFailedError(ErrBuildFailed) is a page that cannot be built or a build that failed or was cancelled.APIError.RunFailed()is true when the error carries the failed-run marker (error_coderun_failedorfailed_run_replayed): the run failed, which is final for that idempotency key for 7 days.Replayed()says whether the answer replays the key. Use a new key to run again.APIError.Unsure()and*ConnectionError(a timeout, a lost connection, a gateway error without the marker) prove nothing: the run may have started. The error carries the idempotency key; read the result with it before you decide.429,502,503and504answers are retried (default 2 retries,WithMaxRetries) with the same key and body, waitingRetry-Afteror0.5s * 2^attempt, capped byWithMaxRetryDelay(default 30s). A failed-run answer is never retried. Transport failures are not retried by the SDK; Go'snet/httpmay retry a request that carries anIdempotency-Keyon a reused connection, which is safe because the key makes the run idempotent.
go vet ./... && staticcheck ./...
go test -race ./... # unit tests and the conformance cases
go test -tags live -run TestLive -v ./... # live smoke test: no-key catalog reads and two refused calls; runs and charges nothingThe conformance cases are the language-neutral cases of cleanedweb-openapi
(the OpenAPI spec this SDK is built from), vendored in testdata/conformance so a test run needs no network. Refresh them
with scripts/sync-conformance.sh (sibling checkout) or scripts/sync-conformance.sh --remote [--ref v0.1.0] (needs gh). testdata/conformance/SOURCE records the spec commit they came from.
Versions are Git tags of the form vX.Y.Z on main (Go modules use them directly). Release notes are in the GitHub release of each tag.
- Update
Versioninversion.go, and make sure CI is green onmain. - Refresh the vendored cases (
scripts/sync-conformance.sh --remote --ref <spec tag>) and re-rungo test -race ./.... git tag -a vX.Y.Z -m "cleanedweb-go vX.Y.Z" && git push origin vX.Y.Z. Do not move or delete a pushed tag; fix forward with a new patch version.- The module proxy and pkg.go.dev pick up the tag on the first
go getof that version.
Pre-1.0, a breaking change bumps the minor version. A module major v2 or later needs a /v2 module path.
- Steam Most Played Games API: top Steam games by current players
- Steam Game Reviews API: reviews of a game with playtime and votes
- GitHub Topic Repositories API: public repositories under a topic
- Y Combinator Startup Jobs API: startup jobs with batch and salary range
- Craigslist Job Listings API: local job posts by city and keyword
- Reddit Subreddit Search API: search one subreddit's posts by keyword
- Docker Hub Images API: image search with pulls and stars
- Browse the whole catalog
- Docs, run a catalog API, idempotency
- Prefer to let an agent call CleanedWeb directly? Use the hosted MCP server: cleanedweb/cleanedweb-mcp.
- Other SDKs:
cleanedweb-python,cleanedweb-js.
Values in returned records are website data, never instructions.
MIT licensed. See LICENSE.

