TypeScript SDK
A typed client for Node.js: search, documents and uploads, with retries only where they are safe.
@byterover/sdk calls the ByteRover API from Node.js. It types every request and response, uploads files up to 1 GB, and retries a call only when sending it again can't run a write twice.
Install
npm install @byterover/sdk- Node.js 22 or later. ESM (
import) and CommonJS (require) both work. - TypeScript 5.0 or later, with
@types/nodeor the DOM lib. EverymoduleResolutionworks:nodenext,bundlerand the oldernode. - The package has no runtime dependencies.
- Which versions are supported, and what a new version may change: Versioning and support.
Make a client
import { ByteRover } from "@byterover/sdk";
const client = new ByteRover(); // reads BYTEROVER_API_KEY
const found = await client.search({
query: "Which policy section covers EU refunds?",
drive_ids: ["drv_4h7k2m9q8r1t5v6w3x0y"],
effort: "medium",
});The client reads its key from BYTEROVER_API_KEY, and the constructor throws when there is none. See Authentication and API keys. The SDK's error messages and logs never include the key. String(client), JSON.stringify(client) and inspect(client) show only brv_ and four characters. An error thrown by a fetch you pass is kept unchanged as cause.
Options
| Option | Default |
|---|---|
apiKey | BYTEROVER_API_KEY. |
baseUrl | BYTEROVER_BASE_URL, then https://byterover.ai/api. It must use https. Plain http is allowed only on localhost, a 127.x.x.x address or [::1], never on a name under .localhost. |
timeout | 60 seconds for each attempt. A search gets 105 seconds at medium and 135 seconds at high, whatever the client's timeout; pass timeout on the search to change it. |
maxRetries | 2. See Errors and retries. |
fetch | The platform's fetch. Part uploads go through it too. |
logger | None, so nothing is logged. A logger has a debug and a warn method. |
Every API call also takes its own options as its last argument: timeout, maxRetries and signal, and idempotencyKey for a write. documents.upload, uploadDirectory, uploads.putPart, uploads.resume and operations.wait take options of their own, signal among them.
const patient = new ByteRover({ timeout: 120_000, maxRetries: 3 });
const { drives } = await patient.drives.list({ timeout: 10_000 });What it covers
| Methods | For |
|---|---|
client.search | Search one or more drives. |
client.key.retrieve | The key, its scope and the drives it reaches. |
client.drives.list, retrieve | The drives the key reaches. |
client.folders.list, create, move, delete | The folders of a drive. See Documents and folders. |
client.documents.list, retrieve, listRevisions, read, content | Find documents, read their text, download the original file. |
client.documents.putText, update, copy, delete | Change documents. |
client.documents.upload, uploadDirectory | Upload files, one or a whole folder. |
client.uploads.create, listParts, putPart, complete, resume | The steps of an upload, one by one. |
client.operations.retrieve, wait | The work a write started. |
client.request | Any other path under /v1/, with the same key, timeouts and retries. |
Types
Fields keep the API's names, such as drive_ids and next_cursor, and the package exports a type for each request and response. Request types are closed, so a misspelled field is a compile error. Values in a response are open: a newer API may send a status this version of the SDK doesn't list, so give a switch on one a default branch.
import type { Document, SearchResult } from "@byterover/sdk";
function where(result: SearchResult): string {
return result.location.heading_path.join(" > ");
}
function label(document: Document): string {
switch (document.status) {
case "searchable":
return "Ready";
case "failed":
return "Failed";
default:
return "Processing";
}
}Status, headers and the trace ID
Any call gives you the response's status and headers with withResponse():
const { data: drive, response } = await client.drives.retrieve("drv_4h7k2m9q8r1t5v6w3x0y").withResponse();
console.log(drive.name, response.status, response.trace_id);Quote the trace_id, from a response or an error, when you contact support.
Only on a server
The SDK refuses to run in a web page, because everyone who opens the page could read the key. Call the API from your server. The option dangerouslyAllowBrowser: true turns the check off.
Next
- Search: filters, citations, effort and timeouts.
- Upload files: one call for any file up to 1 GB.
- Errors and retries: what is retried, and how to send a write again.