Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Engine KDL Specification

This document specifies the KDL format for defining generic engines in data/engines.kdl. Generic engines are parsed by go-server/generic_engine.go and registered alongside hand-written engines (Brave, Google, etc.) at startup. A single engines.kdl file defines all ~274 generic engines.

Engine block structure

Each engine is a top-level engine node with a quoted string ID and a child block of properties:

engine "my_engine" {
    name "My Engine Display Name"
    categories "web" "news"
    search-url "https://example.com/search?q={query}&page={page}"
    method "GET"
    result-type "json"
    results-path "data.items"
    title-path "title"
    url-path "link"
    content-path "description"
    page-size 20
    paging true
    first-page 1
}

The engine ID (the string after engine) is the unique identifier used in logs, cache keys, weight cookies, and the admin UI. It must be a short slug (lowercase, underscores allowed).

Attributes reference

Identity

AttributeTypeRequiredDefaultDescription
namestringNoSame as IDHuman-readable display name shown in engine badges and the settings page.
categoriesstring listYes(none – engine is skipped if empty)Space-separated quoted category slugs. Valid values: web, images, videos, news, music, science, it, files, maps, social, books, qa / q&a, packages, weather, lyrics, marketplace. An engine with no parseable categories is silently skipped during registration.
safe-searchstringNo""What the engine can return at safe search Moderate or Strict: "family" (nothing to filter: code, docs, reference, science, maps; asked at every level) or "moderate" (little to filter: news, books, music, stores; asked at Moderate, not Strict). An engine with neither is not asked at Moderate or Strict.
safe-valuesstringsNo(none)What {safesearch} becomes at None, Moderate and Strict, for an engine with a filter of its own, e.g. safe-values "both" "false" "false" (PeerTube’s nsfw) or safe-values "" "&nsfw=false" "&nsfw=false". An engine with them is asked at every level, when its search-url or body-template holds {safesearch}; without it they are ignored, which the load says. With safe-search "moderate" too, it is asked at Moderate with its filter and not at Strict (the boorus, 7TV).

Request

AttributeTypeRequiredDefaultDescription
search-urlstringYes–URL template. Placeholders: {query} (URL-encoded query), {page} / {pageno} (page number = (page-1) + first-page), {offset} (offset = (page-1) * page-size + first-page), {lang} and {country} (the region’s language and country, from go-server/regions.tsv; en and us for all), {safesearch} (the person’s level, 0, 1 or 2, or what safe-values says for it), {query_json} (the words as the inside of a JSON string, then URL-encoded: for a JSON value carried in the address, as Pinterest’s search is; in a body-template, {query} is already JSON-escaped).
methodstringNo"GET"HTTP method. "GET" or "POST".
body-templatestringNo""POST body template (same placeholders as search-url). Only used when method is "POST".
{query_path}placeholderNo—In search-url, the query encoded as {query} is but a space as %20, not +: for a path segment (pixiv’s /illustrations/{query_path}) or a site that refuses + (Rumble’s q=).
before-paramstringNo""Added to the address (after &) when a search has a Before date (?before=YYYY-MM-DD, before_date.go), e.g. filter=to_publication_date:{before_last}. Placeholders: {before} (2012-01-01), {before_last} (the last day included, 2011-12-31), {before_last_ymd} (that day as 20111231), {before_unix} (the cutoff in unix seconds).
before-querystringNo""Added to the words of the search when it has a Before date, for engines whose date bound is query syntax, e.g. " AND submittedDate:[199101010000 TO {before_last_ymd}2359]". Same placeholders. Either way, rows dated on or after the cutoff are dropped afterwards.
time-paramstringNo""Added to the address (after &) when a search has a time range (past day, week, month or year), e.g. created_after={since_unix}. Placeholders: {since_date} (the range’s first day, 2026-10-25), {since_unix} (its midnight UTC in unix seconds) and {time} (from time-values). An engine with it, or with {time} in its search-url, is asked over a time range (time_range.go); one with neither is asked only if its rows carry dates (published-path, date-selector), and is held to them.
time-valuesstringsNo(none)What {time} becomes, in the address or in time-param: without a time range, then for a past day, week, month and year, in that order, e.g. time-values "all" "day" "week" "month" "year". A range whose value is "" is not sent, and the engine is then asked for it only if its rows carry dates.
near-biasstringNo""For a map engine: added to the address when the search reads “X near Y”, “X around Y” or “X in Y” (for “in”, Y a town or city, not a state, country or island), Y is a clear place, and the person may use the map or Places card. The engine is then asked for X (common words translated, e.g. coffee → cafe) instead of the whole phrase. Placeholders: {lat}, {lon} (Y’s point) and {bbox} (about 5 km either side, as west,south,east,north), e.g. &bbox={bbox}&lat={lat}&lon={lon} (Photon) or &viewbox={bbox}&bounded=1 (Nominatim).
headerssub-blockNo(none)Custom HTTP headers as key-value pairs. Default headers (User-Agent, Accept, Accept-Language, DNT) are always sent; entries here override or add to them.
first-visitstringNo""A page whose visit hands every visitor the cookies the engine’s search wants (Bilibili’s home page sets buvid3 and b_nut; its search answers 412 without them). This server visits it as itself (the engine’s User-Agent), reads the cookies its own answer sets (a redirect is not followed), and sends them with every search: one visit for every search waiting on it, kept until one of them expires or a day. A search refused with them (412, 401 or 403) drops them, and the page is not visited again for a minute; a visit that sets none sends no search. No cookie is ever made up.
token-betweentwo stringsNo(none)With first-visit: its page hands out a token instead of cookies, the text between these two marks in its answer (token-between "'currentSessionId', '" "'": Boardreader’s session id; "\"token\":\"" "\"": Vimeo’s guest JWT), and {token} in search-url and in header values is it ("Authorization" "jwt {token}"). The page is asked with the engine’s headers but those holding {token}; the token is kept 5 minutes, else as first-visit’s cookies are.
query-tagbool or stringNofalse{query} is the words as one hashtag: their letters and digits, joined and lowercased (framework laptop → frameworklaptop). A string goes between the words: query-tag "_" asks a booru for its tag thumbs_up. A search with none is not sent. Used by mastodon_social, seventv, danbooru and safebooru.

