diegosouzapw/OmniRoute · error

Vision API returned empty or invalid response

Error message

Vision API returned empty or invalid response

What it means

readVisionResponseBody could not extract any vision result from the upstream response: the body was neither parseable JSON (including the {_streamed, summary} diagnostics envelope) nor an SSE stream parseable by parseSseVisionBody, and reading raw text yielded nothing usable. The vision endpoint answered 2xx but with an empty or unrecognized body shape.

Solutions

  1. Log the raw response text to identify the gateway's HTML/error page
  2. Retry once — some gateways intermittently return empty bodies
Defensive patterns

Strategy: try-catch

When it happens

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

Appendix: source

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

    // JSON path — also unwrap the { _streamed, summary } diagnostics envelope
    // that some OmniRoute capture paths attach to provider responses.
    return unwrapVisionSummary(await response.json());
  } catch {
    // Not JSON — attempt SSE / envelope parsing from the raw text.
  }

  let rawText = "";
  try {
    if (typeof (response as Response & { text?: unknown }).text === "function") {
      rawText = await response.text();
    }
  } catch {
    rawText = "";
  }

  const parsed = parseSseVisionBody(rawText);
  if (parsed === null) {
    throw new Error("Vision API returned empty or invalid response");
  }
  return parsed;
}

/**
 * Extract the description text from an OpenAI-compatible vision response.
 * Falls back to `reasoning_content` then `reasoning` when `content` is empty —
 * reasoning models (e.g. xiaomi/mimo-v2.5, opencode/mimo-v2.5-free) can exhaust
 * `max_tokens` on chain-of-thought and return `content: null` with a complete
 * analysis in a reasoning field. opencode-routed gateways name that field
 * `reasoning` rather than `reasoning_content` (#6623 / #10809).
 */
function extractOpenAICompatibleContent(data: unknown): string {
  const record = data as {
    choices?: Array<{
      message?: { content?: unknown; reasoning_content?: unknown; reasoning?: unknown };
    }>;
    error?: { message?: string };

View on GitHub (pinned to a179ffed5b)