remotion-dev/remotion · error · TypeError

topK must be a non-negative integer.

Error message

topK must be a non-negative integer.

What it means

transcribe() validates the sampling option topK: it must be an integer >= 0 (0 typically disables top-K sampling). Fractional, negative, or non-number values are rejected with a TypeError before transcription starts.

Source

Thrown at packages/whisper-webgpu/src/transcribe.ts:95

		throw new Error(
			'strideLengthInSeconds must be a finite, non-negative number and less than half of chunkLengthInSeconds.',
		);
	}

	if (typeof forceFullSequences !== 'boolean') {
		throw new TypeError('forceFullSequences must be a boolean.');
	}

	if (typeof doSample !== 'boolean') {
		throw new TypeError('doSample must be a boolean.');
	}

	if (!Number.isFinite(temperature) || temperature <= 0) {
		throw new TypeError('temperature must be a finite number greater than 0.');
	}

	if (!Number.isInteger(topK) || topK < 0) {
		throw new TypeError('topK must be a non-negative integer.');
	}

	if (!Number.isFinite(repetitionPenalty) || repetitionPenalty <= 0) {
		throw new TypeError(
			'repetitionPenalty must be a finite number greater than 0.',
		);
	}

	if (!Number.isInteger(noRepeatNgramSize) || noRepeatNgramSize < 0) {
		throw new TypeError('noRepeatNgramSize must be a non-negative integer.');
	}

	if (task !== 'transcribe' && task !== 'translate') {
		throw new TypeError('task must be either "transcribe" or "translate".');
	}

	const {multilingual, supportsTranslation} = getModelInfo(model);
	if (task === 'translate' && !supportsTranslation) {

View on GitHub (pinned to b2f4e34732)

Solutions

  1. Pass an integer >= 0, e.g. topK: 5
  2. Convert with Math.max(0, Math.round(Number(raw))) after parsing
  3. Validate numeric inputs from config files before constructing options

Example fix

// before
await transcribe({topK: '50'});
// after
await transcribe({topK: Math.round(Number(rawTopK))});
Defensive patterns

Strategy: validation

Validate before calling

if (!Number.isInteger(topK) || topK < 0) throw new Error('topK must be a non-negative integer');

Type guard

const isNonNegInt = (v: unknown): v is number => typeof v === 'number' && Number.isInteger(v) && v >= 0;

Try / catch

try {
  await transcribe(options);
} catch (e) {
  if (e instanceof TypeError && e.message.includes('topK')) {
    options.topK = 5;
  } else throw e;
}

Prevention

When it happens

Trigger: Passing topK as a float (e.g. 5.5), a negative number, NaN from parsing, or a string from config.

Common situations: Numeric strings from CLI/JSON options not converted; computing topK dynamically and producing NaN; confusing 0 semantics (0 may mean disabled — it is allowed as non-negative).

Related errors


AI-assisted analysis of remotion-dev/remotion@b2f4e34732 (2026-09-09). Data as JSON: /api/errors/b750b01f2acd1b3c. Report an issue: GitHub.