jackwener/OpenCLI · error · ArgumentError

--repeat in the prompt must be a positive integer

Error message

--repeat in the prompt must be a positive integer

What it means

resolveGenerationPlan validates the --repeat value found inside the Midjourney prompt text (flags like `--r 4` or `--repeat 4`). This error is thrown when that in-prompt value is not a string of digits, or is 0/negative. The CLI requires repeat to be a positive integer because it multiplies GPU job count and cost.

Source

Thrown at clis/midjourney/capabilities.js:239

  }
  const quality = promptParamValue(prompt, ['q', 'quality']);
  if (quality && ['v8.1', 'v8.2'].includes(selectedModel)) {
    throw new ArgumentError(`--quality is not supported by ${selectedModel}`);
  }
  if (quality) {
    const normalizedQuality = Number(quality);
    if (![0.25, 0.5, 1].includes(normalizedQuality)) {
      throw new ArgumentError('--quality must be 0.25, 0.5, or 1 for supported legacy models');
    }
  }

  const rawRepeat = promptParamValue(prompt, ['r', 'repeat']);
  const structuredRepeat = args.repeat == null || args.repeat === '' ? null : Number(args.repeat);
  if (structuredRepeat != null && (!Number.isInteger(structuredRepeat) || structuredRepeat < 1)) {
    throw new ArgumentError('--repeat must be a positive integer');
  }
  if (rawRepeat != null && (!/^\d+$/.test(rawRepeat) || Number(rawRepeat) < 1)) {
    throw new ArgumentError('--repeat in the prompt must be a positive integer');
  }
  if (structuredRepeat != null && rawRepeat != null && structuredRepeat !== Number(rawRepeat)) {
    throw new ArgumentError(`--repeat conflicts with the prompt (${structuredRepeat} vs ${rawRepeat})`);
  }
  const repeat = structuredRepeat ?? (rawRepeat == null ? 1 : Number(rawRepeat));
  if (repeat > capabilities.repeatLimit) {
    throw new ArgumentError(`${capabilities.plan || 'current'} plan allows at most ${capabilities.repeatLimit} repeat/permutation jobs`);
  }

  let perJobMinutes = hasOmniReference || promptHasFlag(prompt, ['oref'])
    ? GPU_COST_MINUTES.omni
    : resolution === 'hd'
      ? GPU_COST_MINUTES.imageHd
      : GPU_COST_MINUTES.imageSd;
  if (promptHasFlag(prompt, ['draft'])) perJobMinutes /= 2;
  // The current web service charged a full SD batch for a live V6 --q 0.5
  // job. Keep the cost guard conservative instead of applying historical
  // quality discounts that are no longer reflected in account credits.

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Change the in-prompt flag to a positive integer, e.g. '... --r 4' (or '--repeat 4').
  2. Remove the --r/--repeat flag from the prompt text entirely and pass it via the structured args.repeat option instead.
  3. If repeat was meant to be 0/omitted, delete the flag; the default repeat is 1.
  4. Trim/inspect the final prompt string before calling the API to ensure no empty or malformed flag values remain.

Example fix

// before
await midjourney.generate({ prompt: 'a cat --r 0' });
// after
await midjourney.generate({ prompt: 'a cat', repeat: 4 });
Defensive patterns

Strategy: validation

Validate before calling

function validPromptRepeat(prompt) {
  const m = /(?:^|\s)--(?:r|repeat)(?:[= ]([^\s]+))?/.exec(prompt);
  if (!m) return true;
  const v = m[1];
  return v != null && /^\d+$/.test(v) && Number(v) >= 1;
}
if (!validPromptRepeat(prompt)) throw new Error('fix --r/--repeat in prompt to a positive integer');

Type guard

function isPositiveInt(v) {
  return typeof v === 'number' && Number.isInteger(v) && v >= 1;
}

Try / catch

try {
  await midjourney.generate({ prompt });
} catch (err) {
  if (err instanceof ArgumentError && err.message.includes('--repeat in the prompt')) {
    prompt = prompt.replace(/\s*--(?:r|repeat)(?:[= ]\S+)?/, '');
    return midjourney.generate({ prompt, repeat: 1 });
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling generate/plan with a prompt containing an invalid in-prompt repeat flag, e.g. prompt 'imagine a cat --r abc', '--r 0', '--repeat -2', '--repeat 2.5', or '--r' with no/empty value. Equivalent to a malformed args.repeat but for the prompt-embedded form.

Common situations: Typo in the flag value, copy-pasting examples with fractional repeats, shell quoting swallowing part of the value ('--r ' + empty var), or assuming repeat can be 0 to 'disable' repetition.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/1d44c0427367d0d5. Report an issue: GitHub.