Docs / AI Infrastructure / AI providers
AI providers
Keel's AI chat runs on the Vercel AI SDK, so the model is a small, swappable dependency rather than a hardcoded API call. Two providers ship wired up out of the box, and adding a third is a few lines.
What's wired
lib/ai/provider.ts imports both official SDK adapters and exposes one function, getChatModel():
- Anthropic via
@ai-sdk/anthropic, defaulting toclaude-sonnet-4-6. - OpenAI via
@ai-sdk/openai, defaulting togpt-4o-mini.
Each default is overridable without touching code. Set ANTHROPIC_MODEL or OPENAI_MODEL in your env and the provider picks it up:
ANTHROPIC_MODEL=claude-sonnet-4-6
OPENAI_MODEL=gpt-4o-mini
How the provider is selected
resolveProviderId() decides which one to use, in order:
- If
AI_PROVIDERis set toanthropicoropenai, that wins. - Otherwise, whichever API key is present wins (
ANTHROPIC_API_KEY, thenOPENAI_API_KEY). - If neither key is set,
getChatModel()throws, and the chat route returns a clear 503 instead of crashing.
Tip, one key is enough
You don't need to pick a provider explicitly. Drop in a single API key and AI chat just works with it. AI_PROVIDER only matters when both keys are set and you want to pin one.
Adding or swapping a model
Changing the model on an existing provider is env-only (see ANTHROPIC_MODEL / OPENAI_MODEL above). Adding a whole new provider is a small edit to lib/ai/provider.ts:
- Install its SDK adapter, e.g.
bun add @ai-sdk/google. - Import it and add its id to the
AiProviderIdunion. - Add a branch in
resolveProviderId()andgetChatModel()that returnsgoogle(MODEL), mirroring the two existing branches.
Every adapter returns the same LanguageModel type, so nothing downstream in the streaming route changes.