chatboxai/chatbox · error · Error

knowledge_base_parsed_content_too_large

knowledge_base_parsed_content_too_large

Error message

knowledge_base_parsed_content_too_large

What it means

Thrown by CustomGemini.listModels() when GET `${apiHost}/models?key=...` returns a body without a top-level `models` array. Note: this method is wrapped in try/catch that logs and returns `[]`, so the ApiError itself only escapes if a caller rethrows or if the catch is bypassed — but it is the documented failure signal. The Gemini ListModels API normally returns `{ models: [{ name, displayName, supportedGenerationMethods, ... }] }`, so a missing `models` field means the request did not reach a real Gemini-style models endpoint.

Source

Thrown at src/main/knowledge-base/file-loaders.ts:73

// Parse file to MDocument using the parser router
async function parseFileToDocumentWithRouter(
  filePath: string,
  fileMeta: ParserFileMeta,
  kbId: number,
  parserConfig: DocumentParserConfig
): Promise<{ document: MDocument; parserUsed: string }> {
  log.info(`[FILE] Parsing ${fileMeta.filename} with ${parserConfig.type} parser`)

  const result = await parseFileWithRouter(filePath, fileMeta, parserConfig, kbId)

  log.info(`[FILE] Parse completed for ${fileMeta.filename}, parser used: ${result.parserUsed}`)

  const parsedContentByteLength = Buffer.byteLength(result.content, 'utf8')
  if (parsedContentByteLength > KNOWLEDGE_BASE_MAX_PARSED_CONTENT_SIZE) {
    log.info(
      `[FILE] Parsed content too large: filename=${fileMeta.filename}, bytes=${parsedContentByteLength}, limit=${KNOWLEDGE_BASE_MAX_PARSED_CONTENT_SIZE}`
    )
    throw new Error(KNOWLEDGE_BASE_PARSED_CONTENT_TOO_LARGE_ERROR)
  }

  // Convert content to MDocument based on content type
  const document = MDocument.fromText(result.content)
  return { document, parserUsed: result.parserUsed }
}

// Use mastra to parse, chunk, embed, and store files
export async function processFileWithMastra(
  filePath: string,
  fileMeta: { fileId: number; filename: string; mimeType: string },
  kbId: number,
  parserConfig: DocumentParserConfig
) {
  const startTime = Date.now()
  log.debug(
    `[FILE] Starting file processing: ${fileMeta.filename} (id=${fileMeta.fileId}, parser=${parserConfig.type})`
  )

View on GitHub (pinned to 81571269ad)

Solutions

  1. Inspect the JSON.stringify'd payload — `{ error: {...} }` from Google means auth/quota/permission issue; `{ data: [...] }` means the host is OpenAI-style and you should switch provider type.
  2. Confirm `apiHost` is the base origin (e.g. `https://generativelanguage.googleapis.com`) without a `/v1beta` suffix; normalizeGeminiHost appends the version.
  3. Verify the API key is enabled for the Generative Language API in the Google Cloud project and has no referring-URL restriction that blocks the request.
  4. If using a relay that only exposes OpenAI `/v1/models`, switch to a Custom OpenAI provider instead of Custom Gemini.

Example fix

// before: relay returns { data: [...] }, throws '{"data":[...]}'
// after: detect schema and adapt, or fall back to manual model list
if (!json.models && json.data) {
  return json.data.map((m) => ({ modelId: m.id, type: 'chat' as const }))
}
if (!json.models) throw new ApiError(JSON.stringify(json))
Defensive patterns

Strategy: try-catch

Validate before calling

async function probeCustomGeminiModels(host: string, key: string): Promise<boolean> {
  const res = await fetch(`${host}/models?key=${encodeURIComponent(key)}`)
  const json = await res.json().catch(() => ({}))
  return Array.isArray((json as any)?.models)
}

Type guard

function isGeminiModelsResponse(json: unknown): json is { models: { name: string; supportedGenerationMethods: string[] }[] } {
  return typeof json === 'object' && json !== null && Array.isArray((json as any).models)
}

Try / catch

// listModels already wraps in try/catch returning []; ensure callers handle the empty array
const models = await customGemini.listModels()
if (models.length === 0) showFallbackModelList()

Prevention

When it happens

Trigger: Invalid `apiKey` (Google returns `{ error: { code: 400, message: 'API key not valid...' } }`); `apiHost` points to an OpenAI-compatible relay whose `/models` returns `{ data: [...] }`; the key query param is URL-mangled by a proxy; the custom host does not implement the `/models` route at all (returns `{}` or HTML); quota/billing disabled the key and Google returns an error envelope.

Common situations: Custom Gemini provider configured with the OpenAI-style host by mistake; key generated for a different Google project / restricted API; corporate proxy strips the `?key=` query parameter; the host includes `/v1beta` already so the URL becomes `.../v1beta/v1beta/models`; region where Generative Language API is unavailable returns a non-models JSON.

Related errors


AI-assisted analysis of chatboxai/chatbox@81571269ad (2026-08-12). Data as JSON: /api/errors/1f68448275d9e320. Report an issue: GitHub.