> ## Documentation Index
> Fetch the complete documentation index at: https://docs.filerouter.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Direct BYOK: Use Your Own Provider API Keys

> Use the FileRouter class with your own LlamaParse, Mistral OCR, or Datalab keys. Documents and credentials never leave your environment.

Direct BYOK (Bring Your Own Key) mode lets you call LlamaParse, Mistral OCR, and Datalab without routing documents or API keys through the FileRouter hosted service. You instantiate `FileRouter` directly with your chosen provider adapters, and every request goes straight from your runtime to the provider. This is ideal for environments with strict data residency requirements or when you already have provider accounts you want to use.

## The FileRouter class

In BYOK mode you use `FileRouter` (not `FileRouterClient`). Import it from `@file_router/sdk` alongside the provider adapter factories from their respective sub-paths.

```ts router.ts theme={null}
import { FileRouter } from '@file_router/sdk'
import { llamaparse } from '@file_router/sdk/llamaparse'
import { mistralOcr } from '@file_router/sdk/mistral'

const router = new FileRouter({
  providers: {
    llamaparse: llamaparse(),
    'mistral-ocr': mistralOcr(),
  },
})
```

### Constructor options

<ParamField body="providers" type="ProviderMap" required>
  An object mapping provider IDs to provider adapter instances. Use the adapter factory functions (`llamaparse()`, `mistralOcr()`, `datalab()`) to create adapters. At least one provider is required.
</ParamField>

## Provider adapters

Each adapter factory reads its standard environment variable automatically so you don't need to hard-code credentials.

### `llamaparse()` — LlamaParse

Import from `@file_router/sdk/llamaparse`. Requires the `@llamaindex/llama-cloud` peer dependency.

```ts llamaparse.ts theme={null}
import { llamaparse } from '@file_router/sdk/llamaparse'

// Reads LLAMA_CLOUD_API_KEY from the environment
const provider = llamaparse()

// Or pass the key explicitly
const providerWithKey = llamaparse({ apiKey: 'llx-...' })
```

### `mistralOcr()` — Mistral OCR

Import from `@file_router/sdk/mistral`. Requires the `@mistralai/mistralai` peer dependency.

```ts mistral.ts theme={null}
import { mistralOcr } from '@file_router/sdk/mistral'

// Reads MISTRAL_API_KEY from the environment
const provider = mistralOcr()

// Or pass the key explicitly
const providerWithKey = mistralOcr({ apiKey: 'your-mistral-key' })
```

### `datalab()` — Datalab

Import from `@file_router/sdk/datalab`. No additional peer dependency required.

```ts datalab.ts theme={null}
import { datalab } from '@file_router/sdk/datalab'

// Reads the Datalab API key from the environment
const provider = datalab()

// Or pass the key explicitly
const providerWithKey = datalab({ apiKey: 'your-datalab-key' })
```

## All providers at once with `builtInProviders()`

If you want to configure all three built-in providers in one call, use `builtInProviders()` from `@file_router/sdk/catalog`. It creates `llamaparse`, `mistral-ocr`, and `datalab` adapters, reading each provider's standard environment variable automatically.

```ts catalog.ts theme={null}
import { FileRouter } from '@file_router/sdk'
import { builtInProviders } from '@file_router/sdk/catalog'

const router = new FileRouter({
  providers: builtInProviders(),
})
```

You can also pass explicit keys for any or all providers:

```ts catalog-with-keys.ts theme={null}
import { FileRouter } from '@file_router/sdk'
import { builtInProviders } from '@file_router/sdk/catalog'

const router = new FileRouter({
  providers: builtInProviders({
    llamaCloudApiKey: 'llx-...',
    mistralApiKey: 'your-mistral-key',
    datalabApiKey: 'your-datalab-key',
  }),
})
```

## Complete example

The example below creates a router with LlamaParse and Mistral OCR, then parses a local file with LlamaParse.

```ts byok-parse.ts theme={null}
import { FileRouter } from '@file_router/sdk'
import { llamaparse } from '@file_router/sdk/llamaparse'
import { mistralOcr } from '@file_router/sdk/mistral'

const router = new FileRouter({
  providers: {
    llamaparse: llamaparse(),
    'mistral-ocr': mistralOcr(),
  },
})

const file = new File([await Bun.file('report.pdf').arrayBuffer()], 'report.pdf', {
  type: 'application/pdf',
})

const result = await router.parse(file, {
  provider: 'llamaparse',
  outputs: ['markdown', 'pages'],
})

console.log(result.outputs.markdown)
console.log(`Parsed ${result.pageCount} page(s)`)
```

<Warning>
  BYOK mode uses each provider's native file size limits. These differ by provider and may be lower or higher than the 100 MB ceiling enforced by the hosted service. Check each provider's documentation for their current limits.
</Warning>

<Note>
  Provider-specific options are namespaced under `providerOptions`, so they are never forwarded to the wrong provider during a `compare()` call. See [parse()](/sdk/parse) for the full `providerOptions` reference.
</Note>
