You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python: malformed base64 embedding payload raises a bare struct error with no context #9511
With encoding_format set to base64, OpenAIEmbeddingClient.get_embeddings decodes each payload with struct.unpack sized as len(raw) // 4. When the decoded byte length is not a multiple of 4 (a truncated or malformed response), the buffer is longer than the format expects and the call fails with a bare struct.error: unpack requires a buffer of X bytes, with no wrapping and no indication of which input's embedding broke.
Observed Behavior
A response item whose base64 payload decodes to, say, 5 bytes raises struct.error straight out of get_embeddings.
Expected Behavior
The client should reject the payload with a descriptive error naming the input index and the decoded length, so callers can tell a malformed response apart from a client bug.
Reproduction Steps
Request embeddings with options={"encoding_format": "base64"}.
Have the endpoint (or a proxy) return a payload whose decoded length is not divisible by 4.
get_embeddings raises struct.error.
Minimal Reproduction
raw=base64.b64encode(struct.pack("<1f", 0.5) +b"\\x00").decode()
# served as the embedding string for one item
Activity