{"record":{"id":"e30daddde703f733","repo":"chroma-core/chroma","slug":"error-calling-cloudflare-workers-ai-api","errorCode":null,"errorMessage":"Error calling Cloudflare Workers AI API","messagePattern":"Error calling Cloudflare Workers AI API","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/ai-embeddings/cloudflare-worker-ai/src/index.ts","lineNumber":92,"sourceCode":"\n  public async generate(texts: string[]): Promise<number[][]> {\n    const payload = { text: texts };\n    let cloudFlareResult: { result?: { data?: number[][] }; detail?: string };\n\n    try {\n      const response = await fetch(this.apiUrl, {\n        method: \"POST\",\n        headers: this.headers,\n        body: JSON.stringify(payload),\n      });\n\n      cloudFlareResult = await response.json();\n    } catch (e) {\n      throw new Error(`Error calling Cloudflare Workers AI API: ${e}`);\n    }\n\n    if (!cloudFlareResult.result || !cloudFlareResult.result.data) {\n      throw new Error(\n        cloudFlareResult.detail || \"Error calling Cloudflare Workers AI API\",\n      );\n    }\n\n    return cloudFlareResult.result.data;\n  }\n\n  public defaultSpace(): EmbeddingFunctionSpace {\n    return \"cosine\";\n  }\n\n  public supportedSpaces(): EmbeddingFunctionSpace[] {\n    return [\"cosine\", \"ip\", \"l2\"];\n  }\n\n  public static buildFromConfig(\n    config: CloudflareWorkerAIConfig,\n  ): CloudflareWorkerAIEmbeddingFunction {","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/ai-embeddings/cloudflare-worker-ai/src/index.ts#L74-L110","documentation":"Response-shape validation in generate(): the Cloudflare Workers AI reply lacked `result.data` (missing result object or missing embeddings inside it). Usually the API returned an error payload with a `detail` field instead of embeddings; the subsequent code prefers that detail as the message.","triggerScenarios":"Thrown at clients/new-js/packages/ai-embeddings/cloudflare-worker-ai/src/index.ts:92 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Log the full response body — the `detail` field typically explains the API-side failure","Verify the model name and that the account is authorized for Workers AI","Correct the reported issue and resend the embedding request"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","contentChangedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}