Skip to Content
searchSDK

Search

Search the web through one provider or a fallback chain, with filters, deadlines, retries and a cancel signal.

search(query, options) uses keys from the environment. createClient(config).search(query, options) takes keys and defaults once.

import { search } from "@searchsdk/sdk";

const controller = new AbortController();
const res = await search("postgres full text search", {
  provider: "tavily",
  maxResults: 5,
  recency: "month",
  country: "DE",
  timeoutMs: 10_000,
  signal: controller.signal,
});

Options

OptionMeaning
providerProvider id; required unless the client sets one
fallbackProviders to try next, in order
maxResults1 to 100; default 10
includeDomains, excludeDomainsDomain filters
recencyday, week, month or year
startDate, endDateInclusive YYYY-MM-DD, by publication date
country, languageISO 3166-1 and ISO 639-1 codes
depthfast, standard or deep
providerOptionsOptions one provider understands, keyed by id
timeoutMsDeadline for the whole call; default 30 s
attemptTimeoutMsDeadline for each attempt
maxRetriesRetries of transient failures; default 0
maxResponseBytesLargest response read
signalCancels the call

An option a provider cannot honour fails as unsupported before anything is sent. Each provider's page lists what it honours.

Results

FieldMeaning
urlPage address
title, author, publishedAtOr null when the provider has none
excerptsText the provider matched
rankPosition, from 1
providerFieldsProvider-scoped values such as scores; not comparable across providers

The response also carries provider, cost, requestId, latencyMs, warnings, attempts and raw, the provider's own body.

Errors

Failures throw SearchError with a fixed code and the attempts made.

import { search, SearchError } from "@searchsdk/sdk";

try {
  await search("postgres full text search", { provider: "brave", includeDomains: ["postgresql.org"] });
} catch (e) {
  if (e instanceof SearchError) console.log(e.code, e.field, e.attempts);
}

On this page