NPM library for creating AI model pickers in a standardized fashion based on Vercel AI SDK.
A project vibe coded by Eric Burel at LBKE, a French training organisation (π«π·) with Claude Code.
- β Support for official Vercel AI SDK providers
- β List available providers and their models
- β Dynamic model filtering with flexible options
- β
Dynamic importing of AI SDK provider packages, using JavaScript
import() - β API key name resolution for each provider
- β Provider name synonyms support (e.g., "mistralai" β "mistral")
- β TypeScript support with comprehensive type definitions
- β Works in both Node.js and browser environments
First, install the dependencies for the providers you'll want to support. This package helps picking a provider and loading the right package, but won't install the dependencies for you in order to streamline your JS bundle.
npm install ai
# Pick the providers you want to support
npm install @ai-sdk/mistral @ai-sdk/openai @ai-sdk/anthropic @ai-sdk/groq @ai-sdk/googleπ‘ Want more providers? Contribute to the providers list!
npm install ai-sdk-model-pickerimport { providers, mistralModels, listProviderModels, findModels, loadModel, getApiKeyName } from "ai-sdk-model-picker"
// List all available providers
console.log(providers)
// Output: [{name: "openai", packageName: "@ai-sdk/openai", apiKeyName: "OPENAI_API_KEY"}, ...]
// Get models for Mistral provider
console.log(mistralModels)
// Output: [{name: "mistral-large-latest", type: "language", capabilities: {...}}, ...]
// List models for a specific provider
console.log(listProviderModels({provider: "mistralai"}))
// Output: {provider: "mistralai", models: [{name:"mistral-large-latest", ...}]}
// List models for multiple providers or run a free search (outputs an array of providers + models)
console.log(findModels({providers: ["mistralai", "openai"]}))
// Output: [{provider: "mistralai", models: [{name:"mistral-large-latest", ...}]}]
// List models excluding certain providers/models
console.log(findModels({
excludedProviders: ["xai"],
excludedModels: ["mistralai/codestral-latest"]
}))
// Get API key name for a provider
console.log(getApiKeyName("mistralai"))
// Output: "MISTRAL_API_KEY"
// Load a model dynamically (triggers dynamic import of the provider package)
const modelResult = await loadModel("mistralai/mistral-large-latest")
// This will:
// 1. Dynamically import @ai-sdk/mistral
// 2. Create the model instance: mistral("mistral-large-latest")
// 3. Return {model: <model_instance>, provider: "mistralai", modelName: "mistral-large-latest"}import { findModels } from "ai-sdk-model-picker"
// Filter by model type
const languageModels = findModels({ modelType: 'language' })
const embeddingModels = findModels({ modelType: 'embedding' })
const imageModels = findModels({ modelType: 'image' })
// Complex filtering example
const filteredModels = findModels({
providers: ["openai", "anthropic", "mistralai"],
excludedModels: ["gpt-3.5-turbo", "claude-3-haiku-20240307"],
modelType: "language"
})import { loadModel, getApiKeyName } from "ai-sdk-model-picker"
import { generateText } from "ai"
// Set up environment variables
const provider = "openai"
const modelName = "gpt-4"
const apiKeyName = getApiKeyName(provider)
console.log(`Make sure to set ${apiKeyName} environment variable`)
// Load and use the model
const { model } = await loadModel(`${provider}/${modelName}`)
const { text } = await generateText({
model: model,
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
})
console.log(text)The library supports provider name synonyms for better developer experience:
import { findModels, getApiKeyName } from "ai-sdk-model-picker"
// These are equivalent:
console.log(findModels({provider: "mistral"}))
console.log(findModels({provider: "mistralai"}))
// Both return "MISTRAL_API_KEY"
console.log(getApiKeyName("mistral"))
console.log(getApiKeyName("mistralai"))This library supports all official AI SDK providers:
| Provider | Package | API Key | Synonyms |
|---|---|---|---|
| OpenAI | @ai-sdk/openai |
OPENAI_API_KEY |
- |
| Anthropic | @ai-sdk/anthropic |
ANTHROPIC_API_KEY |
- |
| Mistral AI | @ai-sdk/mistral |
MISTRAL_API_KEY |
mistral |
| Groq | @ai-sdk/groq |
GROQ_API_KEY |
- |
| xAI Grok | @ai-sdk/xai |
XAI_API_KEY |
- |
@ai-sdk/google |
GOOGLE_GENERATIVE_AI_API_KEY |
- |
Models are categorized by type:
language: Text generation models (GPT-4, Claude, etc.)embedding: Text embedding modelsimage: Image generation models (DALL-E, etc.)transcription: Audio transcription models (Whisper)speech: Text-to-speech models
Array of all available providers with their basic information.
interface Provider {
name: string;
packageName: string;
apiKeyName: string;
synonyms?: string[];
}Convenience export for Mistral AI models.
List models with flexible filtering options.
interface findModelsOptions {
provider?: string; // Single provider name
providers?: string[]; // Multiple provider names
excludedProviders?: string[]; // Providers to exclude
excludedModels?: string[]; // Models to exclude (format: "provider/model" or just "model")
modelType?: 'language' | 'embedding' | 'image' | 'transcription' | 'speech';
}Dynamically load a model from its provider package.
interface LoadModelResult {
model: any; // The loaded model instance
provider: string; // Provider name
modelName: string; // Model name
}Model ID Format: "provider/model" (e.g., "openai/gpt-4", "mistralai/mistral-large-latest")
Get the environment variable name for a provider's API key.
The library provides descriptive error messages for common issues:
try {
const model = await loadModel("invalid/model")
} catch (error) {
console.error(error.message)
// "Provider 'invalid' not found"
}
try {
const apiKey = getApiKeyName("nonexistent")
} catch (error) {
console.error(error.message)
// "Provider 'nonexistent' not found"
}Contributions are welcome! The provider data is maintained in src/data/providers.ts. To add support for new providers:
- Add the provider data to
PROVIDERS_DATA - Add any synonyms to
PROVIDER_SYNONYMS - Update the README documentation
- Add tests for the new provider
You can test the "basic-demo.html" example using http-server. Currently, you'll need to manually copy the built "index.mjs" file
in the examples folder.
MIT
Based on research from ai-sdk.dev/providers/ai-sdk-providers