FileRouterClient is the class you use to interact with the hosted FileRouter service. It manages authentication, submits parse and compare jobs to the FileRouter API, and polls for results automatically — you just await the call. The hosted service handles job durability, so transient failures don’t require you to resubmit.
Constructor
ImportFileRouterClient from @file_router/sdk and call new FileRouterClient(). Without any arguments, the client reads FILEROUTER_API_KEY from your environment.
client.ts
Constructor options
Your FileRouter API key. If omitted, the client reads
FILEROUTER_API_KEY from the environment. The constructor throws a FileRouterError with code Auth if no key is found.Override the FileRouter API base URL. Useful for pointing at a staging environment. The client also reads
FILEROUTER_API_URL from the environment as a fallback before using the default.Provide a custom
fetch implementation. Useful in environments where the global fetch is unavailable or you need request interception for testing.How often the client polls for job completion, in milliseconds. Increase this value if you want to reduce API traffic for long-running jobs.
Methods
FileRouterClient exposes two core methods that mirror the BYOK FileRouter interface exactly. This means you can switch between hosted and BYOK modes without changing your parsing logic.
parse()
Process a single document with one provider. Returns a
ParseResult with normalized outputs, page count, and optional raw provider response.compare()
Run one document through multiple providers concurrently. Returns a
CompareResult with a providers array containing each provider’s outcome.Idempotency keys
Bothparse() and compare() on the hosted client accept an idempotencyKey option. The client generates a random UUID for every call by default, so retrying on a network failure is safe. Pass an explicit idempotencyKey when you want to guarantee that re-submitting the same logical job — for example, after a process crash — returns the existing result rather than creating a new job.
An explicit idempotency key for this request. When you retry with the same key, the hosted service returns the result of the original job. If omitted, the client generates a new UUID automatically.
Complete example
The example below sends a PDF by URL to the hosted service, requests markdown and per-page output from thellamaparse provider, and prints the result.
parse-example.ts
Explicit retry with idempotency key
idempotent-parse.ts
The hosted service accepts documents up to 100 MB. For direct BYOK mode without this ceiling, see Direct BYOK.