{"record":{"id":"ea2b5a0d63a1a47e","repo":"chroma-core/chroma","slug":"bad-request-to-input-as-request-url-chroma","errorCode":null,"errorMessage":"Bad request to ${(input as Request).url || \"Chroma\"} with status: ${status}","messagePattern":"Bad request to (.+?) with status: (.+?)","errorType":"http","errorClass":"ChromaClientError","httpStatus":400,"severity":"error","filePath":"clients/new-js/packages/chromadb/src/chroma-fetch.ts","lineNumber":70,"sourceCode":"      throw new ChromaConnectionError(\n        \"Failed to connect to chromadb. Make sure your server is running and try again. If you are running from a browser, make sure that your chromadb instance is configured to allow requests from the current origin using the CHROMA_SERVER_CORS_ALLOW_ORIGINS environment variable.\",\n      );\n    }\n    throw new ChromaConnectionError(\"Failed to connect to Chroma\");\n  }\n\n  if (response.ok) {\n    return response;\n  }\n\n  switch (response.status) {\n    case 400:\n      let status = \"Bad Request\";\n      try {\n        const responseBody = await response.json();\n        status = responseBody.message || status;\n      } catch {}\n      throw new ChromaClientError(\n        `Bad request to ${\n          (input as Request).url || \"Chroma\"\n        } with status: ${status}`,\n      );\n    case 401:\n      throw new ChromaUnauthorizedError(`Unauthorized`);\n    case 403:\n      throw new ChromaForbiddenError(\n        `You do not have permission to access the requested resource.`,\n      );\n    case 404:\n      throw new ChromaNotFoundError(\n        `The requested resource could not be found`,\n      );\n    case 409:\n      const conflictBody = await getErrorBody(response);\n      if (\n        conflictBody.error === \"ConditionalWriteConflictError\" ||","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/chromadb/src/chroma-fetch.ts#L52-L88","documentation":"Thrown by chromaFetch (chroma-fetch.ts:70) as a ChromaClientError when the Chroma server returns HTTP 400. The library tries to parse the JSON body and surface its `message` field (defaulting to 'Bad Request'), then prefixes the target URL. A 400 means the request reached the server but was rejected as malformed or semantically invalid before processing.","triggerScenarios":"Malformed API input: invalid collection configuration, bad query parameters, invalid IDs/metadata shapes, dimension mismatches in embeddings, or an API contract mismatch where the client sends fields the server version does not understand.","commonSituations":"Client/server version skew after upgrading one side; hand-constructed request payloads; passing wrong types (e.g. string IDs where UUIDs are required); embedding dimension not matching the collection's configured space.","solutions":["Read the embedded server message in the thrown error — it names the exact validation failure.","Check client and server versions match on major/minor (chroma --version vs the npm chromadb package) and align them.","Validate payload shapes (IDs, metadata key types, embedding dimensions) against the collection's configuration.","Reproduce with curl against the raw API to see the full 400 response body."],"exampleFix":"// before\nawait collection.add({ ids: [\"1\"], embeddings: [[1.0, 2.0]], documents: [\"hi\"] }); // 400: dimension mismatch (collection expects 384)\n\n// after\nawait collection.add({ ids: [\"1\"], embeddings: [new Array(384).fill(0.1)], documents: [\"hi\"] });","handlingStrategy":"try-catch","validationCode":"function assertEmbeddingDims(embeddings: number[][], expected: number) {\n  for (const e of embeddings) {\n    if (e.length !== expected) throw new Error(`expected ${expected} dims, got ${e.length}`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await collection.add(payload);\n} catch (e) {\n  if (e instanceof ChromaClientError && e.message.startsWith(\"Bad request to\")) {\n    // server rejected the payload; parse the trailing server message for the exact field\n  }\n  throw e;\n}","preventionTips":["Keep client and server versions in lockstep (pin both in CI).","Validate payload shapes (array lengths, metadata value types, ID formats) before sending.","Log the full error message — it embeds the server's validation reason."],"tags":["http-400","validation","server-response","version-skew"],"backgroundTag":"bad-request-validation","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}