{"record":{"id":"70c0ca0296429917","repo":"diegosouzapw/OmniRoute","slug":"invalid-json-body","errorCode":null,"errorMessage":"Invalid JSON body","messagePattern":"Invalid JSON body","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/app/api/v1/embeddings/route.ts","lineNumber":47,"sourceCode":"    (model) => model.type === \"embedding\"\n  );\n}\n\ntype ValidatedEmbeddingBody = Record<string, unknown> & { model: string };\n\nexport async function handleValidatedEmbeddingRequestBody(\n  body: ValidatedEmbeddingBody,\n  options: EmbeddingHandlerOptions = {}\n) {\n  return createEmbeddingResponse(body, options);\n}\n\nasync function postHandler(request, context) {\n  let rawBody;\n  try {\n    rawBody = await request.json();\n  } catch {\n    log.warn(\"EMBED\", \"Invalid JSON body\");\n    return errorResponse(HTTP_STATUS.BAD_REQUEST, \"Invalid JSON body\");\n  }\n\n  const validation = validateBody(v1EmbeddingsSchema, rawBody);\n  if (isValidationFailure(validation)) {\n    return errorResponse(HTTP_STATUS.BAD_REQUEST, validation.error.message);\n  }\n  const body = validation.data;\n\n  // Auth check — when REQUIRE_API_KEY=false, ignore presented invalid keys\n  // so anonymous access works the same as all other client APIs (#7785).\n  const apiKeyRaw = extractApiKey(request);\n  if (isRequireApiKeyEnabled() && !apiKeyRaw) {\n    return errorResponse(HTTP_STATUS.UNAUTHORIZED, \"Authentication required\");\n  }\n  if (isRequireApiKeyEnabled() && apiKeyRaw && !(await isValidApiKey(apiKeyRaw))) {\n    return errorResponse(HTTP_STATUS.UNAUTHORIZED, \"Invalid API key\");\n  }","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/app/api/v1/embeddings/route.ts#L29-L65","documentation":"Error \"Invalid JSON body\" thrown in diegosouzapw/OmniRoute.","triggerScenarios":"Thrown at src/app/api/v1/embeddings/route.ts:47 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","schemaVersion":2},"datasetVersion":"2026-08-25T21:54:21.419Z"}