Python SDK

A typed, sync client for Python: search, documents and uploads, with retries only where they are safe.

byterover calls the ByteRover API from Python. 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

pip install byterover
  • Python 3.11 or later; tested on 3.11, 3.12 and 3.13. The import name is byterover.
  • Its runtime dependencies are httpx and pydantic.
  • The client is sync and thread-safe: one client, shared by your threads, holds one pool of connections.
  • Version 0.2.0 replaces the old byterover client (0.1.x) on PyPI, and isn't compatible with it. See Versioning and support.

Make a client

from byterover import ByteRover

client = ByteRover()  # reads BYTEROVER_API_KEY

found = 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 raises when there is none. See Authentication and API keys. The SDK's error messages and logs never include the key, and the httpx errors it chains hold their request without it. repr(client) shows only brv_ and four characters. Use the client in a with block, or call client.close(), to close its connections. After os.fork(), make a new client in the child.

Options

OptionDefault
api_keyBYTEROVER_API_KEY.
base_urlBYTEROVER_BASE_URL, then https://byterover.ai/api. It must use https, except on localhost, 127.x.x.x or [::1].
timeout60 seconds for each step of an 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. See Timeouts for what it bounds.
max_retries2. See Errors and retries.
http_clientAn httpx.Client of the client's own. Part uploads go through it too. Redirects are never followed and its own auth is never used.
loggerNone, so nothing is logged. A logging.Logger works.

Every API call also takes options of its own as keyword arguments: timeout, max_retries and traceparent, and idempotency_key for a write. documents.upload, upload_directory, uploads.resume and operations.wait take options of their own.

patient = ByteRover(timeout=120, max_retries=3)
drives = patient.drives.list(timeout=10).drives

What it covers

MethodsFor
client.searchSearch one or more drives.
client.key.retrieveThe key, its scope and the drives it reaches.
client.drives.list, retrieveThe drives the key reaches.
client.folders.list, create, move, deleteThe folders of a drive. See Documents and folders.
client.documents.list, retrieve, list_revisions, read, contentFind documents, read their text, download the original file.
client.documents.put_text, update, copy, deleteChange documents.
client.documents.upload, upload_directoryUpload files, one or a whole folder.
client.uploads.create, list_parts, put_part, complete, resumeThe steps of an upload, one by one.
client.operations.retrieve, waitThe work a write started.
client.requestAny other path under /v1/, with the same key, timeouts and retries.

Types

Fields keep the API's names, such as drive_ids, next_cursor and apiKey. Responses are pydantic models, built without validation: fields a newer API adds are kept (model_extra, and to_dict() gives the response as it came), and a value this version of the SDK doesn't list, such as a new document status, arrives as a string. So give a match on one a default case. Requests are typed with closed values, so a type checker catches a misspelled effort.

from byterover.types import Document, SearchResult


def where(result: SearchResult) -> str:
    return " > ".join(result.location.heading_path)


def label(document: Document) -> str:
    match document.status:
        case "searchable":
            return "Ready"
        case "failed":
            return "Failed"
        case _:
            return "Processing"

Status, headers and the trace ID

Any call gives you the response's status and headers through client.with_raw_response:

answered = client.with_raw_response.drives.retrieve("drv_4h7k2m9q8r1t5v6w3x0y")
print(answered.data.name, answered.status, answered.trace_id)

Quote the trace_id, from a response or an error, when you contact support.

Next

On this page