4got API documentation ====================== 4got exposes a JSON/MessagePack API for programmatic search. All API endpoints require authentication unless noted otherwise. ENDPOINTS --------- GET /api/v1/search?q=QUERY&category=web Native 4got search API. Returns merged, deduplicated results from all engines with cross-engine scoring. Parameters: q - search query (required) category - web, images, videos, news, music (default: web) page - page number (default: 1) t - time range: day, week, month, year (optional); the engines that can't filter by date are not asked context - research context name (lowercase, digits, hyphens, up to 32 chars). Results already shown in that context are hidden; results returned are recorded, so many related queries hand back only what is new. Adds context, hidden_seen, marked_seen to the response. For groups the server allows (agent_contexts); 403 otherwise. show_seen - 1 to include already-seen results anyway mark_seen - 0 to read without recording nocache - 1 to ask the engines again instead of this server's copy of the same search; their rows are still kept A search reads this server's shared copy of the same words while it is fresh, as the results page does, and keeps its own rows in it; an engine served from the copy reads "name (cached)" in engines_used. A test request (X-4got-Test) reads and keeps none. Response fields: query, category, elapsed_ms, engines_used, engines_errored, results (array of {score, engines, items}); searches_left, where a per-day limit holds for you (RATE LIMITS) format=html (web-type categories) is Load more's: page N of the results page's own list, as the results page drew page 1, as rendered rows {html, media, page, total_pages, new_hashes}; media is the page's image and video strips, [{after, html}], each after that many of its rows; seen= (row hashes, comma-separated) leaves those rows out. total_pages is the pages known so far: one more while the engines' own next page is still to ask, the exact count once none is left. POST /api/v1/lens The image search as JSON: where an image appears, its text and its QR codes. Form fields (multipart, or urlencoded with url): image - the image file, up to 10 MB url - or an http(s) address of one then - "region" when the image is a part you cut from a bigger one, as the page's region search sends it Response fields: matches (array of {title, url, snippet, engine, engines, thumbnail}, one a page, engines every source that found it, the thumbnail a /proxy/image path), engines_used (the sources that answered), reverse_search_unavailable (none did), no_answer (the keyed sources asked that gave none), seen_by (every service the image was sent to: tineye, google-lens, google-vision, saucenao, serpapi for Google Lens through SerpApi), text, lines (the text's lines in reading order, {x, y, w, h, par, words: [{text, x, y, w, h}]}, boxes in the image's pixels, par where a paragraph starts), codes, labels, entities, similar (the last three from Google Vision), elapsed_ms The image goes where the image search sends it, stripped of its metadata, and is not kept: TinEye, then Google Lens when TinEye fails or finds nothing; with a key (yours, or the server's where your group may use it) SauceNAO, and Google Lens through SerpApi; and Google Vision for a region (then=region) or when TinEye and Google Lens give nothing. Text and codes are read here. Over 10 MB: 413. Not an image: 400. Each counts toward the per-day search limit. Example (a region of the screen, on Wayland): grim -g "$(slurp)" - | curl -H "X-API-Key: YOUR_KEY" \ -F "image=@-;filename=shot.png" -F then=region \ https://HOST/api/v1/lens POST /api/v1/research-contexts/share {"ctx": NAME, "kid": KID} Shares your context NAME and returns {context, link, kid}. Anyone holding the link can join; a result one member has seen is then hidden from all of them. kid (optional) is the key id of the group chat key you made for it (below), which its chat then takes. {"ctx": NAME, "stop": true}: stop sharing it (its owner; the link stops working) or leave it (your number is kept, as one who left, until you delete your server data or the share ends). POST /api/v1/research-contexts/join {"link": LINK, "ctx": NAME} Joins a shared context as a context of your own (ctx optional: the shared name by default) and returns {context}. Search in it with context= as above; no agent_contexts permission needed. GET /api/v1/research-contexts/chat?ctx=NAME A shared context's group chat as this server holds it, for its members: {entries: [{seq, n, t, c}], you, owner}: n a member's number, t a unix time, c the entry, end-to-end encrypted under the key after #k= in the context's link, which this server never sees. c is base64url of 0x01, a key id (HMAC-SHA256(key, "4got group chat key"), 4 bytes), a 12-byte nonce and the AES-256-GCM ciphertext of the entry's JSON ({"note"}, or {"q", "a", "m"} for a question to its AI; "name" when given), with the first 5 bytes and the author's member number n (4 bytes, big-endian) as additional data. /chat/stream holds it open as server-sent events: on each connect {cleared} and then every entry, then each new entry, {seq, gone} and {cleared}; four at a time for each member. POST {"ctx", "c"} posts an entry (8 KB at most; a full chat answers 413 with its size; one under another key than the chat's, 409), {"ctx", "delete": SEQ} deletes one of yours, {"ctx", "clear": true} (the owner) empties it, {"ctx", "kid": KID} (the owner) names the key of a chat shared without one, once. This server reads the chat only during a request that carries it: an agent's, with the link and its key, or a question to the AI, with the chat so far, names included; it keeps nothing of either beyond the request. GET /api/v1/qa (?text=WORDS) and /api/v1/qa?id=ID Questions, where this server takes them: the open ones and those published lately, or one, with its answers (and the award as its asker signed it) once awarded or past its deadline. No authentication. To post: POST /api/v1/qa/ticket {"kind": "ask" or "answer"} with your session (ten an hour), then POST /api/v1/qa {"do", "ticket", "pub", "m", "sig"} without it: m the post's JSON, sig the post's Ed25519 key's signature of "4got-sign|v1|\n" and m. Opening the answers ("nonce", then "open", signed for proof), "award" and "retract" are signed so too. MCP does all of it below. GET /questions.atom is the open questions as an Atom feed, and GET /questions/watch/TOKEN.atom those a watch in Settings found. A question awarded here that answers a search is drawn above its results, and MCP's search puts it in a line above its own: "Answered here: TITLE — ADDRESS"; one awarded on a friend's server, "Answered on FRIEND: TITLE — ADDRESS". Friends' open questions are on /questions and in MCP's questions, not here. POST /mcp 4got as an MCP server (Model Context Protocol, Streamable HTTP, JSON-RPC 2.0), for AI agents. Same authentication as the rest of the API. Methods: initialize, ping, tools/list, tools/call. Tools: search query, category, limit (default 10), page, time; context, show_seen, mark_seen as for /api/v1/search. Where the page would show an AI overview, it comes first: its paragraph, a line "[n] address" for each result it cites, then the top 5 results. answer: false turns it off, true gives it even where a card answers contexts action, context, link: list (the default) your contexts and how much each has seen, and your searches left today; forget (delete) or clear (keep the name) one; share one and answer its link (a new share's with its chat key after #k=); stop the share (yours) or leave it (joined); join a share by its link, as a context of your own thread_read link: its group chat, opened with the link's key thread_post link, text, name: post a note to it. Either shows this server the chat for that call; it keeps no key research query: GET /api/v1/research's answer (that stream is the page's, every sentence) cut to the sentences citing a page the run read, and sources: each page cited, with the [oN] it is cited by; left_out counts the rest, unsourced true gives them. With ask, answer, turns: Chat about it, the research agent asked more with the chat you send; nothing kept or cached overview query: the AI overview above the results, as text, cut to the sentences citing a result, then a line "[n] address" for each result it cites (and its title where the address does not name the page), and a line counting what it left out, which unsourced true gives answer query, name: the instant answers (the cards); words no card answers get the overview, where you have one bookmarks url, title, folder, limit: your folders and bookmarks, or keep a page; a session cookie's own lens image_url or image (base64), region: POST /api/v1/lens trending period, from: /trending's searches, Liked here and live feed check url, quote: whether quote is in the page's text, less what its markup hides, case and punctuation aside: found; near, with the page's own words nearest it (300 characters at most); or absent; with when the page was read and its text's hash. The page is fetched as 4got, once an hour for each caller, who alone reads that copy, and its address kept nowhere else; a call counts as a read questions text, since: the questions here; id: one question title, body, tried, days: ask (its seed opens the answers and awards); id, body, link: answer one question_award id, seed: the answers to your question; accept: the answers you accept, awarded The names these replaced still answer: list_contexts, forget_context (clear), share_context (stop), join_context, follow_up, question_read, question_ask, question_answer and question_answers. The question tools are there where this server takes questions and you may ask. Contexts are the same objects a person sees under Settings > Profiles & tabs (global) > Research contexts, and are purged by "delete my server data". Each tool runs the API or the page it names on your own request: the same permissions, group, keys and daily limit, and a test request (X-4got-Test) stays bare unless X-4got-Want names the extra (research, overview, wolfram, reverse_image). search answers numbered results as text, each with its date when the engine gave one, and as JSON in structuredContent, with overview there when the answer came first; overview answers text, and answer too where no card answers; research, bookmarks, lens, trending and answer's cards compact JSON, in structuredContent and as text. tools/list leaves out what you may not use: research and overview where the page offers you neither, bookmarks without a session cookie. A call that sends a progressToken (params._meta) with Accept: text/event-stream gets each step as notifications/progress, then its result, as server-sent events; research takes one to six minutes. Example: curl -X POST -H "X-API-Key: YOUR_KEY" -H "Content-Type: application/json" \ https://HOST/mcp -d '{"jsonrpc":"2.0","id":1,"method":"tools/call", "params":{"name":"search","arguments":{"query":"kdl config language","context":"kdl"}}}' With a personal token in X-4got-Token instead, /mcp serves the token owner's own history, and only that, as tools (by the token's scopes): history_since since, limit, results, why: GET /api/v1/me/history?since= history_search from, to, q, limit, results, why: GET /api/v1/me/history?from=&to=&q= recall q, from, to, limit, why: GET /api/v1/me/recall save url, title: POST /api/v1/me/save Each is that REST call: the same checks, bounds and answer, in structuredContent (and as JSON text). A refusal is an isError result with the REST error's fields: needs_approval, approve_url. A token in the address is refused. Config for MCP clients: GET /settings/ai/mcp.json. GET /api/v1/me/history?since=CURSOR&from=&to=&q=&limit=&results=&why= Your own search history, for your own AI. Needs a personal token (Settings > Connect my AI) with the history:read scope in the X-4got-Token header; a token in the address is refused. Returns your searches as rows ({q, category, at, t}), oldest first, with next (a cursor) and more. Only the history kept on this server: history locked in a browser with a passphrase is not served by this read (see /api/v1/me/locked). Parameters: since - next from an earlier answer: only what came after it from, to - unix seconds, YYYY-MM-DD or RFC 3339 q - only the searches whose words hold every word of q limit - 1 to 1000 (default 200) results - 0 to 40: the first results each search showed; each result counts as a row toward the day's rows why - one line on what the task needs; shown to the person if the read needs their approval A token reads 7 days back, 2000 rows a day and 60 requests an hour, until its owner raises them. Past the days or the rows: 403 {"error":"needs_approval","reason":"window|rows", "approve_url":...}. The AI gives the link to the person and never opens it or presses anything on it itself. The person opens it in their own browser (their session; it works for 15 minutes, is answered once, and never carries the token) and sees which token asks, for which window, how many rows and why. They allow it once (that window, paged with since, at most the rows shown, within the hour; or the rows for today), raise the token's limits, or refuse. Past the requests: 429 with Retry-After, never an approval. Revoked or expired: 401. GET /api/v1/me/recall?q=DESCRIPTION&from=&to=&limit=&why= Pages you've seen and searches you made that match a description, from your history on this server (the recall:query scope). Returns pages ({url, title, snippet, q, at}: the search that showed it) and searches ({q, category, at}); each counts as a row. limit 1 to 50 (default 20) of each. Same window, bounds and approval as above. Nothing is sent to a language model. GET /api/v1/me/limits The token's bounds and what is used: window_days, rows_per_day, rows_left_today, requests_per_hour, requests_left_this_hour, expires. POST /api/v1/me/save {"url": "https://…", "title": "…"} Keeps a page your AI found for you in your bookmarks here, in the folder "Found by my AI" (made the first time, kept offline as a reading list). Needs the found:save scope, which a token has only when its owner ticks "save what it finds". Returns {saved, already, folder, url}: already=true when you had kept the page before, and then it stays where it is. 400 for an address that is not http or https; 507 {"error":"full"} when your space here is full. Counts toward the requests an hour like the reads. GET /settings/ai/SKILL.md A skill for your AI, filled in for this server: how to read the history above with the fewest rows. GET /settings/ai/mcp.json An MCP client's config for this server; the token stays in the FGOT_TOKEN environment variable. GET /api/v1/me/locked?from=YYYY-MM&to=YYYY-MM&why=&meta=1 Your locked history (kept in your browser under your passphrase), for your bridge, 4got-mcp. Needs a bridge token (Settings > Connect my AI > Your locked history; the locked:read scope) in X-4got-Token. This server holds only what your unlocked browser sealed when you allowed months: each month's searches and opened pages, sealed under a key derived from the token's bridge key and bound to the token, the month and the grant (data). Whoever holds the bridge key, or a browser holding your lock, can open them. This server cannot; it never gets your passphrase or the bridge key. Returns bridge_id and months ({month, grant, data, bytes, sealed, expires}); meta=1 leaves data out; without from and to, the months allowed now. from..to is at most 24 months (UTC). A month not allowed: 403 {"error":"needs_approval", "reason":"months","missing":[...],"approve_url":...}. The AI gives the link to the person and never opens it or presses anything on it itself. The person opens it in the browser that keeps the history, unlocks it there and presses Allow these months: that browser seals those months and sends them. They are readable for an hour (the bridge refuses one sealed longer ago), deleted about an hour after they were allowed, and at once when the token is revoked. 60 requests an hour (429 past them). Revoked or expired: 401. 4got-mcp (GET /settings/ai/4got-mcp/4got-mcp.go, and builds for Linux, macOS and Windows where this server has them) The bridge: a stdio MCP server you run on your own computer. It reads FGOT_SERVER, FGOT_TOKEN and FGOT_BRIDGE_KEY from its environment, fetches the months above, opens them there, and serves history_since, history_search and recall over them, with the arguments and answers of /mcp's history tools. It sends nothing but its token and the months it asks for, writes nothing to disk, and forgets each month when its hour is over (counted from its sealing, by its own clock) or the token is revoked. Build it from the source: go build 4got-mcp.go (Go 1.24 or later). Config: GET /settings/ai/mcp-bridge.json. GET /api/v1/web?s=QUERY 4get-compatible web search. Uses the same response envelope as 4get's /api/v1/web endpoint for drop-in compatibility. GET /api/v1/images?s=QUERY 4get-compatible image search. GET /api/v1/videos?s=QUERY 4get-compatible video search. GET /api/v1/news?s=QUERY 4get-compatible news search. GET /api/v1/music?s=QUERY 4get-compatible music search. GET /api/v1/ac?q=QUERY Autocomplete suggestions from multiple backends. No authentication required. Returns a JSON array of suggestion strings. GET /ami4got Instance information (version, engine count, uptime, etc.). CORS enabled. No authentication required. Returns: status, server info, real_searches, bot_requests, api_enabled, version, instances list. GET /api/v1/status This server's own uptime, as /log's bar shows it. No authentication required. Returns: started (RFC 3339), uptime_seconds (since then), uptime_24h, uptime_7d, uptime_90d (percent of 5-minute heartbeats received, from counted_since when that is later). GET /api/v1/cache?key=HASH This server's cached results for a search, by its cache key. For a friend (X-Peer-Secret), the owner, and anyone whose group or API key has peer_cache; else 403 with a session, 401 without. A server with no peer-secret answers anyone. POST /api/v1/cache A friend's push of its fresh results, kept only when signed by its key in peers.kdl (X-Result-Signature, X-Peer-Identity). X-Peer-Secret too when this server has one (else 401); a bad signature gets 403. GET /api/v1/discovery/advertise The Discovery entries this server shares with its friends: those marked federate=true that may leave it, and its webring's. Only for a friend (X-Peer-Secret); else 403. Response: {"entries": [{"url", "title", "note", "tags", "bot_friendly", "join", "webring", and with a place "place" (its name as typed), "lat", "lon" (the middle of a cell about 25 km wide)}]} GET /api/v1/qa/offer The questions this server offers anyone holding the peer secret (X-Peer-Secret; else, or where it takes none, 404): what anyone reads of them here. Response: {"m": {"at", "open": [{"id", "title", "body" (its opening), "at", "due", "answers_count", "agent"}], "awarded": [the same, with "answer" (the accepted answer's opening) and "link"]}, "sig": ed25519 over "4got-sign|v1|questions\n" and m, base64}; 100 of each. A friend keeps it 5 minutes and matches its searches against it itself, so no search's words come here. GET /api/v1/engine-offers?at=UNIX&sig=SIG The engines.kdl blocks this server runs, for a friend's owner to take. Only for a friend whose pubkey is in this server's peers.kdl. Headers: X-Peer-Secret, X-Peer-Identity (the asker's fingerprint). sig: ed25519 over "engine-offers " by the asker's identity key, base64; at within 5 minutes. Response: {"offers": [{"block", "sig" (ed25519 over block, base64), "health": {"engine", "status", "consecutive_errors"}}]} POST /api/v1/proxy?service=SERVICE&... Service proxy endpoint. Friends proxy services for each other. Only for a friend (X-Peer-Secret); else 401. The instance must have allow-proxy configured for the service. Services: translation - text, target (lang code) deepl - text, target lingva - text, target nllb - text, target wolfram - query autocomplete - query engine:ID - q, cat, page, before, safe (0-2, never below this server's floor; an engine that can't filter at that level answers 403) Response: {"result": "...", "service": "...", "via": "hostname"} POST /api/v1/relay Run one web search for a friend. Only for a friend whose pubkey and "relay true" are in this server's peers.kdl. Body (JSON, signed): {"q", "safe", "region", "page", "to", "asked_at"} Headers: X-Peer-Secret, X-Peer-Identity (the asker's fingerprint), X-Result-Signature (ed25519 over the body, base64). asked_at must be within 5 minutes of this server's clock. Body over 16 KB: 413. "to" must be this server's fingerprint. 200, 429 and 503 carry X-4got-Relay-Left (searches left this hour). 429 + Retry-After past relay-per-hour; 503 + Retry-After when busy. Response: {"results": [{"title", "url", "snippet", "engine", ...}]} AUTHENTICATION -------------- Three methods, checked in order: 1. Bearer token (owner access): Authorization: Bearer 2. API key: X-API-Key: API keys are generated by the instance owner at /admin/users. Each key has specific permissions (api_access, no_pow, etc.). 3. Session cookie: A valid 4got_session cookie from passing the captcha or PoW challenge. Your own history (/api/v1/me/*, and /mcp's history tools) takes only a personal token: X-4got-Token: TESTING FROM A SCRIPT --------------------- A script testing 4got should send X-4got-Test: 1 so its searches stay out of Trending and the public log views. A client that cannot set headers can add test=1 to the address instead; it counts only from a client with no session cookie and a User-Agent that does not start with "Mozilla/", so a browser opening such a link is normally not marked. Requests with the owner secret in a header count as tests unless they send X-4got-Test: 0. This is separate from opting out of logging: a test search is still logged for the owner, marked as a machine's. A test search is bare: no Jev classifier, no language model, no Wolfram, no browser sidecar. Name the extras you are testing: X-4got-Want: rerank,merge or want=rerank,merge in the address of a single request. The names: routing, universal, news, saying, forums, shortform, lyrics, placement, answered, indicators, page_audio, source, merge, crawl, rerank, tab_filter, tab_picks, pagedates, platform_go, dict_pick, page_profile, cache_judge, planner, clarify, followups, lists, research_after, world_search, deep, research, overview, questions, graph, translation, query_language, morelike, engine_advice, captions, each_language, recall_expand, char_meaning, ask_jev, quiz, attachments, agent_history, wolfram, sidecar, reverse_image, telemetry and all (nothing left out). The response says what you got in X-4got-Bare, and lists names it did not know in X-4got-Want-Unknown. The owner secret alone does not make a search bare. GET /feed/search?q=QUERY&category=web Per-query Atom feed of search results. Subscribe in any RSS reader to get fresh results for a query on each poll. Requires authentication. Respects Cache-Control for poll interval. GET /api/openapi.yaml OpenAPI 3.0 YAML specification for all API endpoints. No authentication required. MESSAGEPACK ----------- To receive MessagePack instead of JSON, set the Accept header: Accept: application/msgpack All endpoints that return JSON also support MessagePack with the same field names. CSV --- To receive CSV instead of JSON from /api/v1/search, either set: Accept: text/csv or append ?format=csv to the query string. The CSV has headers: title, url, snippet, engine. RATE LIMITS ----------- The instance owner sets a per-day search limit (default: 200), and a group in groups.kdl may set its own, which holds for its people and for an API key that names the group (/admin/users); a key in two groups takes the more generous, no limit beating any number. Each person has a count of their own, and so does each key: everything that uses one key shares its count. The owner has none. An API key's own searches a day (on /agents) holds too, where it is fewer. Exceeding either returns HTTP 429 with Retry-After, and a message saying whose limit it is and when it resets (midnight UTC). Counted, one each, just before the engines are asked: /api/v1/search, /api/v1/{web,images,videos,news,music}, /api/v1/lens, /feed/search, /search (format=json, or with a key) unless the cache answers it, the scroll's next page unless page 1's list answers it, and over MCP search, lens, and overview and answer when they search (a card's answer does not); research, over MCP or /api/v1/research with a key, one a run its cache does not answer. Where a limit holds, /api/v1/search answers searches_left, and MCP's search, overview, answer, lens and research end in a line "searches left today: N"; contexts (list) says it too, spending no search. EXAMPLES -------- # Search with API key curl -H "X-API-Key: YOUR_KEY" "https://HOST/api/v1/search?q=hello" # A test search: kept out of the search log and Trending curl -H "X-API-Key: YOUR_KEY" -H "X-4got-Test: 1" \ "https://HOST/api/v1/search?q=hello" # A test search with the oracle router on, and nothing else paid curl -H "X-API-Key: YOUR_KEY" -H "X-4got-Test: 1" -H "X-4got-Want: routing" \ "https://HOST/api/v1/search?q=is+it+going+to+rain+in+berlin" # 4get-compatible search curl -H "X-API-Key: YOUR_KEY" "https://HOST/api/v1/web?s=hello" # Autocomplete (no auth needed) curl "https://HOST/api/v1/ac?q=hel" # MessagePack response curl -H "X-API-Key: YOUR_KEY" \ -H "Accept: application/msgpack" \ "https://HOST/api/v1/search?q=hello" # Time-filtered search curl -H "X-API-Key: YOUR_KEY" \ "https://HOST/api/v1/search?q=hello&t=week"