CherryHQ/cherry-studio · error · Error

Rerank response must contain a results array

Error message

Rerank response must contain a results array

What it means

Thrown after the submit/poll cycle completed successfully but the resulting URL list is empty (covers both submit.imageUrls === [] and poll() === []). Unlike the malformed-submit case (error 400), the provider invocation genuinely finished — it just produced no images. The handler records the invocation with imageCount=0 BEFORE throwing, because the call was observable/billable, then fails to avoid reporting a silent zero-image 'success'. Typical cause is vendor-side content moderation or a degraded response that still charged.

Source

Thrown at packages/ai-sdk-provider/src/openai-compatible-reranking-model.ts:88

        }
      },
      abortSignal,
      fetch: this.config.fetch
    })

    return {
      ranking: value,
      response: {
        body: rawValue
      }
    }
  }
}

function parseRerankResponse(body: unknown, documentCount: number): RerankRanking {
  const results = (body as OpenAICompatibleRerankResponse).results
  if (!Array.isArray(results)) {
    throw new Error('Rerank response must contain a results array')
  }

  return results.map((result) => {
    if (typeof result !== 'object' || result === null) {
      throw new Error('Rerank response results must be objects')
    }

    if (typeof result.index !== 'number' || typeof result.relevance_score !== 'number') {
      throw new Error('Rerank response results must contain numeric index and relevance_score')
    }

    if (!Number.isInteger(result.index) || result.index < 0 || result.index >= documentCount) {
      throw new Error('Rerank response results must reference a valid document index')
    }

    return { index: result.index, relevanceScore: result.relevance_score }
  })
}

View on GitHub (pinned to 726446b54c)

Solutions

  1. Revise the prompt to remove content likely to trip the vendor's moderation policy and retry.
  2. Check the vendor dashboard/console for moderation actions or policy flags on the account/model.
  3. Verify the requested image count (n) is >= 1 end-to-end through providerOptions.
  4. Try a different model id from the same provider to isolate whether the block is model-specific.
  5. Inspect the aiUsageRecord for the requestId (`custom-image:<jobId>`) — imageCount=0 with a recorded invocation confirms a vendor-side empty response.

Example fix

// No code fix exists at the caller — the provider genuinely returned nothing.
// Mitigation is operational: surface a user-facing message and offer retry with a sanitized prompt.
// before
try { await generateImageViaJob(payload) }
catch (e) { logger.error(e.message) }
// after: distinguish the moderation case for the user
try { await generateImageViaJob(payload) }
catch (e) {
  if (/completed but returned no image URLs/.test(e.message)) {
    notifyUser('The model produced no image (possibly content moderation). Try a different prompt.')
  } else { throw e }
}
Defensive patterns

Strategy: try-catch

Validate before calling

// The empty-list case comes from the vendor post-success; you cannot fully
// prevent it client-side, but you can pre-validate inputs that commonly trip moderation.
const MODERATION_RISK = /(violence|explicit|weapon)/i
if (input.prompt && MODERATION_RISK.test(input.prompt)) {
  warnUser('Prompt may be filtered by the model content policy.')
}

Try / catch

try {
  await generateImageViaJob(payload)
} catch (e) {
  if (e instanceof Error && /completed but returned no image URLs/.test(e.message)) {
    notifyUser('The model produced no image — likely content moderation. Revise the prompt and retry.')
  } else throw e
}

Prevention

When it happens

Trigger: The prompt or input image triggers the vendor's safety/content-moderation filter, which returns a 200 with an empty result array instead of an error; a requested image count of n=0 propagated through; a degraded vendor path that accepts the request but yields no output URLs; an async poll that resolved to an empty array while reporting success.

Common situations: Prompt contains disallowed content or copyrighted names; input image is flagged by safety models; vendor temporarily degrades and returns zero results; the n parameter was overridden to 0 somewhere in option mapping; region/account under a content-policy shadow-ban.

Related errors


AI-assisted analysis of CherryHQ/cherry-studio@726446b54c (2026-08-12). Data as JSON: /api/errors/cc51f0cd639c7306. Report an issue: GitHub.