DayuanJiang/next-ai-draw-io · error · Error
At least one of [${customApiKeyEnv.join(", ")}] environment
Error message
At least one of [${customApiKeyEnv.join(", ")}] environment variables is required for ${provider} provider. Please set at least one in your .env.local file. What it means
validateProviderCredentials supports an array of acceptable env var names; when none is set it throws listing all candidates required by that provider.
Source
Thrown at lib/ai-providers.ts:643
}
return null
}
/**
* Validate that required API keys are present for the selected provider
* @param provider - The provider to validate
* @param customApiKeyEnv - Optional custom env var name(s) (from ai-models.json apiKeyEnv)
*/
function validateProviderCredentials(
provider: ProviderName,
customApiKeyEnv?: string | string[],
): void {
// Handle array of env var names - at least one must be set
if (Array.isArray(customApiKeyEnv)) {
const hasAnyKey = customApiKeyEnv.some((envVar) => process.env[envVar])
if (!hasAnyKey) {
throw new Error(
`At least one of [${customApiKeyEnv.join(", ")}] environment variables is required for ${provider} provider. ` +
`Please set at least one in your .env.local file.`,
)
}
return
}
// Anthropic accepts ANTHROPIC_AUTH_TOKEN (Bearer auth) as alternative to ANTHROPIC_API_KEY
if (provider === "anthropic" && !customApiKeyEnv) {
const hasCredential = !!(
process.env.ANTHROPIC_API_KEY || process.env.ANTHROPIC_AUTH_TOKEN
)
if (!hasCredential) {
throw new Error(
`Either ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN environment variable is required for anthropic provider. ` +
`Please set one in your .env.local file.`,
)
}View on GitHub (pinned to 155ef4f7ac)
Solutions
- Set at least one of the env vars listed in the message in .env.local
- Restart the dev server / redeploy so the new env is loaded
- Fix typos in the variable name so it matches one of the listed options
Example fix
# before # (no key set) # after OPENROUTER_API_KEY=sk-or-...
Defensive patterns
Strategy: validation
Validate before calling
const hasAny = (vars: string[]) => vars.some((v) => !!process.env[v])
if (!hasAny(requiredKeyVars)) throw new Error('Missing credentials config') Try / catch
try { getAIModel(...) } catch (e) { if ((e as Error).message.includes('environment variables is required')) showEnvSetupGuide(e) } Prevention
- Fail fast at boot with a credential checklist for the chosen provider
- Restart servers after env edits
- Automate .env drift checks in deployment
When it happens
Trigger: Using a custom provider whose configuration lists multiple possible API key env vars (e.g. OPENROUTER_API_KEY / custom keys) with none present in the environment.
Common situations: Renamed env vars after config changes, forgetting to restart after editing .env.local, deploying without copying env settings.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- ${requiredVar} environment variable is required for ${provid
- Either ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN environment
- Azure requires either AZURE_BASE_URL or AZURE_RESOURCE_NAME
- ${varName} must be a valid integer, got: ${value}
- ${varName} must be >= ${min}, got: ${parsed}
AI-assisted analysis of DayuanJiang/next-ai-draw-io@155ef4f7ac (2026-08-27).
Data as JSON: /api/errors/f740134e1673948c.
Report an issue: GitHub.