AI Provider Routing

Route extraction and assisted workflows through workspace-configured encrypted provider keys.

AI calls use provider configuration owned by the organization.

The app should not assume one hard-coded provider for every workspace. Provider selection starts from available, valid keys and can honor workspace defaults.

Routing principles

PrincipleReason
BYOK firstFirms keep control of provider access and cost exposure.
Encrypted storageAPI keys are sensitive workspace secrets.
Runtime validationProvider configuration must be checked before calls run.
Structured errorsProvider failures must be visible enough for retry and support.
Bounded promptsLong documents are chunked before extraction.

Cloudflare fallback

Cloudflare routing can use AI Gateway when available and fall back to native Workers AI when Gateway access is unavailable but Workers AI is permitted.

Fallbacks should be explicit and observable. A slower or failing model should not silently make documents look complete when extraction did not succeed.