openai/openai-python · error · ValueError
No embedding data received
Error message
No embedding data received
What it means
parse_embedding_response decodes base64 embeddings into numpy float arrays when no explicit encoding_format was requested. If the API response contains an empty data list, there is nothing to decode and it raises ValueError('No embedding data received').
Source
Thrown at src/openai/lib/_parsing/_embeddings.py:21
import array
import base64
from typing import cast
from ..._types import Omit, NotGiven
from ..._utils import is_given
from ..._extras import numpy as np, has_numpy
from ...types.create_embedding_response import CreateEmbeddingResponse
def parse_embedding_response(
obj: CreateEmbeddingResponse, *, encoding_format: str | Omit | NotGiven
) -> CreateEmbeddingResponse:
if is_given(encoding_format):
# don't modify the response object if a user explicitly asked for a format
return obj
if not obj.data:
raise ValueError("No embedding data received")
for embedding in obj.data:
data = cast(object, embedding.embedding)
if not isinstance(data, str):
continue
if not has_numpy():
# use array for base64 optimisation
embedding.embedding = array.array("f", base64.b64decode(data)).tolist()
else:
embedding.embedding = np.frombuffer( # type: ignore[no-untyped-call]
base64.b64decode(data), dtype="float32"
).tolist()
return obj
View on GitHub (pinned to 9917c6e28e)
Solutions
- Inspect the raw response before parsing (check len(response.data))
- Retry the embeddings.create call — an empty body is usually transient or a proxy issue
- If you requested base64 explicitly, pass encoding_format='base64' so the helper returns the response untouched
Example fix
# before
parsed = parse_embedding_response(response, encoding_format=NOT_GIVEN)
# after
if not response.data:
raise ValueError("empty embedding response from API")
parsed = parse_embedding_response(response, encoding_format=NOT_GIVEN) Defensive patterns
Strategy: validation
Validate before calling
if not response.data:
raise ValueError("empty embedding response; retrying") Try / catch
try:
parsed = parse_embedding_response(response, encoding_format=NOT_GIVEN)
except ValueError as e:
if "No embedding data" in str(e):
response = client.embeddings.create(...) # retry
else:
raise Prevention
- Check response.data before parsing
- Pass encoding_format explicitly to bypass decoding
When it happens
Trigger: A CreateEmbeddingResponse arrives with data == [] (or the mock/response object has no data) and encoding_format was not given, when using the embeddings parsing helper.
Common situations: Mocking responses without data; a malformed or truncated API response; proxy/gateway stripping the body.
Related errors
- invalid datetime format
- invalid date format
- Currently only `function` tool types support auto-parsing; R
- `{tool['function']['name']}` is not strict. Only `strict` fu
- Non BaseModel types are only supported with Pydantic v2 - {r
AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28).
Data as JSON: /api/errors/21c26c3b3cfaa329.
Report an issue: GitHub.