diegosouzapw/OmniRoute · error

Invalid image URL: must be a non-empty string

Error message

Invalid image URL: must be a non-empty string

What it means

Type/emptiness guard at the top of resolveImageAsDataUri: the imageUrl argument is falsy or not a string. The caller passed an invalid image reference (undefined/null/empty) from a normalized message part, so no URL resolution or data-URI conversion can be attempted.

Solutions

  1. Filter empty image parts out of the message before calling the resolver
  2. Validate the image_url.url shape with a Zod schema at the API boundary
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at src/lib/guardrails/visionBridgeHelpers.ts:288 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/d0b843345525ed95. Report an issue: GitHub.

Appendix: source

Thrown at src/lib/guardrails/visionBridgeHelpers.ts:288

      const dataUri = byIndex.get(imageIndex);
      imageIndex++;
      if (dataUri) {
        (part as { image_url?: { url: string } }).image_url = { url: dataUri };
      }
    }
  }
  return result;
}

/**
 * Resolve image URL to data URI format for vision model.
 * - HTTP/HTTPS URLs: passed through as-is
 * - Data URIs: passed through as-is
 * - Base64 without media type: assumed PNG
 */
export function resolveImageAsDataUri(imageUrl: string): string {
  if (!imageUrl || typeof imageUrl !== "string") {
    throw new Error("Invalid image URL: must be a non-empty string");
  }

  // Already a data URI
  if (imageUrl.startsWith("data:")) {
    return imageUrl;
  }

  // HTTP/HTTPS URL - vision API will fetch it
  if (imageUrl.startsWith("http://") || imageUrl.startsWith("https://")) {
    return imageUrl;
  }

  // Assume it's a base64 string without prefix
  // Add PNG as default media type
  return `data:image/png;base64,${imageUrl}`;
}

async function fetchRemoteImageAsDataUri(

View on GitHub (pinned to a179ffed5b)