{"record":{"id":"407d2b57a3ff0c7e","repo":"BerriAI/litellm","slug":"embeddings-error","errorCode":null,"errorMessage":"{embeddings[error]}","messagePattern":"\\{embeddings\\[error\\]\\}","errorType":"http","errorClass":"HuggingFaceError","httpStatus":500,"severity":"error","filePath":"litellm/llms/huggingface/embedding/handler.py","lineNumber":278,"sourceCode":"        if client is None:\n            client = get_async_httpx_client(\n                llm_provider=litellm.LlmProviders.HUGGINGFACE,\n            )\n\n        response: Final = await client.post(api_base, headers=headers, data=json.dumps(data))\n\n        ## LOGGING\n        logging_obj.post_call(\n            input=input,\n            api_key=api_key,\n            additional_args={\"complete_input_dict\": data},\n            original_response=response,\n        )\n\n        embeddings: Final = response.json()\n\n        if \"error\" in embeddings:\n            raise HuggingFaceError(status_code=500, message=embeddings[\"error\"])\n\n        ## PROCESS RESPONSE ##\n        return self._process_embedding_response(\n            embeddings=embeddings,\n            model_response=model_response,\n            model=model,\n            input=input,\n            encoding=encoding,\n        )\n\n    def embedding(\n        self,\n        model: str,\n        input: list,\n        model_response: EmbeddingResponse,\n        optional_params: dict,\n        litellm_params: dict,\n        logging_obj: LiteLLMLoggingObj,","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/huggingface/embedding/handler.py#L260-L296","documentation":"Raised in the sync embedding path after the HTTP call succeeds at the transport level but the HuggingFace response body is a JSON object containing an 'error' key. Litellm surfaces the upstream error text verbatim with status 500 (regardless of the upstream code).","triggerScenarios":"HF Inference API returns {\"error\": ...} for the embedding request — e.g. model is gated/private, invalid API token, model loading or unavailable on the inference endpoint, or input too long for the model context.","commonSituations":"Expired/missing HF_TOKEN, using a model id that was renamed or deprecated on the Hub, cold-start/loading errors on serverless inference, or a free-tier rate limit returning an error payload.","solutions":["Read the surfaced message — it is HF's own error text and names the real cause (auth, loading, limits).","Verify the token: set HF_TOKEN / pass api_key with access to the model (check gated-model acceptance).","Confirm the model id exists and serves the embedding task on the Hub; try a known-good model to isolate.","Retry after a short backoff for transient 'currently loading' responses from serverless inference."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"def huggingface_ready(model: str, api_key: str) -> bool:\n    import httpx\n    r = httpx.get(f'https://huggingface.co/api/models/{model}', headers={'Authorization': f'Bearer {api_key}'})\n    return r.status_code == 200","typeGuard":null,"tryCatchPattern":"from tenacity import retry, wait_exponential, retry_if_exception\n\n@retry(wait=wait_exponential(multiplier=1, max=30), retries=3,\n       retry=retry_if_exception(lambda e: 'loading' in str(e).lower()))\ndef embed(texts):\n    return litellm.embedding(model=MODEL, input=texts)","preventionTips":["Preflight-check model existence + token before batch jobs","Treat 'loading' errors as retryable, auth errors as fatal"],"tags":["huggingface","embeddings","upstream-error","api","auth"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}