{"record":{"id":"92104e2e373e3f80","repo":"chroma-core/chroma","slug":"unknown-error-92104e","errorCode":null,"errorMessage":"Unknown error","messagePattern":"Unknown error","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/cloudflare_workers_ai_embedding_function.py","lineNumber":102,"sourceCode":"        Args:\n            input: Documents to generate embeddings for.\n\n        Returns:\n            Embeddings for the documents.\n        \"\"\"\n        if not all(isinstance(item, str) for item in input):\n            raise ValueError(\n                \"Cloudflare Workers AI only supports text documents, not images\"\n            )\n\n        payload: Dict[str, Any] = {\n            \"text\": input,\n        }\n\n        resp = self._session.post(self._api_url, json=payload).json()\n\n        if \"result\" not in resp and \"data\" not in resp[\"result\"]:\n            raise RuntimeError(resp.get(\"detail\", \"Unknown error\"))\n\n        return cast(Embeddings, resp[\"result\"][\"data\"])\n\n    @staticmethod\n    def name() -> str:\n        return \"cloudflare_workers_ai\"\n\n    def default_space(self) -> Space:\n        return \"cosine\"\n\n    def supported_spaces(self) -> List[Space]:\n        return [\"cosine\", \"l2\", \"ip\"]\n\n    @staticmethod\n    def build_from_config(config: Dict[str, Any]) -> \"EmbeddingFunction[Documents]\":\n        api_key_env_var = config.get(\"api_key_env_var\")\n        model_name = config.get(\"model_name\")\n        account_id = config.get(\"account_id\")","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/cloudflare_workers_ai_embedding_function.py#L84-L120","documentation":"__call__ posts to the API and parses the JSON body without checking the HTTP status, then expects the shape {'result': {'data': [...]}}. When the payload does not match, it raises RuntimeError with the response's 'detail' field, falling back to 'Unknown error' when the body has no detail key. Note the guard uses 'and', so this exact RuntimeError fires when 'result' exists but lacks 'data' (a body missing 'result' entirely surfaces as a KeyError instead) - in practice both indicate an error or unexpected body from a bad account_id, model_name, key, or gateway route.","triggerScenarios":"Calling ef(texts) when the POST returns an error or unexpected body: wrong account_id or non-existent @cf/... model_name in the URL, invalid/expired API key, wrong gateway_id, or rate limiting - with no 'detail' field in the JSON.","commonSituations":"Typos in account_id or model name; key rotated in the Cloudflare dashboard while the env var still holds the old value; account without Workers AI enabled; gateways/proxies returning a differently-shaped error that still parses as JSON.","solutions":["Reproduce the raw request with httpx and print status_code and text to see the real API error - the function swallows the HTTP status.","Verify account_id, gateway_id (if used), and that model_name exists for your account (https://developers.cloudflare.com/workers-ai/models/).","Confirm the API key is current: curl the same endpoint with Authorization: Bearer $CLOUDFLARE_API_KEY and expect HTTP 200.","Wrap __call__ in try/except RuntimeError and log the exception before re-raising so production failures carry context."],"exampleFix":"# before\nembs = ef(['hello'])  # RuntimeError: Unknown error\n\n# after (diagnose the underlying API response)\nimport httpx, os\nkey = os.getenv('CLOUDFLARE_API_KEY')\nr = httpx.post(api_url, json={'text': ['hello']}, headers={'Authorization': f'Bearer {key}'})\nprint(r.status_code, r.text)  # e.g. 404 -> wrong account_id/model_name","handlingStrategy":"try-catch","validationCode":"import httpx, os\n\ndef cloudflare_preflight(api_url: str) -> None:\n    key = os.getenv('CLOUDFLARE_API_KEY')\n    r = httpx.post(api_url, json={'text': ['ping']}, headers={'Authorization': f'Bearer {key}'})\n    if r.status_code != 200:\n        raise RuntimeError(f'Workers AI preflight failed: {r.status_code} {r.text}')","typeGuard":null,"tryCatchPattern":"try:\n    embs = ef(texts)\nexcept RuntimeError as e:\n    logger.error('workers-ai embed failed: %s', e)\n    raise\nexcept KeyError:\n    logger.error('workers-ai returned an error body without result/detail')\n    raise","preventionTips":["Wrap the first production embed call in logging so API error bodies are captured.","Validate account_id/model_name at deploy time with a one-item preflight request.","Watch for this error after key rotations and model deprecations."],"tags":["chroma","cloudflare","http","api-response","runtime-error"],"backgroundTag":"api-unexpected-response","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}