diegosouzapw/OmniRoute · error

Failed to parse stage response as JSON

Error message

Failed to parse stage response as JSON

What it means

Error "Failed to parse stage response as JSON" thrown in diegosouzapw/OmniRoute.

Source

Thrown at open-sse/services/autoCombo/pipelineRouter.ts:174

    // Intermediate stage: buffer and extract text
    if (!response.ok) {
      const errorText = await response.text().catch(() => "unknown error");
      log.warn("PIPELINE", `Stage returned ${response.status}: ${errorText.slice(0, 200)}`);
      return { text: "" };
    }

    try {
      const json = await response.json();
      // OpenAI chat completions format: choices[0].message.content
      const content = json?.choices?.[0]?.message?.content;
      if (typeof content === "string") {
        return { text: content };
      }
      // Fallback: try to extract any text field
      return { text: JSON.stringify(json) };
    } catch {
      log.warn("PIPELINE", "Failed to parse stage response as JSON");
      return { text: "" };
    }
  };
}

// ---------------------------------------------------------------------------
// Token estimation
// ---------------------------------------------------------------------------

/**
 * Rough token estimate from message content (4 chars ≈ 1 token).
 */
function estimateTokens(messages: Array<{ role: string; content: unknown }>): number {
  let total = 0;
  for (const msg of messages) {
    if (typeof msg.content === "string") {
      total += Math.ceil(msg.content.length / 4);
    } else if (Array.isArray(msg.content)) {

View on GitHub (pinned to a179ffed5b)

When it happens

Trigger: Thrown at open-sse/services/autoCombo/pipelineRouter.ts:174 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


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