Official

Exa

Let agents search the web, find similar pages, read clean page text and highlights, and produce summaries or answers with citations. Filters narrow searches by site, date, country or category.

Exa charges searches, page reads and answers to your team's credits. Set a key budget in Exa to control spending.

Access is read-only. Exa Agent tasks, monitors, batches and Websets are not included.

Connect Exa.

Setup instructions

Connect Exa

  1. In the Exa dashboard, select the team whose credits Houston should use.
  2. Open API Keys, create a key and copy it.
  3. Paste it into Houston's API key and save the connection.

Searches, page reads and answers spend your team's Exa credits. Set a budget and rate limit for this key on the API Keys page.

Advanced

If requests exhaust credits or a budget, check Billing and the key's limits. Features depend on your plan; pages requiring sign-in or blocking crawlers may be unavailable. Replace deleted keys in Houston.

Billing and limits.

Files

  • connector.luau
    -- Exa API (OpenAPI 2.0.0, https://exa.ai/docs/exa-spec.yaml) for web search, page contents, similar pages and cited answers. Arguments and results keep Exa's native field names.
    type Options = {[string]: any}
    type Check = (any, string) -> any
    
    local API = "https://api.exa.ai"
    -- Houston ends a call after 30 s and the sandbox has no clock. Exa sends its whole answer once it is ready (about
    -- 1 s for auto, 4 to 15 s for deep, plus up to livecrawlTimeout for fresh pages), so headers get most of the time.
    local CALL_TIME, BODY_TIME = 27000, 4000
    local MAX_BYTES = 4 * 1024 * 1024
    -- Every call spends Exa credits. These bounds keep a call's cost and answer predictable: Exa bills each result above
    -- 10, and without a limit returns up to 5,000,000 characters of text per page. Text and sized highlights share one budget.
    local MAX_RESULTS, DEFAULT_RESULTS = 25, 10
    local TEXT_DEFAULT, TEXT_BUDGET = 10000, 500000
    -- A fresh fetch waits up to livecrawlTimeout before Exa answers, so it must leave room within the header budget.
    local HIGHLIGHTS_MAX, LINKS_MAX, LIVECRAWL_MAX = 10000, 20, 8000
    local MAX_QUERY, MAX_PROMPT, MAX_URL, MAX_DOMAINS = 4096, 4096, 2048, 1200
    -- Exa's recommended search types; the legacy instant, fast and deep-reasoning are left out.
    local TYPES = table.freeze({"auto", "lite", "deep-lite", "deep"})
    local CATEGORIES = table.freeze({"company", "people", "news", "publication", "financial report", "personal site"})
    -- exa-research is left out: its latency is undocumented and may pass the call limit, billed all the same.
    local MODELS = table.freeze({"exa", "exa-pro", "exa-fast"})
    local VERBOSITY = table.freeze({"compact", "standard", "full"})
    local SECTIONS = table.freeze({"header", "navigation", "banner", "body", "sidebar", "footer", "metadata"})
    
    local function finite(value: any): boolean
    	return type(value) == "number" and value == value and math.abs(value) < 2 ^ 53
    end
    
    local function integer(minimum: number, maximum: number): Check
    	return function(value: any, field: string): any
    		assert(finite(value) and value % 1 == 0 and value >= minimum and value <= maximum,
    			field .. " must be an integer from " .. tostring(minimum) .. " to " .. tostring(maximum))
    		return value
    	end
    end
    
    local function flag(value: any, field: string): any
    	assert(type(value) == "boolean", field .. " must be true or false")
    	return value
    end
    
    local function text(maximum: number): Check
    	return function(value: any, field: string): any
    		assert(type(value) == "string" and string.find(value, "%S") and #value <= maximum,
    			field .. " must be a string of at most " .. tostring(maximum) .. " bytes, not only spaces")
    		return value
    	end
    end
    
    local function choice(values: {string}): Check
    	return function(value: any, field: string): any
    		assert(type(value) == "string" and table.find(values, value), field .. " must be one of " .. table.concat(values, ", "))
    		return value
    	end
    end
    
    local function list(maximum: number, item: Check): Check
    	return function(value: any, field: string): any
    		assert(type(value) == "table", field .. " must be an array")
    		local count = 0
    		for index, entry in value do
    			assert(type(index) == "number" and index >= 1 and index % 1 == 0, field .. " must be a dense array")
    			item(entry, field .. "[" .. tostring(index) .. "]")
    			count += 1
    		end
    		assert(count == #value and count >= 1 and count <= maximum,
    			field .. " must be a dense array of 1 to " .. tostring(maximum) .. " entries")
    		return value
    	end
    end
    
    -- URLs and domain filters: no spaces or control characters, which would silently match nothing.
    local function link(value: any, field: string): any
    	assert(type(value) == "string" and #value <= MAX_URL and string.match(value, "^[^%s%c]+$"),
    		field .. " must be a URL or host of at most " .. tostring(MAX_URL) .. " bytes without spaces")
    	return value
    end
    
    local DAYS = table.freeze({31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31})
    
    local function within(digits: string?, minimum: number, maximum: number): boolean
    	local number = if digits then tonumber(digits) else nil
    	return number ~= nil and number >= minimum and number <= maximum
    end
    
    -- A real date, or a date-time with seconds, optional fractions and a Z or +hh:mm offset.
    local function isDate(value: any): boolean
    	if type(value) ~= "string" or #value > 40 then return false end
    	local y, m, d, rest = string.match(value, "^(%d%d%d%d)%-(%d%d)%-(%d%d)(.*)$")
    	if not y or not within(m, 1, 12) then return false end
    	local year, month = tonumber(y) :: number, tonumber(m) :: number
    	local leap = year % 4 == 0 and (year % 100 ~= 0 or year % 400 == 0)
    	if not within(d, 1, if month == 2 and not leap then 28 else DAYS[month]) then return false end
    	if rest == "" then return true end
    	local hour, minute, second, zone = string.match(rest or "", "^T(%d%d):(%d%d):(%d%d)(.*)$")
    	if not (within(hour, 0, 23) and within(minute, 0, 59) and within(second, 0, 59)) then return false end
    	-- Optional fractional seconds: a dot and at least one digit.
    	if string.sub(zone or "", 1, 1) == "." then zone = string.match(zone :: string, "^%.%d+(.*)$") end
    	if zone == "Z" then return true end
    	local zoneHour, zoneMinute = string.match(zone or "", "^[+-](%d%d):(%d%d)$")
    	return within(zoneHour, 0, 23) and within(zoneMinute, 0, 59)
    end
    
    local DATE_RULE = " must be an ISO 8601 date such as 2026-01-31 or date-time such as 2026-01-31T12:00:00Z"
    
    -- Published-date filters take date-times only, so a date alone covers its whole UTC day. Snapshots take either.
    local function published(suffix: string): Check
    	return function(value: any, field: string): any
    		assert(isDate(value), field .. DATE_RULE)
    		return if #value == 10 then value .. suffix else value
    	end
    end
    
    local function schema(value: any, field: string): any
    	assert(type(value) == "table" and next(value) ~= nil and #value == 0, field .. " must be a JSON Schema object")
    	return value
    end
    
    local function location(value: any, field: string): any
    	if type(value) == "string" then
    		assert(string.match(value, "^%a%a$"), field .. " must be a two-letter country code such as US")
    		return value
    	end
    	assert(type(value) == "table", field .. " must be a country code or {country?, latitude?, longitude?}")
    	local out: Options = {}
    	for key, item in value do
    		if key == "country" then
    			assert(type(item) == "string" and string.match(item, "^%a%a$"), field .. ".country must be a two-letter country code")
    		elseif key == "latitude" or key == "longitude" then
    			local limit = if key == "latitude" then 90 else 180
    			assert(finite(item) and math.abs(item) <= limit, field .. "." .. key .. " must be a number from -" .. limit .. " to " .. limit)
    		else
    			error(field .. " received an unknown option " .. string.sub(tostring(key), 1, 64), 0)
    		end
    		out[key] = item
    	end
    	assert((out.latitude == nil) == (out.longitude == nil) and (out.country ~= nil or out.latitude ~= nil),
    		field .. " needs country, or latitude and longitude together")
    	return out
    end
    
    -- Copies the known fields of an options table, checked, so unknown fields and the caller's table never reach Exa.
    local function fields(value: any, spec: {[string]: Check}, name: string, prefix: string): Options
    	assert(type(value) == "table", name .. " must be an options table")
    	local out: Options = {}
    	for key, item in value do
    		local check = if type(key) == "string" then spec[key] else nil
    		assert(check, name .. " received an unknown option " .. string.sub(tostring(key), 1, 64))
    		out[key] = check(item, prefix .. key)
    	end
    	return out
    end
    
    local function nested(spec: {[string]: Check}): Check
    	return function(value: any, field: string): any return fields(value, spec, field, field .. ".") end
    end
    
    local function extend(base: {[string]: Check}, more: {[string]: Check}): {[string]: Check}
    	local out = table.clone(base)
    	for key, check in more do out[key] = check end
    	return table.freeze(out)
    end
    
    local TEXT = table.freeze({maxCharacters = integer(1, TEXT_BUDGET), includeHtmlTags = flag, verbosity = choice(VERBOSITY),
    	includeSections = list(#SECTIONS, choice(SECTIONS)), excludeSections = list(#SECTIONS, choice(SECTIONS))})
    local HIGHLIGHTS = table.freeze({query = text(MAX_PROMPT), maxCharacters = integer(1, HIGHLIGHTS_MAX)})
    local SUMMARY = table.freeze({query = text(MAX_PROMPT), schema = schema})
    
    -- A content type is true or an options table, or false to leave it out. Without defaults, true is sent as is.
    local function view(spec: {[string]: Check}, default: Options?): Check
    	return function(value: any, field: string): any
    		if value == false then return nil end
    		if value == true and default == nil then return true end
    		local out = fields(if value == true then {} else value, spec, field, field .. ".")
    		local defaults: Options = default or {}
    		for key, item in defaults do
    			if out[key] == nil then out[key] = item end
    		end
    		return out
    	end
    end
    
    -- Full text always gets a character limit; a summary is an object even when empty.
    local CONTENTS: {[string]: Check} = table.freeze({
    	text = view(TEXT, {maxCharacters = TEXT_DEFAULT}),
    	highlights = view(HIGHLIGHTS),
    	summary = view(SUMMARY, {}),
    	extras = nested({links = integer(0, LINKS_MAX), imageLinks = integer(0, LINKS_MAX), richImageLinks = integer(0, LINKS_MAX)}),
    	livecrawlTimeout = integer(1, LIVECRAWL_MAX),
    	maxAgeHours = integer(-1, 720),
    	snapshotAsOf = published(""),
    })
    local RESULTS: {[string]: Check} = table.freeze({
    	numResults = integer(1, MAX_RESULTS),
    	includeDomains = list(MAX_DOMAINS, link),
    	excludeDomains = list(MAX_DOMAINS, link),
    	startPublishedDate = published("T00:00:00.000Z"),
    	endPublishedDate = published("T23:59:59.999Z"),
    	category = choice(CATEGORIES),
    	contents = nested(CONTENTS),
    })
    local SEARCH = extend(RESULTS, {
    	query = text(MAX_QUERY),
    	type = choice(TYPES),
    	additionalQueries = list(10, text(MAX_QUERY)),
    	userLocation = location,
    	moderation = flag,
    	objective = text(MAX_PROMPT),
    	systemPrompt = text(MAX_PROMPT),
    	outputSchema = schema,
    })
    local SIMILAR = extend(RESULTS, {url = link, excludeSourceDomain = flag})
    local GET_CONTENTS = extend(CONTENTS, {urls = list(MAX_RESULTS, link)})
    local ANSWER: {[string]: Check} = table.freeze({query = text(MAX_QUERY), model = choice(MODELS), systemPrompt = text(MAX_PROMPT),
    	userLocation = location, outputSchema = schema})
    
    local function required(body: Options, field: string, operation: string)
    	assert(body[field] ~= nil, operation .. " requires " .. field)
    end
    
    -- Bounds the text and sized highlights one call can return, which Exa sends for every result.
    local function budget(contents: Options?, count: number)
    	local perPage = 0
    	for _, kind in {"text", "highlights"} do
    		local options = if contents then contents[kind] else nil
    		if type(options) == "table" and options.maxCharacters then perPage += options.maxCharacters end
    	end
    	assert(count * perPage <= TEXT_BUDGET, "text.maxCharacters (default " .. tostring(TEXT_DEFAULT)
    		.. ") plus highlights.maxCharacters, times the number of results, must be at most " .. tostring(TEXT_BUDGET))
    end
    
    local function errorCode(err: any): any
    	return if type(err) == "table" then err.code else nil
    end
    
    local function fail(operation: string, status: number?, retryable: boolean, message: string): never
    	return houston.fail({operation = operation, layer = "upstream", upstream_status = status, retryable = retryable,
    		message = message})
    end
    
    -- houston.fail repairs a character split by the cut.
    local function tidy(message: string): string
    	return string.sub(string.match(string.gsub(message, "%s+", " "), "^ ?(.-) ?$") :: string, 1, 300)
    end
    
    -- Exa's error envelope is {requestId, error, tag}, given as " TAG: error (request id)"; other bodies, such as gateway
    -- pages, are never shown.
    local function reason(body: string): string
    	local ok, value = false, nil
    	if string.match(body, "^%s*{") then ok, value = pcall(json.decode, body) end
    	if not ok or type(value) ~= "table" or type(value.error) ~= "string" then return "" end
    	local tag = if type(value.tag) == "string" and string.match(value.tag, "^[%w_]+$") then " " .. string.sub(value.tag, 1, 64) else ""
    	local id = if type(value.requestId) == "string" and string.match(value.requestId, "^%w+$")
    		then " (request " .. string.sub(value.requestId, 1, 64) .. ")" else ""
    	return tag .. ": " .. tidy(value.error) .. id
    end
    
    local function failure(operation: string, response: HttpResponse): never
    	local status = response.statusCode
    	local detail = ""
    	if status >= 300 and status < 400 then
    		response.body:close()
    		detail = ": unexpected redirect"
    	else
    		-- An error body that stalls or breaks counts as empty.
    		local read, prefix = pcall(function() return await(response.body:readPrefix(4096), BODY_TIME) end)
    		if not read and errorCode(prefix) == "cancelled" then error(prefix, 0) end
    		if read then detail = reason(prefix) end
    	end
    	if detail == "" and status == 401 then detail = ": check the connection's Exa API key" end
    	local message = "Exa HTTP " .. tostring(status) .. detail
    	local retry = response.headers["retry-after"]
    	if (status == 429 or status == 503) and retry and retry[1] then
    		-- Retry-After is either delay seconds or an HTTP date.
    		local value = string.sub(retry[1], 1, 32)
    		message ..= "; retry after " .. value .. (if string.match(value, "^%d+$") then "s" else "")
    	end
    	-- Input is checked first, so Exa's 4xx answers (bad requests, keys, credits, plans) are final.
    	return fail(operation, status, status == 429 or status >= 500, message)
    end
    
    -- Posts one request and returns Exa's JSON object, which must hold the given field.
    local function call(operation: string, path: string, body: Options, field: string): any
    	local sent, response = pcall(function()
    		return await(http.request({method = "POST", url = API .. path, timeoutMs = CALL_TIME - BODY_TIME,
    			headers = {["Content-Type"] = {"application/json"}, Accept = {"application/json"}}, body = json.encode(body)}))
    	end)
    	if not sent then
    		if errorCode(response) ~= "timeout" then error(response, 0) end
    		fail(operation, nil, false, "Exa did not answer within " .. tostring((CALL_TIME - BODY_TIME) // 1000)
    			.. " s; Exa may still bill it. Use a faster type or model, fewer results or a lower livecrawlTimeout")
    	end
    	if response.statusCode ~= 200 then failure(operation, response) end
    	local read, raw = pcall(function() return await(response.body:readAll(MAX_BYTES), BODY_TIME) end)
    	if not read then
    		local code = errorCode(raw)
    		if code == "limit_exceeded" then
    			fail(operation, 200, false, "Exa returned more than " .. tostring(MAX_BYTES // 1048576)
    				.. " MiB; request fewer results or less text")
    		elseif code == "timeout" then
    			fail(operation, 200, true, "Exa did not finish sending its answer within " .. tostring(BODY_TIME // 1000) .. " s; retry")
    		elseif code == "cancelled" then
    			error(raw, 0)
    		end
    		local detail = if type(raw) == "table" and type(raw.message) == "string" then raw.message else tostring(raw)
    		fail(operation, 200, true, "Exa response failed: " .. string.sub(detail, 1, 300))
    	end
    	local ok, value = false, nil
    	if string.match(raw, "^%s*{") then ok, value = pcall(json.decode, raw) end
    	-- results is an array and answer a string or an object; an explicit JSON null (userdata) is neither.
    	local result = if ok and type(value) == "table" then value[field] else nil
    	if not (type(result) == "table" or (field == "answer" and type(result) == "string")) then
    		fail(operation, 200, false, "Exa returned an unexpected answer")
    	end
    	return value
    end
    
    local function search(input: Options?): any
    	local body = fields(input, SEARCH, "search", "")
    	required(body, "query", "search")
    	budget(body.contents, body.numResults or DEFAULT_RESULTS)
    	return call("search", "/search", body, "results")
    end
    
    local function findSimilar(input: Options?): any
    	local body = fields(input, SIMILAR, "findSimilar", "")
    	required(body, "url", "findSimilar")
    	budget(body.contents, body.numResults or DEFAULT_RESULTS)
    	return call("findSimilar", "/findSimilar", body, "results")
    end
    
    local function getContents(input: Options?): any
    	local body = fields(input, GET_CONTENTS, "getContents", "")
    	required(body, "urls", "getContents")
    	assert(body.text ~= nil or body.highlights ~= nil or body.summary ~= nil, "getContents requires text, highlights or summary")
    	budget(body, #body.urls)
    	return call("getContents", "/contents", body, "results")
    end
    
    local function answer(input: Options?): any
    	local body = fields(input, ANSWER, "answer", "")
    	required(body, "query", "answer")
    	return call("answer", "/answer", body, "answer")
    end
    
    local function help(): string
    	local n = tostring
    	return [[Exa: web search built for agents (https://exa.ai/docs), with your connection's Exa API key. Credentials stay on Houston. Read-only: nothing is created or changed in Exa or on the web. Calls return completed values; do not wrap them in await(). Each call makes one Exa request with no paging (Houston retries an HTTP 429 briefly, nothing else), and results keep Exa's field names and values (requestId, results, costDollars, warnings, notices...).
    
    Every call spends the connection's Exa credits (about $0.004 to $0.012 per search, $0.005 per answer, $0.001 per page and content type for getContents; each search result above 10 and each AI summary add $0.001). Read costDollars in each result. Search once with the content you need instead of searching, then fetching each page. Bounds: numResults and urls 1 to ]] .. n(MAX_RESULTS) .. [[ (default ]] .. n(DEFAULT_RESULTS) .. [[); text.maxCharacters defaults to ]] .. n(TEXT_DEFAULT) .. [[ (also for text = true) and highlights.maxCharacters is at most ]] .. n(HIGHLIGHTS_MAX) .. [[; together, times the number of results, they allow at most ]] .. n(TEXT_BUDGET) .. [[ characters per call (one page of ]] .. n(TEXT_BUDGET) .. [[, or 25 of 20000). Unknown options and invalid values fail before any request, so they cost nothing.
    
    ## search({query, type?, numResults?, category?, includeDomains?, excludeDomains?, startPublishedDate?, endPublishedDate?, userLocation?, moderation?, objective?, additionalQueries?, systemPrompt?, outputSchema?, contents?})
    
    POST /search. Returns `{requestId, results, costDollars, searchTime, output?, warnings?, notices?}`; there is no paging. Each result has id (its URL, also accepted by getContents), url, title, publishedDate?, author?, image?, favicon?, and the requested text, highlights (array of strings), summary, extras, or entities (structured company, person or publication data for those categories). Pass notices to the reader with the results; warnings name request fields that had no effect.
    - query: natural language describing the pages wanted, such as "recent papers comparing hybrid and dense retrieval", at most ]] .. n(MAX_QUERY) .. [[ bytes. Prefer includeDomains over site: in the query.
    - type: auto (default, about 1 s), lite (cheapest, about 0.5 s, cached content only; rejects additionalQueries, outputSchema, systemPrompt, summary, extras, livecrawlTimeout and maxAgeHours), deep-lite (about 4 s, synthesized) or deep (4 to 15 s, multi-step research with synthesis).
    - category: ]] .. table.concat(CATEGORIES, ", ") .. [[. company and people return profiles and reject published dates; people also rejects excludeDomains.
    - includeDomains, excludeDomains: arrays of hosts, host paths or *.subdomain wildcards, such as {"arxiv.org", "github.com/exa-labs", "*.gov"}.
    - startPublishedDate, endPublishedDate: ISO 8601 date (a whole UTC day: from its start, or through its end) or date-time with seconds.
    - userLocation: two-letter country code such as "US", or {country?, latitude?, longitude?}. moderation: true filters unsafe content.
    - objective: the task behind the query, what should rank first and what to extract. additionalQueries: 1 to 10 extra phrasings, deep types only.
    - outputSchema: {type = "text", description} or a JSON Schema object (at most 10 properties, 2 levels); adds about 2 s and returns output = {content, grounding} citing results. systemPrompt guides that synthesis.
    - contents: what to return for each result; without it, results carry only metadata. Each content type is billed separately, so request one unless the task needs more.
      - highlights: true (recommended: excerpts sized to their relevance) or {query?, maxCharacters?}; query steers which excerpts are chosen.
      - text: true or {maxCharacters?, verbosity? (compact, standard or full), includeHtmlTags?, includeSections?, excludeSections?}; sections are ]] .. table.concat(SECTIONS, ", ") .. [[.
      - summary: true or {query?, schema?}; an AI summary string per page; with schema, a JSON string matching it, to read with json.decode.
      - extras: {links?, imageLinks?, richImageLinks?}, 0 to ]] .. n(LINKS_MAX) .. [[ links per page.
      - maxAgeHours: -1 (cache only) to 720; 0 always fetches the live page. livecrawlTimeout: 1 to ]] .. n(LIVECRAWL_MAX) .. [[ ms (Exa's default 10000); with a fresh fetch, set it low, especially on deep types, so the call finishes in time. snapshotAsOf: a past date or date-time, served from stored versions.
    
    ## findSimilar({url, numResults?, excludeSourceDomain?, category?, includeDomains?, excludeDomains?, startPublishedDate?, endPublishedDate?, contents?})
    
    POST /findSimilar. Pages similar to url, with the same result and contents shapes as search plus score (higher is more similar, comparable within one response). excludeSourceDomain = true leaves out url's own site. Exa deprecates this endpoint in favor of search with a query describing the source, so prefer that when you can describe it.
    
    ## getContents({urls, text?, highlights?, summary?, extras?, maxAgeHours?, livecrawlTimeout?, snapshotAsOf?})
    
    POST /contents. Contents for 1 to ]] .. n(MAX_RESULTS) .. [[ URLs, with the contents options of search at the top level; at least one of text, highlights or summary is required. Returns `{requestId, results, statuses, costDollars}`: results are only the pages read, and statuses holds one {id, status = "success" or "error", source?, error = {tag, httpStatusCode}?} per URL. Tags include CRAWL_NOT_FOUND, CRAWL_HTTP_403, CRAWL_TIMEOUT, CRAWL_LIVECRAWL_TIMEOUT and SOURCE_NOT_AVAILABLE; a failed URL does not fail the call. Contents are billed per page and content type.
    
    ## answer({query, model?, systemPrompt?, userLocation?, outputSchema?})
    
    POST /answer. Exa searches and answers with an LLM: `{requestId, answer, citations, costDollars}`, where answer is a string, or an object matching outputSchema (a JSON Schema), and citations are {id, url, title, publishedDate?, author?} of the sources used. model: ]] .. table.concat(MODELS, ", ") .. [[ (default exa). Read a citation's page with getContents.
    
    ## Errors and limits
    
    Exa errors fail as upstream errors with the HTTP status, Exa's tag and message and its request ID, such as "Exa HTTP 402 NO_MORE_CREDITS: ...". 401 means the API key is invalid; 402 that credits or a spending budget ran out; 403 that the plan lacks a feature or moderation refused the request; 400 that options conflict (such as an option lite does not accept). HTTP 429, 500, 503 and 504 are retryable: Exa allows 10 searches or answers and 5 deep searches per second per team, and Houston waits and retries a refused request briefly. A call gives Exa ]] .. n((CALL_TIME - BODY_TIME) // 1000) .. [[ s to answer and reads at most ]] .. n(MAX_BYTES // 1048576) .. [[ MiB; past that it fails, and Exa may still bill it. A timed-out call is not retryable: make it faster (another type or model, fewer results, a lower livecrawlTimeout) before calling again. Not exposed: Exa Agent runs, the exa-research answer model, monitors, batches, Websets, team and API key management, streaming, subpage crawling and Exa's deprecated options.
    
    ## Example
    
    Here exa is the configured Exa connection.
    
    ```lua
    local found = exa.search({query = "open-source vector databases benchmarked in 2026", numResults = 5,
    	startPublishedDate = "2026-01-01", contents = {highlights = {query = "benchmark results"}}})
    for _, result in found.results do print(result.title, result.url, result.highlights and result.highlights[1]) end
    print(found.costDollars.total)
    if found.results[1] then
    	local page = exa.getContents({urls = {found.results[1].url}, text = {maxCharacters = 20000}})
    	if page.results[1] then print(page.results[1].text) else print(page.statuses[1].error.tag) end
    end
    local reply = exa.answer({query = "Which company makes the Exa search API?"})
    print(reply.answer, reply.citations[1] and reply.citations[1].url)
    ```]]
    end
    
    return {search = search, findSimilar = findSimilar, getContents = getContents, answer = answer, help = help}
    
  • houston.json
    {
      "schema_version": 2,
      "name": "Exa",
      "stateless": true,
      "files": [
        "connector.luau"
      ],
      "icon": "icon.svg",
      "auth": {
        "api_key": {
          "type": "manual",
          "label": "API key",
          "config": {
            "token": {
              "type": "secret",
              "label": "API key",
              "description": "Create a key on the API Keys page of your Exa dashboard. Exa bills each search, page read and answer to your Exa account.",
              "required": true
            }
          }
        }
      },
      "proxy": [
        {
          "match": {
            "protocol": "http",
            "host": [
              "api.exa.ai"
            ],
            "method": [
              "POST"
            ],
            "path": [
              "/search",
              "/contents",
              "/findSimilar",
              "/answer"
            ]
          },
          "action": {
            "headers": {
              "remove": [
                "Authorization"
              ],
              "set": {
                "x-api-key": "{{auth.api_key.token}}"
              }
            }
          }
        }
      ]
    }
    
  • icon.svgicon.svg
  • README.md
    ---
    description: Search the web with Exa, read pages as clean text, highlights or summaries, find similar pages and get cited answers.
    ---
    
    # Exa
    
    Let agents search the web, find similar pages, read clean page text and highlights,
    and produce summaries or answers with citations. Filters narrow searches by site,
    date, country or category.
    
    > Exa charges searches, page reads and answers to your team's credits. Set a key
    > budget in Exa to control spending.
    
    Access is read-only. Exa Agent tasks, monitors, batches and Websets are not included.
    
    [Connect Exa](SETUP.md).
    
  • SETUP.md
    # Connect Exa
    
    1. In the [Exa dashboard](https://dashboard.exa.ai/), select the team whose credits
       Houston should use.
    2. Open [API Keys](https://dashboard.exa.ai/api-keys), create a key and copy it.
    3. Paste it into Houston's **API key** and save the connection.
    
    > Searches, page reads and answers spend your team's Exa credits. Set a budget and
    > rate limit for this key on the API Keys page.
    
    ## Advanced
    
    If requests exhaust credits or a budget, check [Billing](https://dashboard.exa.ai/billing)
    and the key's limits. Features depend on your plan; pages requiring sign-in or
    blocking crawlers may be unavailable. Replace deleted keys in Houston.
    
    [Billing and limits](https://exa.ai/docs/admin/billing).
    
  • tests
    • authentication.luau
      return {
      	contract = function(m)
      		m.authentication({
      			{
      				auth = { token = "synthetic-method-secret" },
      				config = {},
      				endpoint = { "POST", "https://api.exa.ai/search" },
      				expected = "synthetic-method-secret",
      				header = "x-api-key",
      				method = "api_key",
      				publisher = {},
      			},
      		})
      	end,
      }
      
    • errors.luau
      -- Invalid input never reaches Exa, and Exa's errors, slow answers and bad bodies map to clear failures.
      return {
      	scenario = {publisher = {}, config = {}, auth_method = "api_key", auth_config = {token = "synthetic-exa-key"}},
      	configure = function()
      		calls = 0
      		status = 200
      		payload = "{}"
      		responseHeaders = {}
      		http = {request = function(req)
      			calls += 1
      			-- A table stands for a failure while waiting for headers, such as a timeout or a refused origin.
      			if requestError then error(requestError, 0) end
      			-- A body whose read fails stands in for a dropped connection or a cancelled invocation.
      			local body = if readError
      				then {readAll = function() error(readError, 0) end, readPrefix = function() error(readError, 0) end, close = function() end}
      				else fixture.reader(payload)
      			return fixture.operation({statusCode = status, headers = responseHeaders, body = body})
      		end}
      	end,
      	run = function(exa)
      		local function rejected(fn, expected)
      			local before = calls
      			local ok, err = pcall(fn)
      			assert(not ok and string.find(tostring(err), expected, 1, true), "wrong validation error: " .. tostring(err))
      			assert(calls == before, "invalid input reached Exa")
      		end
      		local function search(opts) return function() exa.search(opts) end end
      		local function contents(opts) return function() exa.getContents(opts) end end
      
      		rejected(function() exa.search("vector databases") end, "search must be an options table")
      		rejected(function() exa.search() end, "search must be an options table")
      		rejected(search({}), "search requires query")
      		rejected(search({query = " \n"}), "query must be a string of at most 4096 bytes, not only spaces")
      		rejected(search({query = string.rep("a", 4097)}), "query must be a string of at most 4096 bytes")
      		rejected(search({query = 42}), "query must be a string")
      		rejected(search({query = "x", q = "y"}), "search received an unknown option q")
      		rejected(search({"x"}), "search received an unknown option 1")
      		-- Deprecated and unsupported options are refused rather than sent.
      		for _, field in {"includeText", "startCrawlDate", "stream", "compliance", "userIdentifier", "context"} do
      			rejected(search({query = "x", [field] = true}), "search received an unknown option " .. field)
      		end
      		for _, value in {"fast", "instant", "deep-reasoning", "neural", 1} do
      			rejected(search({query = "x", type = value}), "type must be one of auto, lite, deep-lite, deep")
      		end
      		for _, value in {0, 26, 1.5, "10", 100} do
      			rejected(search({query = "x", numResults = value}), "numResults must be an integer from 1 to 25")
      		end
      		for _, value in {"research paper", "pdf", "tweet", "github", ""} do
      			rejected(search({query = "x", category = value}), "category must be one of company, people, news, publication")
      		end
      		rejected(search({query = "x", includeDomains = {}}), "includeDomains must be a dense array of 1 to 1200 entries")
      		rejected(search({query = "x", includeDomains = "arxiv.org"}), "includeDomains must be an array")
      		rejected(search({query = "x", includeDomains = {[1] = "a", [3] = "c"}}), "includeDomains must be a dense array")
      		rejected(search({query = "x", excludeDomains = {domain = "a"}}), "excludeDomains must be a dense array")
      		rejected(search({query = "x", excludeDomains = {"a", ""}}), "excludeDomains[2] must be a URL or host")
      		for _, value in {"arxiv .org", "arxiv.org\n", "\tgithub.com"} do
      			rejected(search({query = "x", includeDomains = {value}}), "includeDomains[1] must be a URL or host of at most 2048 bytes without spaces")
      		end
      		local domains = {}
      		for i = 1, 1201 do domains[i] = "d" .. i .. ".example" end
      		rejected(search({query = "x", includeDomains = domains}), "includeDomains must be a dense array of 1 to 1200 entries")
      		for _, value in {"2026-1-01", "01/31/2026", "2026-01-31 12:00", "2026-01-31T12:00", "2026-01-31T12:00Z", "2026-01-31T12:00::Z", "2026-01-31T12:00:001234Z", "2026-01-31T99:99:99Z", "2026-01-31T24:00:00Z", "2026-01-31T12:60:00Z", "2026-01-31T12:00:60Z", "2026-01-31T12:00:00.Z", "2026-01-31T12:00:00+24:00", "2026-01-31T12:00:00+01:60", "2026-01-31T12:00:00+0100", "2026-02-31", "2025-02-29", "2026-04-31", "1900-02-29", "2026-13-01", "2026-00-10", "2026-01-32", "2026-01-31T12:00:00", "yesterday", 20260131} do
      			rejected(search({query = "x", startPublishedDate = value}), "startPublishedDate must be an ISO 8601 date")
      		end
      		rejected(search({query = "x", endPublishedDate = "2026"}), "endPublishedDate must be an ISO 8601 date")
      		for _, value in {"USA", "u", 1, {country = "USA"}, {latitude = 91, longitude = 0}, {latitude = 0, longitude = -181},
      			{latitude = 1}, {}, {country = "US", city = "SF"}} do
      			rejected(search({query = "x", userLocation = value}), "userLocation")
      		end
      		rejected(search({query = "x", moderation = "yes"}), "moderation must be true or false")
      		rejected(search({query = "x", objective = string.rep("o", 4097)}), "objective must be a string of at most 4096 bytes")
      		rejected(search({query = "x", additionalQueries = {}}), "additionalQueries must be a dense array of 1 to 10 entries")
      		rejected(search({query = "x", additionalQueries = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"}}), "1 to 10 entries")
      		for _, value in {{}, {"text"}, "text", true} do
      			rejected(search({query = "x", outputSchema = value}), "outputSchema must be a JSON Schema object")
      		end
      
      		-- Contents options, nested names included.
      		rejected(search({query = "x", contents = true}), "contents must be an options table")
      		rejected(search({query = "x", contents = {subpages = 2}}), "contents received an unknown option subpages")
      		rejected(search({query = "x", contents = {livecrawl = "always"}}), "contents received an unknown option livecrawl")
      		rejected(search({query = "x", contents = {text = "yes"}}), "contents.text must be an options table")
      		rejected(search({query = "x", contents = {text = {maxCharacters = 500001}}}), "contents.text.maxCharacters must be an integer from 1 to 500000")
      		rejected(search({query = "x", contents = {text = {maxCharacters = 0}}}), "contents.text.maxCharacters must be an integer from 1 to 500000")
      		rejected(search({query = "x", contents = {text = {verbosity = "max"}}}), "contents.text.verbosity must be one of compact, standard, full")
      		rejected(search({query = "x", contents = {text = {includeSections = {"main"}}}}), "contents.text.includeSections[1] must be one of header")
      		rejected(search({query = "x", contents = {text = {includeHtmlTags = 1}}}), "contents.text.includeHtmlTags must be true or false")
      		rejected(search({query = "x", contents = {highlights = {numSentences = 2}}}), "contents.highlights received an unknown option numSentences")
      		rejected(search({query = "x", contents = {highlights = {dynamic = true}}}), "contents.highlights received an unknown option dynamic")
      		rejected(search({query = "x", contents = {highlights = {maxCharacters = 10001}}}), "contents.highlights.maxCharacters must be an integer from 1 to 10000")
      		rejected(search({query = "x", contents = {summary = {schema = {}}}}), "contents.summary.schema must be a JSON Schema object")
      		rejected(search({query = "x", contents = {extras = {links = 21}}}), "contents.extras.links must be an integer from 0 to 20")
      		rejected(search({query = "x", contents = {extras = {codeBlocks = 1}}}), "contents.extras received an unknown option codeBlocks")
      		rejected(search({query = "x", contents = {maxAgeHours = 721}}), "contents.maxAgeHours must be an integer from -1 to 720")
      		rejected(search({query = "x", contents = {maxAgeHours = -2}}), "contents.maxAgeHours must be an integer from -1 to 720")
      		rejected(search({query = "x", contents = {livecrawlTimeout = 8001}}), "contents.livecrawlTimeout must be an integer from 1 to 8000")
      		rejected(search({query = "x", contents = {snapshotAsOf = "last week"}}), "contents.snapshotAsOf must be an ISO 8601 date")
      		-- The text budget counts Exa's default of 10 results.
      		rejected(search({query = "x", contents = {text = {maxCharacters = 50001}}}), "text.maxCharacters (default 10000) plus highlights.maxCharacters, times the number of results, must be at most 500000")
      		rejected(search({query = "x", numResults = 25, contents = {text = {maxCharacters = 20001}}}), "must be at most 500000")
      		rejected(search({query = "x", numResults = 25, contents = {text = {maxCharacters = 10001}, highlights = {maxCharacters = 10000}}}), "must be at most 500000")
      		rejected(function() exa.findSimilar({url = "https://a.example", numResults = 11, contents = {text = {maxCharacters = 50000}}}) end,
      			"must be at most 500000")
      
      		rejected(function() exa.findSimilar({}) end, "findSimilar requires url")
      		rejected(function() exa.findSimilar({url = "https://a.example/x y"}) end, "url must be a URL or host of at most 2048 bytes without spaces")
      		rejected(function() exa.findSimilar({url = "https://a.example/" .. string.rep("p", 2048)}) end, "url must be a URL or host of at most 2048")
      		rejected(function() exa.findSimilar({url = "https://a.example", query = "x"}) end, "findSimilar received an unknown option query")
      		rejected(function() exa.findSimilar({url = "https://a.example", excludeSourceDomain = "true"}) end, "excludeSourceDomain must be true or false")
      		rejected(function() exa.findSimilar({url = "https://a.example", type = "auto"}) end, "findSimilar received an unknown option type")
      
      		rejected(contents({text = true}), "getContents requires urls")
      		rejected(contents({urls = {"https://a.example"}}), "getContents requires text, highlights or summary")
      		rejected(contents({urls = {"https://a.example"}, text = false}), "getContents requires text, highlights or summary")
      		rejected(contents({urls = {}, text = true}), "urls must be a dense array of 1 to 25 entries")
      		rejected(contents({urls = "https://a.example", text = true}), "urls must be an array")
      		rejected(contents({urls = {"https://a.example", "bad url"}, text = true}), "urls[2] must be a URL or host")
      		rejected(contents({ids = {"https://a.example"}, text = true}), "getContents received an unknown option ids")
      		rejected(contents({urls = {"https://a.example"}, text = true, subpages = 1}), "getContents received an unknown option subpages")
      		rejected(contents({urls = {"https://a.example"}, contents = {text = true}}), "getContents received an unknown option contents")
      		local urls = {}
      		for i = 1, 26 do urls[i] = "https://a.example/" .. i end
      		rejected(contents({urls = urls, highlights = true}), "urls must be a dense array of 1 to 25 entries")
      		table.remove(urls)
      		rejected(contents({urls = urls, text = {maxCharacters = 20001}}), "must be at most 500000")
      
      		rejected(function() exa.answer({}) end, "answer requires query")
      		rejected(function() exa.answer({query = "x", model = "gpt-4"}) end, "model must be one of exa, exa-pro, exa-fast")
      		rejected(function() exa.answer({query = "x", model = "exa-research"}) end, "model must be one of")
      		rejected(function() exa.answer({query = "x", text = true}) end, "answer received an unknown option text")
      		rejected(function() exa.answer({query = "x", stream = true}) end, "answer received an unknown option stream")
      		rejected(function() exa.answer({query = "x", outputSchema = "json"}) end, "outputSchema must be a JSON Schema object")
      
      		local function upstream(code, body, headers, call, expected, absent)
      			status, payload, responseHeaders = code, body, headers
      			local before = calls
      			local ok, err = pcall(call)
      			for _, text in expected do
      				assert(not ok and string.find(tostring(err), text, 1, true), "missing " .. text .. " in " .. tostring(err))
      			end
      			if absent then assert(not string.find(tostring(err), absent, 1, true), "unexpected " .. absent .. " in " .. tostring(err)) end
      			assert(calls == before + 1, "a failed request was repeated")
      		end
      		local find = search({query = "x"})
      		local function similar() exa.findSimilar({url = "https://a.example"}) end
      		local read = contents({urls = {"https://a.example"}, highlights = true})
      		local function ask() exa.answer({query = "x"}) end
      		local function envelope(tag, message) return '{"requestId":"a1b2c3","error":"' .. message .. '","tag":"' .. tag .. '"}' end
      
      		upstream(401, envelope("INVALID_API_KEY", "Invalid API key."), {}, find,
      			{"Exa HTTP 401 INVALID_API_KEY: Invalid API key. (request a1b2c3)", '"retryable":false', '"upstream_status":401'})
      		upstream(401, "", {}, ask, {"Exa HTTP 401: check the connection's Exa API key", '"retryable":false'})
      		upstream(402, envelope("NO_MORE_CREDITS", "You have run out of credits."), {}, read,
      			{"Exa HTTP 402 NO_MORE_CREDITS: You have run out of credits.", '"retryable":false'})
      		upstream(403, envelope("FEATURE_DISABLED", "Deep search is not enabled for your plan."), {}, find,
      			{"Exa HTTP 403 FEATURE_DISABLED: Deep search", '"retryable":false'})
      		upstream(400, envelope("INVALID_REQUEST_BODY", 'Not supported with type \\"lite\\": contents.summary.'), {}, find,
      			{'Exa HTTP 400 INVALID_REQUEST_BODY: Not supported with type', 'lite', ': contents.summary.', '"retryable":false'})
      		upstream(429, envelope("RATE_LIMIT_EXCEEDED", "Rate limit exceeded."), {["retry-after"] = {"2"}}, similar,
      			{"Exa HTTP 429 RATE_LIMIT_EXCEEDED: Rate limit exceeded. (request a1b2c3); retry after 2s", '"retryable":true', '"upstream_status":429'})
      		upstream(503, envelope("SERVICE_OVERLOADED", "Exa is over capacity."), {["retry-after"] = {"Fri, 30 Oct 2026 07:00:00 GMT"}}, ask,
      			{"Exa HTTP 503 SERVICE_OVERLOADED: Exa is over capacity. (request a1b2c3); retry after Fri, 30 Oct 2026 07:00:00 GMT", '"retryable":true'}, "GMTs")
      		upstream(500, "", {}, read, {"Exa HTTP 500", '"retryable":true'})
      		upstream(502, "<html>Bad Gateway</html>", {}, find, {"Exa HTTP 502", '"retryable":true'}, "Gateway")
      		upstream(504, '{"message":"timeout"}', {}, find, {"Exa HTTP 504", '"retryable":true'}, "timeout")
      		upstream(400, '{"error":"' .. string.rep("y", 1000) .. '","tag":"bad tag!"}', {}, find, {"Exa HTTP 400: " .. string.rep("y", 300)}, string.rep("y", 301))
      		upstream(400, '{"error":"x","tag":"bad tag!"}', {}, find, {"Exa HTTP 400: x"}, "bad tag")
      		upstream(307, "", {location = {"https://elsewhere.example"}}, find, {"Exa HTTP 307: unexpected redirect", '"retryable":false'}, "elsewhere")
      
      		upstream(200, "<html>maintenance</html>", {}, find, {"Exa returned an unexpected answer", '"retryable":false'}, "maintenance")
      		upstream(200, "[]", {}, read, {"Exa returned an unexpected answer"})
      		upstream(200, '{"requestId":"r"}', {}, similar, {"Exa returned an unexpected answer"})
      		upstream(200, '{"results":[]}', {}, ask, {"Exa returned an unexpected answer"})
      		upstream(200, '{"results":null}', {}, find, {"Exa returned an unexpected answer"})
      		upstream(200, '{"results":"none"}', {}, read, {"Exa returned an unexpected answer"})
      		upstream(200, '{"answer":null}', {}, ask, {"Exa returned an unexpected answer"})
      		upstream(200, '{"answer":42}', {}, ask, {"Exa returned an unexpected answer"})
      		upstream(200, '{"results":[' .. string.rep('{"text":"' .. string.rep("z", 1024) .. '"},', 4 * 1024) .. '{}]}', {}, find,
      			{"Exa returned more than 4 MiB; request fewer results or less text", '"retryable":false'}, "limit")
      
      		requestError = {code = "timeout", message = "request deadline"}
      		upstream(200, "", {}, find, {"Exa did not answer within 23 s; Exa may still bill it", '"retryable":false'})
      		-- Other request failures pass through unchanged, message included, and never become an upstream failure.
      		requestError = {code = "access_denied", message = "origin not allowed"}
      		upstream(200, "", {}, ask, {"origin not allowed"}, "retryable")
      		requestError = nil
      		readError = {code = "timeout", message = "await timed out"}
      		upstream(200, "", {}, read, {"Exa did not finish sending its answer within 4 s; retry", '"retryable":true'})
      		readError = {code = "io_error", message = "connection reset by peer"}
      		upstream(200, "", {}, similar, {"Exa response failed: connection reset by peer", '"retryable":true'})
      		-- An error body that stalls or breaks still gives the structured failure.
      		upstream(503, "", {}, find, {"Exa HTTP 503", '"retryable":true', '"upstream_status":503'}, "reset")
      		readError = {code = "timeout", message = "await timed out"}
      		upstream(402, "", {}, ask, {"Exa HTTP 402", '"retryable":false', '"upstream_status":402'}, "timed out")
      		readError = {code = "cancelled", message = "invocation cancelled"}
      		local before = calls
      		local ok, err = pcall(find)
      		-- A stand-in error loses its native identity across the export boundary; it must still not become an upstream failure.
      		assert(not ok and not string.find(tostring(err), "retryable", 1, true), "cancellation became an upstream error: " .. tostring(err))
      		assert(calls == before + 1)
      		readError = nil
      	end,
      }
      
    • manifest.luau
      return {
      	contract = function(m)
      		-- TestExaRoutes
      		do
      			local r, err = m.resolve(nil, nil, { token = "exa-fixture-key" }, "api_key")
      			assert(not err, tostring(err))
      			local api = "https://api.exa.ai"
      			local dropped = { "Authorization" }
      			for _, path in { "/search", "/contents", "/findSimilar", "/answer" } do
      				local recipe, err = m.recipe(r, "POST", api .. path, nil)
      				if err ~= nil then
      					m.fail("POST %s denied: %s", path, err)
      				end
      				m.rejectPreparedOverrides(recipe, r.Context, "POST " .. path)
      				local caller = { ["Content-Type"] = { "application/json" }, ["X-Api-Key"] = { "forged" } }
      				for _, name in dropped do
      					caller[name] = { "Bearer forged" }
      				end
      				local headers, err = m.prepare(recipe, r.Context, caller)
      				if
      					((err ~= nil) or (m.header(headers, "x-api-key") ~= "exa-fixture-key"))
      					or (m.header(headers, "Content-Type") ~= "application/json")
      				then
      					m.fail("POST %s prepared %s: %s", path, headers, err)
      				end
      				for _, name in dropped do
      					if m.header(headers, name) ~= "" then
      						m.fail("%s reached Exa on %s", name, path)
      					end
      				end
      			end
      			m.routes(r, "", false, {
      				"GET " .. api .. "/search",
      				"POST " .. api .. "/search/x",
      				"POST " .. api .. "/research/v1",
      				"POST " .. api .. "/agent/runs",
      				"GET " .. api .. "/agent/runs/run_1",
      				"POST " .. api .. "/monitors",
      				"POST " .. api .. "/batches",
      				"POST " .. api .. "/chat/completions",
      				"POST " .. api .. "/responses",
      				"GET " .. api .. "/v0/teams/me",
      				"POST " .. api .. "/v0/websets",
      				"POST " .. api .. "/websets/v0/websets",
      				"GET " .. api .. "/team-management/api-keys",
      				"POST " .. api .. "/%2e%2e/agent/runs",
      				"POST " .. api .. "/contents/%2e%2e/agent/runs",
      				"POST https://api.exa.ai.example.com/search",
      				"POST http://api.exa.ai:8080/search",
      				"POST https://exa.ai/search",
      				"POST https://mcp.exa.ai/mcp",
      				"GET https://dashboard.exa.ai/api-keys",
      				"POST https://admin-api.exa.ai/team-management/api-keys",
      			})
      		end
      	end,
      }
      
    • reads.luau
      -- Each export posts one exact JSON body to Exa, with the key left to Houston's proxy, and returns Exa's answer unchanged.
      return {
      	scenario = {publisher = {}, config = {}, auth_method = "api_key", auth_config = {token = "synthetic-exa-key"}},
      	configure = function()
      		requests, responses = {}, {}
      		http = {request = function(req)
      			table.insert(requests, req)
      			for name in req.headers do
      				local lower = string.lower(name)
      				assert(lower ~= "authorization" and lower ~= "x-api-key", "the proxy adds the key")
      			end
      			assert(req.method == "POST" and req.timeoutMs == 23000, "one POST, with the call's time less the body's share")
      			assert(req.headers["Content-Type"][1] == "application/json" and req.headers.Accept[1] == "application/json")
      			assert(#responses > 0, "unexpected request: " .. req.url)
      			return fixture.operation({statusCode = 200, headers = {["content-type"] = {"application/json; charset=utf-8"}},
      				body = fixture.reader(table.remove(responses, 1))})
      		end}
      		function respond(body) table.insert(responses, body) end
      	end,
      	run = function(exa)
      		local function same(a, b)
      			if type(a) ~= "table" or type(b) ~= "table" then return a == b end
      			for key, value in a do
      				if not same(value, b[key]) then return false end
      			end
      			for key in b do
      				if a[key] == nil then return false end
      			end
      			return true
      		end
      		local function posted(path, expected)
      			local req = requests[#requests]
      			assert(req.url == "https://api.exa.ai" .. path, req.url)
      			assert(same(json.decode(req.body), expected), req.body)
      			return req.body
      		end
      
      		local names = {}
      		for name, fn in exa do
      			assert(type(fn) == "function")
      			table.insert(names, name)
      		end
      		table.sort(names)
      		assert(table.concat(names, ",") == "answer,findSimilar,getContents,search", table.concat(names, ","))
      		assert(#requests == 0, "initialization reached Exa")
      
      		-- A bare search sends only the query; an empty result list stays an array.
      		respond('{"requestId":"r0","results":[],"searchTime":412.5,"costDollars":{"total":0.007}}')
      		local found = exa.search({query = "zzqx nothing matches"})
      		posted("/search", {query = "zzqx nothing matches"})
      		assert(json.encode(found.results) == "[]" and found.costDollars.total == 0.007 and found.requestId == "r0")
      
      		-- Every search option, checked and copied; the caller's table is left unchanged.
      		local opts = {query = "open-source vector databases", type = "auto", numResults = 25, category = "news",
      			includeDomains = {"arxiv.org", "github.com/exa-labs", "*.gov"}, excludeDomains = {"example.com"},
      			startPublishedDate = "2026-01-01", endPublishedDate = "2026-06-30", userLocation = "FR",
      			moderation = true, objective = "Benchmarks first; skip vendor pages",
      			contents = {text = {maxCharacters = 18000, verbosity = "standard", includeSections = {"body"}, excludeSections = {"footer", "navigation"},
      				includeHtmlTags = false}, highlights = {query = "benchmark results", maxCharacters = 2000}, summary = {query = "Main finding"},
      				extras = {links = 5, imageLinks = 0, richImageLinks = 2}, maxAgeHours = 24, livecrawlTimeout = 8000}}
      		respond('{"requestId":"r1","results":[{"id":"https://arxiv.org/abs/2601.00001","url":"https://arxiv.org/abs/2601.00001",'
      			.. '"title":"Benchmarking vector databases","publishedDate":"2026-01-12T00:00:00.000Z","author":null,'
      			.. '"text":"# Benchmarking","highlights":["Qdrant led recall at 0.98."],"summary":"Qdrant led.","extras":{"links":["https://qdrant.tech"]}}],'
      			.. '"notices":[{"code":"SITE_OPERATOR_IGNORED","path":"/query","message":"No page matched."}],'
      			.. '"warnings":[{"code":"IGNORED_FIELD","path":"/x","message":"x has no effect."}],"costDollars":{"total":0.023}}')
      		found = exa.search(opts)
      		posted("/search", {query = "open-source vector databases", type = "auto", numResults = 25, category = "news",
      			includeDomains = {"arxiv.org", "github.com/exa-labs", "*.gov"}, excludeDomains = {"example.com"},
      			startPublishedDate = "2026-01-01T00:00:00.000Z", endPublishedDate = "2026-06-30T23:59:59.999Z", userLocation = "FR",
      			moderation = true, objective = "Benchmarks first; skip vendor pages",
      			contents = {text = {maxCharacters = 18000, verbosity = "standard", includeSections = {"body"}, excludeSections = {"footer", "navigation"},
      				includeHtmlTags = false}, highlights = {query = "benchmark results", maxCharacters = 2000}, summary = {query = "Main finding"},
      				extras = {links = 5, imageLinks = 0, richImageLinks = 2}, maxAgeHours = 24, livecrawlTimeout = 8000}})
      		assert(found.results[1].highlights[1] == "Qdrant led recall at 0.98." and found.results[1].extras.links[1] == "https://qdrant.tech")
      		assert(found.notices[1].code == "SITE_OPERATOR_IGNORED" and found.warnings[1].code == "IGNORED_FIELD")
      		assert(opts.startPublishedDate == "2026-01-01" and opts.contents.text.maxCharacters == 18000, "caller options were modified")
      
      		-- Deep search with synthesis; text = true gets the default limit, highlights = true stays true, a bare summary is an
      		-- object and false leaves a content type out.
      		local schema = {type = "object", properties = {leader = {type = "string"}}, required = {"leader"}}
      		respond('{"requestId":"r2","results":[{"id":"u","url":"https://u.example","title":"U"}],'
      			.. '"output":{"content":{"leader":"Qdrant"},"grounding":[{"field":"leader","citations":[{"url":"https://u.example","title":"U"}]}]}}')
      		found = exa.search({query = "vector database leader", type = "deep", additionalQueries = {"best vector DB 2026"},
      			systemPrompt = "Prefer primary sources", outputSchema = schema, userLocation = {country = "US", latitude = 37.77, longitude = -122.42},
      			contents = {text = true, highlights = true, summary = true, extras = {}}, includeDomains = {"x.example"}, endPublishedDate = "2026-01-31T12:00:00+01:00"})
      		local raw = posted("/search", {query = "vector database leader", type = "deep", additionalQueries = {"best vector DB 2026"},
      			systemPrompt = "Prefer primary sources", outputSchema = schema, userLocation = {country = "US", latitude = 37.77, longitude = -122.42},
      			contents = {text = {maxCharacters = 10000}, highlights = true, summary = {}, extras = {}}, includeDomains = {"x.example"}, endPublishedDate = "2026-01-31T12:00:00+01:00"})
      		assert(string.find(raw, '"summary":{}', 1, true) and string.find(raw, '"extras":{}', 1, true), "empty options are objects: " .. raw)
      		assert(found.output.content.leader == "Qdrant" and found.output.grounding[1].field == "leader")
      		respond('{"results":[]}')
      		exa.search({query = "x", type = "lite", contents = {text = false, highlights = true}, userLocation = {latitude = 0, longitude = 0}})
      		posted("/search", {query = "x", type = "lite", contents = {highlights = true}, userLocation = {latitude = 0, longitude = 0}})
      
      		-- The text budget counts text and sized highlights of every result: one page may take all of it.
      		respond('{"results":[]}')
      		exa.search({query = "x", numResults = 5, contents = {text = {maxCharacters = 90000}, highlights = {maxCharacters = 10000}}})
      		posted("/search", {query = "x", numResults = 5, contents = {text = {maxCharacters = 90000}, highlights = {maxCharacters = 10000}}})
      
      		-- Similar pages keep Exa's scores.
      		respond('{"requestId":"r3","results":[{"id":"https://b.example","url":"https://b.example","title":"B","score":0.91}],"costDollars":{"total":0.005}}')
      		found = exa.findSimilar({url = "https://exa.ai/blog/dynamic-highlights", numResults = 3, excludeSourceDomain = true,
      			category = "company", contents = {highlights = true}})
      		posted("/findSimilar", {url = "https://exa.ai/blog/dynamic-highlights", numResults = 3, excludeSourceDomain = true,
      			category = "company", contents = {highlights = true}})
      		assert(found.results[1].score == 0.91)
      		respond('{"results":[]}')
      		found = exa.findSimilar({url = "exa.ai", startPublishedDate = "2025-01-01T00:00:00+02:00", endPublishedDate = "2028-02-29", includeDomains = {"a.example", "*.gov", "github.com/exa-labs"}})
      		posted("/findSimilar", {url = "exa.ai", startPublishedDate = "2025-01-01T00:00:00+02:00", endPublishedDate = "2028-02-29T23:59:59.999Z", includeDomains = {"a.example", "*.gov", "github.com/exa-labs"}})
      		assert(json.encode(found.results) == "[]")
      
      		-- Contents keep Exa's per-URL statuses, including failures inside a successful answer.
      		respond('{"requestId":"r4","results":[{"id":"https://a.example","url":"https://a.example","title":"A","text":"Hello"}],'
      			.. '"statuses":[{"id":"https://a.example","status":"success","source":"cached"},'
      			.. '{"id":"https://gone.example","status":"error","error":{"tag":"CRAWL_NOT_FOUND","httpStatusCode":404}}],"costDollars":{"total":0.002}}')
      		local pages = exa.getContents({urls = {"https://a.example", "https://gone.example"}, text = true, maxAgeHours = 0,
      			snapshotAsOf = "2026-01-15"})
      		posted("/contents", {urls = {"https://a.example", "https://gone.example"}, text = {maxCharacters = 10000}, maxAgeHours = 0,
      			snapshotAsOf = "2026-01-15"})
      		assert(pages.results[1].text == "Hello" and pages.statuses[2].error.tag == "CRAWL_NOT_FOUND")
      		respond('{"results":[],"statuses":[{"id":"https://x.example","status":"error","error":{"tag":"SOURCE_NOT_AVAILABLE","httpStatusCode":403}}]}')
      		pages = exa.getContents({urls = {"https://x.example"}, highlights = {query = "pricing"}, summary = {schema = schema},
      			text = {maxCharacters = 500000}, snapshotAsOf = "2024-02-29T08:30:00.123456-05:30"})
      		posted("/contents", {urls = {"https://x.example"}, highlights = {query = "pricing"}, summary = {schema = schema},
      			text = {maxCharacters = 500000}, snapshotAsOf = "2024-02-29T08:30:00.123456-05:30"})
      		assert(json.encode(pages.results) == "[]" and pages.statuses[1].status == "error")
      
      		-- Answers can be text or structured, with or without citations.
      		respond('{"requestId":"r5","answer":"Exa Labs.","citations":[{"id":"https://exa.ai","url":"https://exa.ai","title":"Exa"}],'
      			.. '"costDollars":{"total":0.005}}')
      		local reply = exa.answer({query = "Who makes Exa?"})
      		posted("/answer", {query = "Who makes Exa?"})
      		assert(reply.answer == "Exa Labs." and reply.citations[1].url == "https://exa.ai")
      		respond('{"answer":{"leader":"Qdrant"},"citations":[]}')
      		reply = exa.answer({query = "Which vector DB leads?", model = "exa-pro", systemPrompt = "Be brief", userLocation = "GB",
      			outputSchema = schema})
      		posted("/answer", {query = "Which vector DB leads?", model = "exa-pro", systemPrompt = "Be brief", userLocation = "GB",
      			outputSchema = schema})
      		assert(reply.answer.leader == "Qdrant" and json.encode(reply.citations) == "[]")
      		assert(#responses == 0, "every queued answer was used")
      	end,
      }