BerriAI/litellm · error · PerplexityEmbeddingError
raw_response.text
Error message
raw_response.text
What it means
LiteLLM's Perplexity embedding handler calls raw_response.json(); when the body is not JSON it raises PerplexityEmbeddingError with the raw body text as the message and the real HTTP status code. Note Perplexity's API is primarily search/chat, so embedding models are limited and invalid model names commonly produce non-JSON errors.
Source
Thrown at litellm/llms/perplexity/embedding/transformation.py:151
int8_values: Final = struct.unpack(f"{count}b", raw_bytes)
return [float(v) / 127.0 for v in int8_values]
return embedding_value
def transform_embedding_response(
self,
model: str,
raw_response: httpx.Response,
model_response: EmbeddingResponse,
logging_obj: LiteLLMLoggingObj,
api_key: str | None = None,
request_data: dict = {},
optional_params: dict = {},
litellm_params: dict = {},
) -> EmbeddingResponse:
try:
raw_response_json: Final = raw_response.json()
except Exception:
raise PerplexityEmbeddingError(message=raw_response.text, status_code=raw_response.status_code)
model_response.model = raw_response_json.get("model", model)
model_response.object = raw_response_json.get("object", "list")
raw_data: Final = raw_response_json.get("data", [])
decoded_data: Final[list[dict[str, Any]]] = []
for item in raw_data:
decoded_item = dict(item)
decoded_item["embedding"] = self._decode_base64_embedding(item.get("embedding"))
decoded_data.append(decoded_item)
model_response.data = decoded_data
usage_data: Final = raw_response_json.get("usage", {})
usage: Final = Usage(
prompt_tokens=usage_data.get("prompt_tokens", 0) or usage_data.get("total_tokens", 0),
total_tokens=usage_data.get("total_tokens", 0),
)
model_response.usage = usageView on GitHub (pinned to 77b7c6c40c)
Solutions
- Read the exception message - it is the raw body naming the real problem
- Confirm the embedding model actually exists on Perplexity's API
- Verify/rotate PERPLEXITYAI_API_KEY
- Route embeddings to a provider that supports them (e.g., OpenAI) if Perplexity lacks the model
Defensive patterns
Strategy: try-catch
Try / catch
Catch PerplexityEmbeddingError around litellm.embedding(); log the message (raw body) to identify auth vs. model-availability issues, and fall back to an OpenAI-compatible embedding provider when Perplexity rejects the model.
Prevention
- Verify the embedding model exists on Perplexity before integrating
- Keep a secondary embedding provider configured for fallback
- Rotate keys proactively so expired credentials surface in staging, not production
When it happens
Trigger: Calling litellm.embedding(model='perplexity/...') with an unavailable embedding model, an invalid/expired API key, or an api_base pointing at something that returns HTML or plain text.
Common situations: Assuming Perplexity serves OpenAI-compatible embeddings it does not offer; expired PERPLEXITYAI_API_KEY; gateway/CDN error pages during incidents.
Related errors
- raw_response.text
- Error parsing OpenRouter response: {e}
- Error parsing OpenRouter response: {e}
- raw_response.text
- judge response is not a JSON object
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/57782a87c93dc4ca.
Report an issue: GitHub.