Repository navigation
fix(sagemaker): use native Cohere format for AWS Marketplace Cohere embedding endpoints - #28633
oss-agent-shin wants to merge 6 commits into
Conversation
[Infra] Promote internal staging to main
[Infra] Promote internal staging to main
chore(ci): promote internal staging to main
…o-2026-04-24 entries Azure Foundry exposes gpt-5.5 as version 2026-04-24, not 2026-04-23. Without this entry, LiteLLM shows $0.00/1M tokens for the model. Adds azure/gpt-5.5-2026-04-24 and azure/gpt-5.5-pro-2026-04-24 with the same pricing/capability data as their 2026-04-23 counterparts. Keeps the old entries for backward compatibility. Fixes LIT-3215 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…here embeddings
AWS Marketplace Cohere embedding containers expect the native Cohere API
format {"texts": [...], "input_type": "..."} but LiteLLM was sending the
HuggingFace format {"inputs": [...]}, causing 4xx errors.
Changes:
- Add SagemakerCohereEmbeddingConfig that sends {"texts", "input_type"}
and parses the Cohere {"embeddings": [[...]]} response format
- Update SagemakerEmbeddingConfig.get_model_config() factory to route
models containing "cohere" to the new config
- Add 17 unit tests covering request/response transformation and factory routing
Affects: cohere.embed-multilingual-v3 and all Cohere models on SageMaker
AWS Marketplace.
Fixes LIT-3289
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Shin seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Greptile SummaryThis PR fixes a request-format mismatch for AWS Marketplace Cohere embedding containers on SageMaker by adding
Confidence Score: 5/5Safe to merge — the new Cohere path is additive and isolated behind the factory, the HuggingFace path is untouched, and all previously raised issues have been addressed. The core fix is a straightforward additive class behind a factory method. The dict-keyed response path (previously flagged) is now correctly handled with an isinstance(embeddings, dict) branch. The Azure JSON entries are data-only additions with no logic changes. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/llms/sagemaker/embedding/transformation.py | Adds SagemakerCohereEmbeddingConfig with correct texts/input_type request format, dict-vs-list response handling, and factory routing; all previously raised issues are addressed |
| model_prices_and_context_window.json | Adds azure/gpt-5.5-2026-04-24 and azure/gpt-5.5-pro-2026-04-24 entries, each identical in capabilities to their -04-23 counterparts; intentional fix for LIT-3215 date mismatch |
| tests/test_litellm/llms/sagemaker/test_sagemaker_embedding_cohere.py | 17 new unit tests covering factory routing, request format, flat-list and dict-keyed response parsing (including the v2 multi-type path), param mapping, and error cases; all mocked, no real network calls |
Reviews (2): Last reviewed commit: "fix(sagemaker/cohere): handle dict-shape..." | Re-trigger Greptile
| embeddings = response_data["embeddings"] | ||
| # The Cohere SageMaker container returns embeddings as a flat list of | ||
| # embedding vectors: [[float, ...], [float, ...], ...] | ||
| output_data = [] | ||
| for idx, embedding in enumerate(embeddings): | ||
| output_data.append( | ||
| {"object": "embedding", "index": idx, "embedding": embedding} | ||
| ) |
There was a problem hiding this comment.
Incorrect iteration when
embedding_types is set
When a user passes encoding_format (mapped to embedding_types in map_openai_params), that param is forwarded to the Cohere container. Cohere v2 containers return embeddings keyed by type — e.g. {"embeddings": {"float": [[...]], "int8": [[...]]}} — rather than a flat list. In that case, enumerate(embeddings) yields (0, "float"), (1, "int8"), etc., so each entry in model_response.data gets the string "float" or "int8" as its embedding value instead of a real vector.
Even if today's containers always return a flat list, the map_openai_params method advertises encoding_format and dimensions as supported params, so callers will pass them and hit this path. Consider either (a) detecting the dict-vs-list response shape and flattening accordingly (as the hosted CohereEmbeddingConfig._transform_response does), or (b) removing encoding_format from get_supported_openai_params until the response parsing supports it.
There was a problem hiding this comment.
Fixed in latest commit (c392411). Added check that flattens all type→list pairs — same pattern as the hosted CohereEmbeddingConfig._transform_response. Added test_transform_response_dict_embeddings_cohere_v2 to cover this path (2 types × 2 texts = 4 expected entries, all validated as numeric vectors).
| if "voyage" in model.lower(): | ||
| return VoyageEmbeddingConfig() | ||
| elif "cohere" in model.lower(): | ||
| return SagemakerCohereEmbeddingConfig() | ||
| else: |
There was a problem hiding this comment.
Hardcoded model-detection string in codebase
The "cohere" in model.lower() check is a hardcoded model-specific flag. Per the team's rule, model-specific routing should be driven by data in model_prices_and_context_window.json (read via get_model_info) rather than inline string checks, so users don't need a LiteLLM upgrade when a new Cohere variant is deployed. The existing "voyage" in model.lower() check in the same method has the same issue, but it's pre-existing; this new check introduces it again. Consider adding a provider-format discriminator field to the relevant JSON entries instead.
Rule Used: What: Do not hardcode model-specific flags in the ... (source)
There was a problem hiding this comment.
Acknowledged. SageMaker endpoints are user-deployed custom endpoints (not entries in model_prices_and_context_window.json), so get_model_info() cannot be used to discriminate them. The cohere-in-name heuristic is intentional here — it mirrors the existing voyage check in the same factory method. I've added a comment to the code noting this limitation and that the same heuristic applies to voyage.
| "azure/gpt-5.5-2026-04-24": { | ||
| "cache_read_input_token_cost": 5e-07, | ||
| "cache_read_input_token_cost_above_272k_tokens": 1e-06, | ||
| "cache_read_input_token_cost_priority": 1e-06, | ||
| "cache_read_input_token_cost_above_272k_tokens_priority": 2e-06, | ||
| "input_cost_per_token": 5e-06, | ||
| "input_cost_per_token_above_272k_tokens": 1e-05, | ||
| "input_cost_per_token_priority": 1e-05, | ||
| "input_cost_per_token_above_272k_tokens_priority": 2e-05, | ||
| "litellm_provider": "azure", | ||
| "max_input_tokens": 1050000, | ||
| "max_output_tokens": 128000, | ||
| "max_tokens": 128000, | ||
| "mode": "chat", | ||
| "output_cost_per_token": 3e-05, | ||
| "output_cost_per_token_above_272k_tokens": 4.5e-05, | ||
| "output_cost_per_token_priority": 6e-05, | ||
| "output_cost_per_token_above_272k_tokens_priority": 9e-05, | ||
| "supported_endpoints": [ | ||
| "/v1/chat/completions", | ||
| "/v1/batch", | ||
| "/v1/responses" | ||
| ], | ||
| "supported_modalities": [ | ||
| "text", | ||
| "image" | ||
| ], | ||
| "supported_output_modalities": [ | ||
| "text" | ||
| ], | ||
| "supports_function_calling": true, | ||
| "supports_native_streaming": true, | ||
| "supports_parallel_function_calling": true, | ||
| "supports_pdf_input": true, | ||
| "supports_prompt_caching": true, | ||
| "supports_reasoning": true, | ||
| "supports_response_schema": true, | ||
| "supports_system_messages": true, | ||
| "supports_tool_choice": true, | ||
| "supports_service_tier": true, | ||
| "supports_vision": true, | ||
| "supports_web_search": true | ||
| }, | ||
| "azure/gpt-5.5-pro": { |
There was a problem hiding this comment.
Unrelated model entries bundled in this PR
The additions of azure/gpt-5.5-2026-04-24 and azure/gpt-5.5-pro-2026-04-24 appear unrelated to the SageMaker Cohere embedding fix described in the PR. Was this intentional, or were these bundled by accident? Were these Azure model entries meant to be included in this PR, or should they be split into a separate PR?
There was a problem hiding this comment.
These entries address LIT-3215 (azure/gpt-5.5 version date mismatch causing $0.00 cost display). They were intentionally bundled since they are a small JSON-only change. I can split them into a separate PR if preferred.
|
🤖 litellm-agent: This PR is currently BLOCKED from merge. Score: 2/5 ❌ Why blocked:
Details: Score docked for: 1 PR-related CI failure (Greptile gate: score 3/5 below required 4/5 — request a Greptile review ( Fix the issues above and push an update — the bot will re-review automatically.
|
…here v2 containers
|
@greptileai Addressed all review comments in commit c392411:
Please re-review. |
Summary
{"inputs": ["hello"]}, but AWS Marketplace Cohere containers (cohere.embed-multilingual-v3, etc.) expect the native Cohere API format{"texts": ["hello"], "input_type": "search_document"}SagemakerCohereEmbeddingConfigclass + updated theget_model_config()factory to route any model containing"cohere"to itChanges
litellm/llms/sagemaker/embedding/transformation.py:SagemakerCohereEmbeddingConfigthat sends{"texts": [...], "input_type": "search_document"}and parses{"embeddings": [[...]]}responsesSagemakerEmbeddingConfig.get_model_config()now checks for"cohere"in model name before falling back to HuggingFace defaulttests/test_litellm/llms/sagemaker/test_sagemaker_embedding_cohere.py: 17 new unit testsTest plan
pytest tests/test_litellm/llms/sagemaker/test_sagemaker_embedding_cohere.py— 17/17 passedpytest tests/test_litellm/llms/sagemaker/test_sagemaker_embedding_voyage.py— 22/22 passed (no regression)Fixes LIT-3289
🤖 Generated with Claude Code