Search with the TypeScript SDK

client.search: the passages that answer a question, with the file and place of each.

client.search sends the request of Search and returns its response, typed. The fields are the API's.

import { ByteRover } from "@byterover/sdk";

const client = new ByteRover();

const found = await client.search({
  query: "Which policy section covers EU refunds?",
  drive_ids: ["drv_4h7k2m9q8r1t5v6w3x0y"],
  effort: "medium",
});

effort has no default; medium suits most questions. See Search effort.

folder covers a folder and everything under it. filters narrows by tag, file type and date, and every filter you set must match. See Filters.

const contracts = await client.search({
  query: "Which contracts renew automatically, and what notice do they need?",
  drive_ids: ["drv_4h7k2m9q8r1t5v6w3x0y"],
  effort: "high",
  folder: "/legal",
  filters: { tags: ["legal", "signed"], file_type: ["pdf", "docx"], updated_after: "2026-01-01" },
  group_by_document: false,
});

group_by_document: false lets several passages come from the same document. By default each comes from a different one.

Show the source

Each result is a passage. Its file is in documents, under the same document_id, so a citation can name the file, the page and the headings.

const files = new Map(found.documents.map((document) => [document.document_id, document]));

for (const result of found.results) {
  const file = files.get(result.document_id);
  const page = result.location.page === undefined ? "" : `, page ${result.location.page}`;
  console.log(`${file?.name ?? "A deleted file"}${page}, ${result.location.heading_path.join(" > ")}`);
  console.log(result.text);
}

A file deleted after it was indexed has no entry in documents, though its results still come back.

To read more around a passage, pass its document_id to client.documents.read, with one selector from its location, such as { page: result.location.page } or { heading_path: result.location.heading_path }. See Documents and folders.

Time and price

A search waits up to 105 seconds at medium and 135 seconds at high; pass timeout to change that. A search is charged once it runs, so the SDK never sends it again when its outcome is unknown: after a timeout, a lost connection or a 5xx, you get the error and decide. A search that was refused before it started, with a 429 from ByteRover or a connection that never opened, is retried.

import { APIConnectionError, RateLimitError } from "@byterover/sdk";

try {
  await client.search({ query: "Refund window", drive_ids: ["drv_4h7k2m9q8r1t5v6w3x0y"], effort: "medium" }, { timeout: 60_000 });
} catch (error) {
  if (error instanceof RateLimitError) console.log("Still limited after the retries.");
  else if (error instanceof APIConnectionError && error.sent === "unknown") console.log("It may have run, and been charged.");
  else throw error;
}

When nothing answers

Search ranks passages; it doesn't decide whether they answer the question. You get an empty results list only when nothing in the drives comes close. See Results.

On this page