6. AI Provider Interface
Status: Roadmap. This section specifies a planned module; it is not yet implemented in
@mvrx/mail.
Every AI surface in the SDK accepts an AiProvider. The interface is a minimal common denominator that every major LLM satisfies.
6.1 Interface
Section titled “6.1 Interface”interface AiProvider { run( model: string, messages: { role: "system" | "user" | "assistant"; content: string }[] ): Promise<{ text: string }>;}6.2 Pre-Built Connectors
Section titled “6.2 Pre-Built Connectors”Import from @mvrx/mail/providers. Each returns an AiProvider.
Cloudflare Workers AI — zero latency, runs on the same Worker, no egress:
import { cfProvider } from "@mvrx/mail/providers";
const ai = cfProvider(env.AI);// Uses env.AI.run() — default model: @cf/meta/llama-3.3-70b-instruct// Override per-call by passing model name to any SDK methodOpenAI:
import { openaiProvider } from "@mvrx/mail/providers";
const ai = openaiProvider({ apiKey: env.OPENAI_KEY });// Default model: gpt-4o-miniAnthropic:
import { anthropicProvider } from "@mvrx/mail/providers";
const ai = anthropicProvider({ apiKey: env.ANTHROPIC_KEY });// Default model: claude-haiku-4-5-20251001Google Gemini:
import { geminiProvider } from "@mvrx/mail/providers";
const ai = geminiProvider({ apiKey: env.GEMINI_KEY });// Default model: gemini-2.0-flashMistral:
import { mistralProvider } from "@mvrx/mail/providers";
const ai = mistralProvider({ apiKey: env.MISTRAL_KEY });// Default model: mistral-small-latestAzure OpenAI:
import { azureProvider } from "@mvrx/mail/providers";
const ai = azureProvider({ endpoint: "https://my-resource.openai.azure.com", deployment: "gpt-4o-mini", apiKey: env.AZURE_KEY,});Ollama (local / self-hosted):
import { ollamaProvider } from "@mvrx/mail/providers";
const ai = ollamaProvider({ baseUrl: "http://localhost:11434" });// Default model: llama3.2Any OpenAI-compatible endpoint:
import { openaiCompatProvider } from "@mvrx/mail/providers";
const ai = openaiCompatProvider({ baseUrl: "https://openrouter.ai/api/v1", apiKey: env.OPENROUTER_KEY, defaultModel: "meta-llama/llama-3.3-70b-instruct",});Custom:
// Implement the interface directly for any provider not listed aboveconst ai: AiProvider = { run: async (model, messages) => { const res = await myLLM.chat({ model, messages }); return { text: res.output }; },};