Response parsing – HTML mode

Used when result-type is "html" (or "HTML" or "xpath").

A selector ending in @attr reads that attribute of what it finds (img@alt); @attr alone reads the row’s own (@cast: Rotten Tomatoes’ rows carry their facts as attributes); as content-selector, a list in it reads with a space after each comma (“Timothée Chalamet, Zendaya”), a number’s “1,000” as it is.

AttributeTypeRequiredDefaultDescription
result-typestringYes–Set to "html" for CSS-selector-based parsing.
results-selectorstringYes (for HTML)""CSS selector for result container elements. Each match becomes one result.
blocked-ifstringNo""CSS selector for what only a captcha or block page holds, e.g. blocked-if "form#gs_captcha_f": an answer holding it fails the engine (classed blocked, as health and the timeline show it), never read as no results.
title-selectorstringNo""CSS selector (relative to result container) for the title text.
url-selectorstringNo""CSS selector for the URL. Extracts href attribute first; falls back to text content.
content-selectorstringNo""CSS selector for the snippet/description text.
thumbnail-selectorstringNo""CSS selector for a thumbnail image URL: the picture of an image or video result, and the one drawn beside a web or news row. "." is the row’s own text (Emojipedia’s character, ahead of its name); thumbnail-template makes an address of what it reads.
image-from-thumbtwo stringsNo(none)The picture itself, for the Images viewer: the thumbnail’s address with its first "<old>" replaced by "<new>", e.g. image-from-thumb "/280h/" "/960w/". In JSON mode too, where image-path is not set or empty. Without either the viewer shows the thumbnail.
date-selectorstringNo""CSS selector for the result’s publication date. Accepts absolute forms (Jan 5, 2024, 2024-01-05) and relative ones (3 days ago). Unparseable values are ignored rather than rendered wrong.
attribute-selector "Label" "css"repeatableNo—An extra fact read from the row by CSS selector (@attr takes an attribute), e.g. attribute-selector "Seeders" "td.seeds" say="{count} seeders". Takes the same say= and more selectors tried in turn as attribute.

Response parsing – JSON mode

Used when result-type is "json".

