Raise model error categories like `ModelRateLimitError` from embedding models
Follow-up to #9354 (and #9339): embedding models still raised a plain ModelHTTPError or ModelAPIError for rate limits, unavailable providers, server errors and dropped connections, so code catching ModelRateLimitError around an Embedder never matched. They now raise the same error categories as chat models, using the classifiers #9354 added rather than new ones.
[!WARNING]
Compatibility impact: Existing code that matches embedding errors by exact type or class name, or that reads the message of a VoyageAI rate limit or 5xx error, may behave differently:
- Errors from embedding models that were a plain
ModelHTTPError or ModelAPIError may now be an instance of a subclass, so exact-type checks like type(e) is ModelHTTPError no longer match them, and the class name in tracebacks, repr() and OTel exception.type is the category's (e.g. ModelRateLimitError).
- VoyageAI errors that came with a 429 or 5xx status are now a
ModelHTTPError (with the category) instead of a plain ModelAPIError, so except ModelHTTPError now catches them, and their str(e)/message takes ModelHTTPError's status_code: ..., model_name: ..., body: ... form; the provider's text is in body.
Why this can ship in a minor release: Every error is still a ModelHTTPError or ModelAPIError (now possibly a subclass), so except and isinstance checks that matched before still match, and errors that already had a status keep their status code, body and headers. This is the same impact #9354 shipped for chat models.
Migration: Match errors with except or isinstance (e.g. except ModelRateLimitError) rather than exact-type checks or class-name strings. Read a VoyageAI error's provider text from e.body rather than str(e).
Mapping per provider (each row is a test case in tests/test_embeddings_error_categories.py)
| Embedding model | Classification | Same as chat? |
|---|---|---|
OpenAIEmbeddingModel (and OpenAI-compatible providers) | _model_errors.openai_compatible_category on status, code, type and message: 429 rate limit, insufficient_quota etc. quota, 503 unavailable, 5xx server error; provider_error_code/provider_error_type set; APIConnectionError/APITimeoutError ā ModelConnectionError/ModelTimeoutError | yes, minus suggested_model_id (it suggests chat model ids) |
CohereEmbeddingModel | _model_errors.http_status_category on status and body message; httpx timeout ā ModelTimeoutError (connection errors were already mapped by #9354) | yes, minus the chat-only too many tokens overflow check |
GoogleEmbeddingModel | models.google._error_category on status (RESOURCE_EXHAUSTED, UNAVAILABLE, INTERNAL, overflow INVALID_ARGUMENT), falling back to the HTTP status; provider_error_code set | yes, minus suggested_model_id |
BedrockEmbeddingModel | models.bedrock._error_category on the error Code (ThrottlingException, ServiceQuotaExceededException, ServiceUnavailableException/ModelNotReadyException, ...), falling back to the HTTP status; provider_error_code set; botocore timeouts/connection errors ā ModelTimeoutError/ModelConnectionError with phase | yes, minus suggested_model_id and the data-retention hint |
VoyageAIEmbeddingModel | _model_errors.http_status_category on the SDK error's http_status and response body (not the SDK's canned 5xx message); Timeout/APIConnectionError ā ModelTimeoutError/ModelConnectionError | see below |
SentenceTransformerEmbeddingModel | unchanged: runs locally, no provider errors | n/a |
Not classified
- Input over the embedding model's token limit. None of the recorded overflow errors match the chat overflow signals, so they stay a plain
ModelHTTPError400: OpenAIInvalid 'input[0]': maximum input length is 8192 tokens.(nocode), Cohereinvalid request: texts[0] is too long. Max tokens per text must be at most 508 - received 3334, Bedrock Titan400 Bad Request: Too many input tokens. Max input tokens: 8192, .... Gemini on the Gemini API truncated instead of erroring even withtruncate=False. The tests pin these bodies as unclassified. An OpenAI-compatible server that words it like chat (maximum context length) is classified asModelContextWindowExceededError, as for chat. - VoyageAI errors without a category (400, 401, 422) stay a plain
ModelAPIErroras before, so only errors that gain a category change type.
Verification
tests/test_embeddings_error_categories.py: 31 cases through each SDK (mock HTTP transport for OpenAI, Cohere, Google; stubbedinvoke_model/ client for Bedrock and VoyageAI). With the adapter changes reverted, 22 of the 25 non-VoyageAI cases fail; the other 3 pin errors that stay unclassified. The VoyageAI cases run on Python < 3.14 only, wherevoyageaiinstalls.- Existing
tests/test_embeddings.pypasses unchanged, including theexcept ModelHTTPError/ModelAPIErrorassertions.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
- PR title is fit for the release changelog.
š¤ Generated with Claude Code