router.parse(input, options) is the core operation in FileRouter. You pass a document input and an options object specifying which provider to use and what outputs you want, and the method returns a normalized ParseResult. Both FileRouter (BYOK) and FileRouterClient (hosted) expose the same parse() signature, so you can switch between modes without rewriting your parsing logic.
Accepted inputs
You can pass a document as any of the following types:- A URL string or
URLobject (e.g.'https://example.com/report.pdf') - A local file path string (e.g.
'./report.pdf') - A
FileorBlobinstance - An
ArrayBufferor typed array view (Uint8Array, etc.) - A
ReadableStream<Uint8Array> - An explicit object:
{ kind: 'bytes', data, name?, mimeType? }or{ kind: 'url', url }
ParseOptions
The ID of the provider to use for this parse operation (e.g.
'llamaparse', 'mistral-ocr', 'datalab'). If omitted, the router uses the first configured provider.The output types you want in the result. Available values are:
'chunks', 'html', 'images', 'json', 'markdown', 'metadata', 'pages', 'tables', 'text'. The router validates that the selected provider supports every requested output before sending the file — unsupported outputs fail immediately with a ProviderUnsupportedOutput error.A subset of one-based page numbers to process (e.g.
[1, 3, 5]). The router translates these into each provider’s native page representation. When omitted, all pages are processed.Namespaced provider-specific options. Each key matches a provider ID, and only the relevant provider’s options are forwarded. This means provider-specific settings never bleed into other providers during a compare run.
Set to
true to include the complete provider response in result.raw. This can substantially increase result size — use it only when you need access to provider-native fields that aren’t surfaced in the normalized outputs.Maximum time in milliseconds to wait for the job to complete. Defaults to 10 minutes (600 000 ms). If the job doesn’t complete in time, the SDK throws a
FileRouterError with code Timeout.An
AbortSignal for cancelling the operation. Pass AbortSignal.timeout(ms) to enforce a custom timeout without relying on the timeoutMs option.ParseResult
An object containing the requested output values. Only the keys you asked for in
options.outputs are present. Common fields include:The total number of pages in the document as reported by the provider.
The ID of the provider that processed this document (e.g.
'llamaparse').Non-fatal warnings from the provider. Each warning has a
code, a message, and an optional pageNumber.Timing information with
startedAt, completedAt (ISO 8601 strings), and durationMs.The complete provider response. Only present when you set
includeRaw: true in the options.A unique identifier for this parse result.
Complete example
The example below parses a PDF from a URL using LlamaParse, requests both Markdown and per-page output, and passes a custom prompt throughproviderOptions.
parse-with-options.ts
Page numbers are always one-based throughout FileRouter. If you pass
pages: [1, 3], you get the first and third pages of the document. The router translates these into each provider’s native representation automatically.