DayuanJiang/next-ai-draw-io · error · Error
${varName} must be a valid integer, got: ${value}
Error message
${varName} must be a valid integer, got: ${value} What it means
parseIntSafe parses provider option env vars (thinking budget, topK, candidateCount, budgetTokens); a value present but not parseable as base-10 integer throws with the var name and raw value.
Source
Thrown at lib/ai-providers.ts:229
defaultEnvVar: string,
): string | undefined {
if (overrides?.baseUrlEnv) return process.env[overrides.baseUrlEnv]
return process.env[defaultEnvVar]
}
/**
* Safely parse integer from environment variable with validation
*/
function parseIntSafe(
value: string | undefined,
varName: string,
min?: number,
max?: number,
): number | undefined {
if (!value) return undefined
const parsed = Number.parseInt(value, 10)
if (Number.isNaN(parsed)) {
throw new Error(`${varName} must be a valid integer, got: ${value}`)
}
if (min !== undefined && parsed < min) {
throw new Error(`${varName} must be >= ${min}, got: ${parsed}`)
}
if (max !== undefined && parsed > max) {
throw new Error(`${varName} must be <= ${max}, got: ${parsed}`)
}
return parsed
}
/**
* Build provider-specific options from environment variables
* Supports various AI SDK providers with their unique configuration options
*
* Environment variables:
* - OPENAI_REASONING_EFFORT: OpenAI reasoning effort level (minimal/low/medium/high) - for o1/o3/o4/gpt-5
* - OPENAI_REASONING_SUMMARY: OpenAI reasoning summary (auto/detailed) - auto-enabled for o1/o3/o4/gpt-5
* - ANTHROPIC_THINKING_BUDGET_TOKENS: Anthropic thinking budget in tokens (1024-64000)View on GitHub (pinned to 155ef4f7ac)
Solutions
- Set the env var to a plain integer (e.g. GOOGLE_TOP_K=40)
- Remove quotes, spaces, units, and decimals from the value
- Comment out or delete the variable if you don't need the option
Example fix
# before THINKING_BUDGET_TOKENS="1.5k" # after THINKING_BUDGET_TOKENS=1500
Defensive patterns
Strategy: validation
Validate before calling
const isIntString = (v?: string) => v === undefined || (/^-?\d+$/.test(v.trim()))
Type guard
const isParsableInt = (v: string): boolean => /^-?\d+$/.test(v.trim())
Try / catch
try { buildProviderOptions() } catch (e) { failFastConfig((e as Error).message) } // message names the exact env var Prevention
- Lint .env.local for integer fields before boot
- Avoid decimals/units in numeric env vars
- Keep a documented .env.example with valid sample values
When it happens
Trigger: Setting an env var like THINKING_BUDGET_TOKENS or GOOGLE_TOP_K to a non-integer string such as 'auto', '1.5', or '' with whitespace.
Common situations: Copy-pasting config from provider docs where values are decimal or text, trailing spaces/units in .env.local, or shell quoting mistakes.
Related errors
- ${varName} must be >= ${min}, got: ${parsed}
- ${varName} must be <= ${max}, got: ${parsed}
- GOOGLE_TOP_P must be a number between 0 and 1, got: ${proces
- At least one of [${customApiKeyEnv.join(", ")}] environment
- Either ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN environment
AI-assisted analysis of DayuanJiang/next-ai-draw-io@155ef4f7ac (2026-08-27).
Data as JSON: /api/errors/31ce32dc48cee0b3.
Report an issue: GitHub.