AttributeTypeRequiredDefaultDescription
result-typestringYes–Set to "json" for dot-path-based JSON parsing.
results-pathstringNo"" (top-level array)Dot-separated path to the results array in the JSON response. Example: "message.items" navigates {"message":{"items":[...]}}.
empty-is-noneboolNofalseAn empty answer is nothing found, not a failure: Safebooru’s when nothing matches. Without it an empty answer is unreadable, as a soft block or a CDN’s stub is.
title-pathstringsNo""Dot-path to the title field within each result object. More paths after the first are tried in turn while the title is empty: Danbooru’s characters, then its series, then its tags.
url-pathstringNo""Dot-path to the URL field.
content-pathstringNo""Dot-path to the snippet/description field.
thumbnail-pathstringNo""Dot-path to a thumbnail URL field: the picture of an image or video result, and the one drawn beside a web or news row.
thumbnail-templatestringNo""Builds the thumbnail’s address from what thumbnail-path (or thumbnail-selector) reads: {value} is that value, {codepoints} the emoji it begins with as OpenMoji names its pictures (each code point in upper-case hex of four digits or more, joined by -, a lone FE0F after one code point left out: ☺️ is 263A), and {field} another field of the row. With {codepoints} and no emoji, the row has no picture.
thumbnail-replacetwo stringsNo(none)The thumbnail’s address with its first "<old>" replaced by "<new>": a smaller form the host serves, e.g. IMDb’s thumbnail-replace "._V1_." "._V1_QL75_UX320_." (320 px wide, where its own address is the poster at full size, often megabytes).
image-pathstringNo""Dot-path to the full picture’s address, which the Images viewer opens (else image-from-thumb, else the thumbnail).
video-pathstringsNo(none)Dot-paths to a clip the Images viewer plays in the picture’s place, muted and looping, the first with a value taken: Gifbox’s video-path "media_formats.webm.url" "media_formats.mp4.url". Through the image proxy, which passes a video only from Gifbox’s media host.
width-path, height-pathstringNo""Dot-paths to the picture’s size in pixels, for its tile’s shape and resolution badge.
source-pathstringNo""Dot-path to who a row is from: a picture’s author or site (its tile’s credit line and the viewer’s), a video’s channel. A key that holds dots (Dailymotion’s owner.screenname) is read as one key.
sourcestringNo""Who every picture is from when source-path gives none, e.g. source "OpenMoji".
graphiconstringNo""Puts an Images engine on the Graphicons tab, in that group of its second row: "text", "media" or "formats". Any other word stops the server’s start and --check-config.
picture-sizetwo intsNo(none)Every picture’s width and height when its row gives none, so its tile has its shape before it loads, e.g. picture-size 618 618 (OpenMoji’s art).
license, license-pathstringNo""A picture’s licence, after its credit in the tile (“OpenMoji · CC BY-SA 4.0”): license for every row, license-path a dot-path to a row’s own (Commons’ imageinfo.0.extmetadata.LicenseShortName.value), which wins.
views-pathstringNo""Dot-path to a video’s view count (a number, or text such as 1.2M views).
source-link-pathstringNo""Dot-path to the page of who a picture is from (a photographer’s profile): their name in the picture’s credit links it, in the tile and the viewer. On Unsplash’s pictures the credit reads “Photo by on Unsplash”, both links with Unsplash’s utm_source=4got&utm_medium=referral, as its API terms ask.
opened-pathstringNo""Dot-path to an address the engine asks to be told at when one of its pictures is opened (Unsplash’s download_location). When the viewer opens the picture, this server calls it, once per picture a page shows, with the key the person’s search would use (their own, else the server’s while it covers them and is under its stop), counted as a search counts it; only an address an answer gave, and only from a page of this server. A results page alone calls nothing.
published-pathstringNo""Dot-path to a publication date. Handles ISO/RFC3339 strings, unix seconds, unix milliseconds, and a bare four-digit year (IMDb’s y). Values that can’t be a plausible date are dropped — a wrong date misleads about freshness worse than no date does.
rating-pathstringNo""Dot-path to a numeric rating. Displayed in the engine’s own scale (“8.9/10”, “4.5/5”) but ALSO kept numerically, normalized to /10, so ranking and filtering stay possible — the thing searxng gave up by storing ratings as display strings.
rating-scalenumberNo10The engine’s maximum rating (5 for star-rating stores, 10 for IMDb/TVmaze).
attribute "Label" "path"repeatableNo—An extra fact to show under the result, e.g. attribute "Network" "show.network.name", drawn “Network HBO” in the row’s facts line, the facts parted by dots. Ordered: the engine knows which facts matter most in its own domain. Empty values are skipped rather than rendered as a blank row. More paths after the first are tried in turn, the first with a value taken (attribute "Severity" "cve.metrics.cvssMetricV40.0.cvssData.baseSeverity" "cve.metrics.cvssMetricV31.0.cvssData.baseSeverity"). An array’s every item is shown, parted by “, “ (a repository’s licences, a package’s authors). say="…": how the line says it, in place of “Label value”: {} is the value, {count} the value as a count (say="{count} stars": 69626 is “70K stars”, 1 is “1 star”), {ago} a date’s age (say="updated {ago}": “updated 2 days ago”); a value its {count} or {ago} cannot read is left out, and so is a {count} of 0, unless zero="…" says what to show for it (zero="no seeders": a dead torrent).
keep-ifstring, repeatableNo—Dot-path: a row is kept only when it holds something other than nothing, false or 0, e.g. keep-if "account.indexable" (Mastodon: the person lets their posts be searched), keep-if "imageinfo.0.duration" (Commons’ animated GIFs: a still one has no duration).
lang-fieldstringNo""Dot-path to the language a row says it is in (an ISO 639-1 code, e.g. Mastodon’s language). A row in none of the person’s known languages, or the query’s own when it is clearly another, is not drawn (on every tab and in What people are saying); it stays in the shared cache for others. A row that says nothing is drawn.
drop-ifstring, repeatableNo—Dot-path: a row is dropped when it holds something other than nothing, false or 0, e.g. drop-if "sensitive" (behind a content warning), drop-if "skintone" (OpenMoji’s skin-tone variants, 1 to 5). With a value after the path, when it holds that value; with safe=true, at safe search Moderate and Strict alone: drop-if "category" "9" safe=true (emoji.gg’s NSFW category).
order-pathstringNo""Dot-path to a number the rows are put in order of, those without one last: MediaWiki answers a generator’s pages in no order, and index is its search’s.
list-matchstringsNo(none)The answer is a whole catalogue, not a search (search-url without {query}): asked on the first search that needs it and kept a day (again a minute after a failure, the last good one served meanwhile), its rows after keep-if and drop-if kept, and a search shows those whose fields at these dot-paths hold each of its words at a word’s start (“facepalm” finds “person facepalming”), in the catalogue’s order, page-size a page. Imgflip’s get_memes, OpenMoji’s openmoji.json.

