musistudio/claude-code-router · error · Error

prompt is required.

Error message

prompt is required.

What it means

requiredPrompt coerces the tool's prompt argument: it must be a string with non-whitespace content after trimming. Missing, non-string, or blank prompts fail before any model call.

Source

Thrown at packages/core/src/media/service.ts:591

    if (!this.running || !config.mediaTools.enabled) throw new Error("Media service is disabled.");
    return config.mediaTools;
  }

  private executor(modelSelector: string, operation?: MediaOperation): GatewayMediaExecutor {
    const transport = this.gatewayTransport;
    if (!transport) throw new Error("Media gateway transport is not configured.");
    return new GatewayMediaExecutor(resolveProviderMediaTarget(this.requireConfig(), modelSelector, operation), transport);
  }
}

function createCompletion(): Completion {
  let resolve!: (job: MediaJob) => void;
  const promise = new Promise<MediaJob>((value) => { resolve = value; });
  return { promise, resolve };
}

function requiredPrompt(value: unknown): string {
  if (typeof value !== "string" || !value.trim()) throw new Error("prompt is required.");
  const prompt = value.trim();
  return prompt;
}

function optionalString(value: unknown): string | undefined {
  return typeof value === "string" && value.trim() ? value.trim() : undefined;
}

function numberValue(value: unknown): number | undefined {
  return typeof value === "number" && Number.isFinite(value) ? value : undefined;
}

function mediaModelAttempts(plan: MediaModelPlan): string[] {
  const attempts: string[] = [];
  for (const modelSelector of [plan.modelSelector, ...plan.fallbackModelSelectors]) {
    for (let index = 0; index <= plan.retryCount; index += 1) {
      attempts.push(modelSelector);
    }

View on GitHub (pinned to 99f24806c6)

Solutions

  1. Always pass a non-empty trimmed string as prompt
  2. Validate tool arguments against the tool's input schema before invoking
  3. Guard against empty interpolation from variables

Example fix

// before
{ prompt: ``, images: [...] }
// after
{ prompt: "Edit: remove the background", images: [...] }
Defensive patterns

Strategy: type-guard

Validate before calling

if (typeof args.prompt !== "string" || !args.prompt.trim()) throw new TypeError("prompt required");

Type guard

const hasPrompt = (a: { prompt?: unknown }): a is { prompt: string } => typeof a.prompt === "string" && a.prompt.trim().length > 0;

Try / catch

try { await tool(args); } catch (e) { if (e instanceof Error && e.message === "prompt is required.") return badRequest(); throw e; }

Prevention

When it happens

Trigger: Calling a media generation tool with prompt: undefined, a number/object, or " ".

Common situations: MCP client forwards unvalidated JSON arguments; prompt field name mismatch (e.g. text vs prompt); empty template string interpolation.

Related errors


AI-assisted analysis of musistudio/claude-code-router@99f24806c6 (2026-08-27). Data as JSON: /api/errors/7814f38cb282dc29. Report an issue: GitHub.