DayuanJiang/next-ai-draw-io · error · Error

${varName} must be >= ${min}, got: ${parsed}

Error message

${varName} must be >= ${min}, got: ${parsed}

What it means

parseIntSafe enforces an optional lower bound; when the parsed integer is below min (e.g. 0 or negative for a count), it throws naming the variable and minimum.

Source

Thrown at lib/ai-providers.ts:232

    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)
 * - ANTHROPIC_THINKING_TYPE: Anthropic thinking type (enabled)
 * - GOOGLE_THINKING_BUDGET: Google Gemini 2.5 thinking budget in tokens (1024-100000)
 * - GOOGLE_THINKING_LEVEL: Google Gemini 3 thinking level (low/high)

View on GitHub (pinned to 155ef4f7ac)

Solutions

  1. Set the value to at least the documented minimum (usually 1)
  2. Remove the env var entirely to disable the option rather than using 0
  3. Double-check for accidental minus signs

Example fix

# before
GOOGLE_TOP_K=0

# after
GOOGLE_TOP_K=1  # or remove the variable entirely
Defensive patterns

Strategy: validation

Validate before calling

const inRange = (v: string, min?: number, max?: number) => {
  const n = Number.parseInt(v, 10)
  return !Number.isNaN(n) && (min === undefined || n >= min) && (max === undefined || n <= max)
}

Type guard

const isNonNegativeInt = (v: string): boolean => /^\d+$/.test(v) && Number.parseInt(v, 10) >= 0

Try / catch

try { ... } catch (e) { if ((e as Error).message.includes('must be >=')) clampOrRemoveEnvVar(e) }

Prevention

When it happens

Trigger: Setting e.g. GOOGLE_TOP_K=0, CANDIDATE_COUNT=-1, or a negative thinking budget where the option requires >= 1.

Common situations: Attempting to disable an option by setting 0, or sign typos/negative values copied from examples.

Related errors


AI-assisted analysis of DayuanJiang/next-ai-draw-io@155ef4f7ac (2026-08-27). Data as JSON: /api/errors/9eaebafe2357c07a. Report an issue: GitHub.