mastra-ai/mastra · error · InvalidArgumentError
Choose a valid provider: ${LLMProvider.join(', ')}
Error message
Choose a valid provider: ${LLMProvider.join(', ')} What it means
The Mastra CLI throws this when the value passed for the LLM provider option is not one of the supported providers in the LLMProvider list. parseLlmProvider validates the raw string before the CLI uses it to scaffold model configuration. Like parseComponents it raises commander's InvalidArgumentError so the help text is shown.
Source
Thrown at packages/cli/src/commands/utils.ts:88
return value
.split(',')
.map(s => s.trim())
.filter(Boolean);
}
export function parseComponents(value: string) {
const parsedValue = value.split(',');
if (!areValidComponents(parsedValue)) {
throw new InvalidArgumentError(`Choose valid components: ${COMPONENTS.join(', ')}`);
}
return parsedValue;
}
export function parseLlmProvider(value: string) {
if (!isValidLLMProvider(value)) {
throw new InvalidArgumentError(`Choose a valid provider: ${LLMProvider.join(', ')}`);
}
return value;
}
export function shouldSkipDotenvLoading(): boolean {
return process.env.MASTRA_SKIP_DOTENV === 'true' || process.env.MASTRA_SKIP_DOTENV === '1';
}
/**
* Get the version tag (e.g., 'beta', 'latest') for the currently running mastra CLI.
* Create passes its known version to avoid resolving package metadata from an installed layout.
* Init omits it and preserves the existing best-effort undefined fallback.
*/
export async function getVersionTag(version?: string): Promise<string | undefined> {
try {
let currentVersion = version;
if (!currentVersion) {
const pkgPath = fileURLToPath(import.meta.resolve('mastra/package.json'));View on GitHub (pinned to 75dd419e61)
Solutions
- Use one of the providers listed verbatim in the error message
- Check `mastra init --help` (or the command's help) for the exact accepted provider strings
- Upgrade the Mastra CLI (`pnpm dlx mastra@latest init`) if you need a recently added provider
- Fix casing/typos to match the enum exactly
Example fix
// before mastra init --provider OpenAI // after mastra init --provider openai
Defensive patterns
Strategy: validation
Validate before calling
const LLMProvider = ['openai', 'anthropic', 'groq', 'google', 'mistral'] as const;
const provider = 'openai';
if (!LLMProvider.includes(provider as typeof LLMProvider[number])) {
throw new Error(`Invalid provider "${provider}". Valid: ${LLMProvider.join(', ')}`);
} Type guard
const isValidProvider = (v: string): v is LLMProvider => LLMProvider.includes(v as LLMProvider);
Try / catch
try {
runCli(['init', '--provider', provider]);
} catch (e) {
if (e instanceof InvalidArgumentError && e.message.startsWith('Choose a valid provider')) {
console.error(`Unknown provider "${provider}". Supported: ${LLMProvider.join(', ')}`);
} else throw e;
} Prevention
- Copy provider names exactly from CLI --help or the error message
- Normalize casing (toLowerCase) before validating user input
- Pin/upgrade CLI version so the supported provider list matches your expectations
- Test CLI invocations in scripts with --dry-run style checks when available
When it happens
Trigger: Running `mastra init`/`mastra create` with --provider (or equivalent llm provider option) set to a string not in LLMProvider, e.g. 'openai' vs 'OpenAI' casing mismatch or a provider the CLI version doesn't support.
Common situations: Using a newer provider name with an older CLI version; case-sensitivity mistakes ('OpenAI' vs 'openai'); copy-pasting flags from tutorials for a different tool; typos like 'anthropicc'.
Understand the failure class
Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.
Related errors
- Invalid --region "${region}". Expected one of: eu, us.
- MISSING_ARGUMENT
- The --llm option can only be used with the default template
- Directory not found: ${dirArg}.${hint}
- Choose a valid value: ${EDITOR.join(', ')}
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/1ec0bdb6e1eed00d.
Report an issue: GitHub.