diegosouzapw/OmniRoute · error

Invalid multipart body

Error message

Invalid multipart body: ${err instanceof Error ? err.message : err}

What it means

images/edits multipart parse failure: constructing formData from the multipart body threw (malformed boundary, missing parts, oversized file). The route logs the raw parser message and returns null, which surfaces as a 400 invalid-body error.

Solutions

  1. Send a well-formed multipart/form-data with correct boundary
  2. Include all required parts (image file + prompt)
  3. Keep files under the route's body-size limit
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at src/app/api/v1/images/edits/route.ts:166 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25). Data as JSON: /api/errors/61a62ae74c55c50a. Report an issue: GitHub.

Appendix: source

Thrown at src/app/api/v1/images/edits/route.ts:166

/** Read the edit input from either multipart/form-data or a JSON/data-URL body. */
async function readEditInput(request: Request): Promise<EditInput | null> {
  const contentType = request.headers.get("content-type") || "";
  let bodySizeSettings: Record<string, unknown> | undefined;
  try {
    bodySizeSettings = await getCachedSettings();
  } catch {
    bodySizeSettings = undefined;
  }
  const bodySizeLimit = getBodySizeLimit("/api/v1/images/edits", bodySizeSettings);
  const rawBody = await readRequestBodyWithLimit(request, bodySizeLimit);
  if (contentType.includes("multipart/form-data")) {
    try {
      const formData = await new Response(rawBody, {
        headers: { "content-type": contentType },
      }).formData();
      return await readMultipartImage(formData);
    } catch (err) {
      log.warn("IMAGE", `Invalid multipart body: ${err instanceof Error ? err.message : err}`);
      return null;
    }
  }
  if (contentType.includes("application/json")) {
    try {
      const parsed = ImageEditJsonSchema.safeParse(
        JSON.parse(new TextDecoder().decode(rawBody)) as unknown
      );
      if (!parsed.success) {
        log.warn("IMAGE", `Invalid JSON edit body shape: ${parsed.error.message}`);
        return null;
      }
      return extractImageEditInputFromJson(parsed.data);
    } catch (err) {
      log.warn("IMAGE", `Invalid JSON edit body: ${err instanceof Error ? err.message : err}`);
      return null;
    }
  }

View on GitHub (pinned to a179ffed5b)