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

GOOGLE_TOP_P must be a number between 0 and 1, got: ${proces

Error message

GOOGLE_TOP_P must be a number between 0 and 1, got: ${process.env.GOOGLE_TOP_P}

What it means

buildProviderOptions parses GOOGLE_TOP_P as a float and requires it in [0,1]; NaN, negative, or >1 values throw with the offending raw string.

Source

Thrown at lib/ai-providers.ts:405

                1,
                8,
            )
            if (candidateCount) {
                options_obj.candidateCount = candidateCount
            }
            const topK = parseIntSafe(
                process.env.GOOGLE_TOP_K,
                "GOOGLE_TOP_K",
                1,
                100,
            )
            if (topK) {
                options_obj.topK = topK
            }
            if (process.env.GOOGLE_TOP_P) {
                const topP = Number.parseFloat(process.env.GOOGLE_TOP_P)
                if (Number.isNaN(topP) || topP < 0 || topP > 1) {
                    throw new Error(
                        `GOOGLE_TOP_P must be a number between 0 and 1, got: ${process.env.GOOGLE_TOP_P}`,
                    )
                }
                options_obj.topP = topP
            }

            if (Object.keys(options_obj).length > 0) {
                options.google = { ...options.google, ...options_obj }
            }
            break
        }
        case "vertexai": {
            const thinkingBudget = parseIntSafe(
                process.env.GOOGLE_VERTEX_THINKING_BUDGET,
                "GOOGLE_VERTEX_THINKING_BUDGET",
                1024,
                100000,
            )

View on GitHub (pinned to 155ef4f7ac)

Solutions

  1. Use a decimal between 0 and 1 (e.g. GOOGLE_TOP_P=0.9)
  2. Use a dot as decimal separator
  3. Remove the variable to use the provider default

Example fix

# before
GOOGLE_TOP_P=90

# after
GOOGLE_TOP_P=0.9
Defensive patterns

Strategy: validation

Validate before calling

const topP = Number.parseFloat(process.env.GOOGLE_TOP_P ?? '')
const ok = Number.isNaN(topP) ? !process.env.GOOGLE_TOP_P : (topP >= 0 && topP <= 1)

Type guard

const isValidTopP = (v: string): boolean => { const n = Number.parseFloat(v); return !Number.isNaN(n) && n >= 0 && n <= 1 }

Try / catch

try { ... } catch (e) { if ((e as Error).message.includes('GOOGLE_TOP_P')) fixTopPEnv() }

Prevention

When it happens

Trigger: GOOGLE_TOP_P=100 (percent-style), '0,5' (comma decimal), or any non-numeric string in .env.local.

Common situations: Developers entering a percentage (50 instead of 0.5), locale-formatted decimals, or trailing characters.

Related errors


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