URL construction

AttributeTypeRequiredDefaultDescription
url-prefixstringNo""String prepended to every extracted URL. Use for APIs that return relative paths (e.g. "https://developer.mozilla.org" + /en-US/docs/...).
url-templatestringNo""Template for building URLs from result fields. Placeholders: {title} (spaces replaced with _), {id}, {url}, {wikilang}. Takes precedence over url-prefix when set. Example: "https://www.artic.edu/artworks/{id}". {wikilang}, here and in search-url, is the person’s first known language as a Wikimedia wiki names it, among the project’s in the host (https://{wikilang}.wiktionary.org/…; Wikipedia’s elsewhere), from go-server/wikis.txt: nb is no, pt-BR is pt, and en where the project has none.

Pagination

AttributeTypeRequiredDefaultDescription
page-sizeintNo10Results per page. Used to compute {offset}.
pagingboolNofalseWhether this engine supports pagination. Without it and without a {page}/{pageno}/{offset} token, the engine is asked for page 1 only: for page 2 it would answer page 1 again. paging false means page 1 only even with a token in the address. Check the site’s own next-page link before adding a token; a parameter the site ignores repeats page 1.
first-pageintNo0The page/offset number for the first page. Most APIs use 0 or 1.

Content processing

AttributeTypeRequiredDefaultDescription
content-html-to-textboolNofalseStrip HTML tags from the content/snippet field before display. Useful for APIs like StackExchange that return HTML in JSON.
content-markdownboolNofalseThe snippet is Markdown: flatten it to one line of plain text (heading, quote and list marks, link addresses, code marks and escapes go; fenced code is kept as written; a line repeating the title is dropped), and undo code marks and escapes in the title. Emphasis is kept, since ** in developer text is as often **kwargs. Used by firecrawl_dev.
title-from-contentboolNofalseA post with no title (no title-path): the title is its first sentences that fit in 100 characters, when they make 40 or more, else its opening cut at a word with … (and the snippet, the rest, starts with …). With content-html-to-text, a paragraph or line break reads as a space.
strip-textstringsNo(none)Marks taken out of a JSON row’s title and snippet, e.g. strip-text "[Keyword]" "[/Keyword]" (Boardreader’s around the words found).

Lifecycle

AttributeTypeRequiredDefaultDescription
disabledboolNofalseIf true, the engine is parsed but not registered. Use to temporarily disable an engine without removing its config.
cache-hoursintNo(none)A search holding the engine’s rows is kept at most this many hours, however long its category’s cache keeps one, and a full search carries none of the engine’s older rows or timing into its copy, every other engine’s as before: Gifbox’s cache-hours 24, as its terms ask.

Federation

AttributeTypeRequiredDefaultDescription
sharestringNoauto-detectedControls whether results from this engine are shared with peer instances. Values: "none" (never share – used for engines with API keys to avoid leaking quota), "cache" (share cached results but don’t proxy live queries – the default), "proxy" (full proxy: friends can trigger live queries through us). When omitted, the engine factory auto-detects: if the URL or headers contain an API key pattern (api_key=, Authorization, etc.), defaults to "none"; otherwise defaults to "cache".
tor-outboundboolNofalseRoute this engine’s HTTP requests through the local Tor SOCKS5 proxy (127.0.0.1:9050). Use for engines that aggressively IP-ban search aggregators. Requires a running Tor daemon.

Host budgets

Each engine has its own budget of requests: its engine-budget line (see engines.kdl budgets in the configuration reference), or 30 a minute and 1,000 a day. Where several engines ask one upstream that limits the address as a whole, a host-budget line gives that host a budget the engines share, checked before each request alongside the engine’s own:

host-budget "api.stackexchange.com" per-minute=25 per-day=280

The host is matched against each engine’s search-url. Both numbers are required and must be above 0, or the engines file does not load. A test search (X-4got-Test) asks such a host only while at least half of its day is left after it, so people’s searches keep the rest.

A host that takes a key identifying the server itself (not a person’s, and not a paid quota) names it:

host-budget "api.stackexchange.com" per-minute=25 per-day=280 key="stackexchange" key-param="key" keyed-per-minute=120 keyed-per-day=9500

key is the key’s name in config.kdl’s api-keys. While the server has it, every request from these engines to the host carries it in key-param, for everyone, and the keyed numbers are the budget. Without it the requests go keyless under the first numbers.

Examples

JSON API engine (MDN)

engine "mdn" {
    name "MDN Web Docs"
    categories "web"
    search-url "https://developer.mozilla.org/api/v1/search?q={query}&page={page}"
    method "GET"
    result-type "json"
    results-path "documents"
    title-path "title"
    url-path "mdn_url"
    url-prefix "https://developer.mozilla.org"
    content-path "summary"
    page-size 10
    paging true
    first-page 1
}

HTML scraping engine (Anaconda)

engine "anaconda" {
    name "Anaconda"
    categories "web"
    search-url "https://anaconda.org/search?q={query}&page={page}"
    method "GET"
    result-type "html"
    url-prefix "https://anaconda.org"
    results-selector "tbody tr"
    title-selector "td h5"
    url-selector "td h5 a:last-of-type"
    content-selector "td p"
    page-size 10
    paging true
    first-page 0
}

Engine with custom headers (Crossref)

engine "crossref" {
    name "Crossref"
    categories "web"
    search-url "https://api.crossref.org/works?query={query}&rows=20&offset={offset}"
    method "GET"
    result-type "json"
    results-path "message.items"
    title-path "title"
    url-path "URL"
    content-path "abstract"
    content-html-to-text true
    headers {
        "User-Agent" "4got/1.0 (https://4got.org; mailto:admin@4got.org)"
    }
    page-size 20
    paging true
    first-page 0
}

POST engine with body template (ArtStation)

engine "artstation" {
    name "www.artstation.com"
    categories "images"
    search-url "https://www.artstation.com/api/v2/search/projects.json"
    method "POST"
    result-type "json"
    results-path "data"
    title-path "title"
    url-path "permalink"
    content-path "description"
    thumbnail-path "smaller_square_cover_url"
    body-template "{\"query\":\"{query}\",\"page\":{page},\"per_page\":20,\"sorting\":\"relevance\",\"pro_first\":\"1\",\"filters\":[],\"additional_fields\":[\"description\"]}"
    page-size 20
    paging true
    first-page 1
}

URL template engine (Art Institute of Chicago)

engine "artic" {
    name "www.artic.edu"
    categories "images"
    search-url "https://api.artic.edu/api/v1/artworks/search?q={query}&page={page}&limit=20"
    method "GET"
    result-type "json"
    results-path "data"
    title-path "title"
    url-path "id"
    url-template "https://www.artic.edu/artworks/{id}"
    content-path "thumbnail.alt_text"
    page-size 20
    paging true
    first-page 1
}

How the generic engine factory works

At startup, LoadAndRegisterGenericEngines() in generic_engine.go:

  1. Reads data/engines.kdl via resolveKDLNodes() (kdl_doc.go, which supports both standalone files and engines { ... } sections inside a unified KDL file), parsed by kdl-go as KDL v1.
  2. Turns the engine nodes into []GenericEngineConfig via engineConfigs(), which handles engine blocks, headers sub-blocks, and all property types.
  3. Skips entries with empty ID, no categories, or disabled true.
  4. Sets defaults: page-size defaults to 10, name defaults to the ID.
  5. Creates a GenericEngine struct (which implements the Engine interface) for each config and registers it in the global engine registry.
  6. Determines the share policy: explicit share attribute wins; otherwise auto-detects based on whether the URL or headers contain API key patterns.

When Search() is called on a GenericEngine:

  1. Substitutes {query}, {page}, {offset}, {lang} in the URL template (and body template if POST).
  2. Makes the HTTP request, routing through Tor if tor-outbound is set.
  3. Records the raw HTML for drift detection (drift.go).
  4. Dispatches to parseHTML() (goquery CSS selectors) or parseJSON() (dot-path navigation) based on result-type.
  5. Returns []WebResult with each result’s Engine field set to the engine ID.

Testing a new engine via the admin playground

The admin playground at /admin/engines/new (owner-only) provides a web form for configuring and testing generic engines without editing KDL files directly.

  1. Log in as owner at /admin/login.
  2. Navigate to /admin/engines/new.
  3. Fill in the engine identity (ID, display name, categories).
  4. Set the search URL template with {query} and {page} placeholders.
  5. Choose HTML or JSON result type and fill in the corresponding selectors/paths.
  6. Enter a test query and click “Test Engine” – this POSTs to /admin/engines/test, which creates a temporary GenericEngine in memory, runs a search, and returns results as JSON displayed in the form.
  7. Iterate on selectors until results look correct.
  8. Click “Save Engine” to append the generated KDL block to data/engines.kdl and register it in memory immediately (no restart needed).

The test endpoint does not persist anything – only “Save Engine” writes to disk.

Example: an offline Wikipedia (Kiwix)

A local archive is an engine like any other. With kiwix-serve running on this machine:

  1. Download a ZIM from https://download.kiwix.org/zim/ (wikipedia_en_simple_all_mini is about 1 GB).
  2. kiwix-serve --port 8080 /path/to/wikipedia.zim
  3. Add this block to data/engines.kdl, with books.name matching your ZIM, and check the selectors against your kiwix-serve’s search page.
engine "kiwix_local" {
    name "Wikipedia (offline)"
    categories "web"
    search-url "http://127.0.0.1:8080/search?books.name=wikipedia&pattern={query}&userlang=en"
    method "GET"
    result-type "html"
    results-selector "ul.results li"
    title-selector "a"
    url-selector "a"
    content-selector "cite"
    url-prefix "http://127.0.0.1:8080"
    page-size 20
    paging false
    first-page 1
    local true
    serves "en.wikipedia.org/wiki/=>http://127.0.0.1:8080/wikipedia/A/"
}

local true exempts it from rate limits and the fanout’s deadlines. serves marks live Wikipedia results as available offline, linking the local copy.