Skip to content

fix(sagemaker): use native Cohere format for AWS Marketplace Cohere embedding endpoints - #28633

Closed
oss-agent-shin wants to merge 6 commits into
BerriAI:litellm_internal_stagingfrom
oss-agent-shin:fix/sagemaker-cohere-embedding-format
Closed

oss-agent-shin wants to merge 6 commits into
BerriAI:litellm_internal_stagingfrom
oss-agent-shin:fix/sagemaker-cohere-embedding-format

Conversation

@oss-agent-shin

Copy link
Copy Markdown
Contributor

Summary

  • Root cause: LiteLLM sent SageMaker Cohere embeddings in HuggingFace format {"inputs": ["hello"]}, but AWS Marketplace Cohere containers (cohere.embed-multilingual-v3, etc.) expect the native Cohere API format {"texts": ["hello"], "input_type": "search_document"}
  • Fix: Added SagemakerCohereEmbeddingConfig class + updated the get_model_config() factory to route any model containing "cohere" to it
  • Keeps HuggingFace behavior unchanged for all non-Cohere models

Changes

  • litellm/llms/sagemaker/embedding/transformation.py:
    • New SagemakerCohereEmbeddingConfig that sends {"texts": [...], "input_type": "search_document"} and parses {"embeddings": [[...]]} responses
    • SagemakerEmbeddingConfig.get_model_config() now checks for "cohere" in model name before falling back to HuggingFace default
  • tests/test_litellm/llms/sagemaker/test_sagemaker_embedding_cohere.py: 17 new unit tests

Test plan

  • pytest tests/test_litellm/llms/sagemaker/test_sagemaker_embedding_cohere.py — 17/17 passed
  • pytest tests/test_litellm/llms/sagemaker/test_sagemaker_embedding_voyage.py — 22/22 passed (no regression)

Fixes LIT-3289

🤖 Generated with Claude Code

shin-berri and others added 5 commits May 13, 2026 22:37
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>
@CLAassistant

CLAassistant commented May 22, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 4 committers have signed the CLA.

✅ yuneng-berri
❌ Shin
❌ oss-agent-shin
❌ shin-berri


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

codecov Bot commented May 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.23810% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/llms/sagemaker/embedding/transformation.py 95.23% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@greptile-apps

greptile-apps Bot commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a request-format mismatch for AWS Marketplace Cohere embedding containers on SageMaker by adding SagemakerCohereEmbeddingConfig, which sends the native Cohere {"texts": [...], "input_type": "..."} format instead of the HuggingFace {"inputs": [...]} format that was previously used. It also bundles two new azure/gpt-5.5 versioned model entries to fix cost-display regressions from a date mismatch (LIT-3215).

  • SagemakerCohereEmbeddingConfig handles both the flat-list (v1) and dict-keyed (v2 embedding_types) response shapes, mirroring the hosted CohereEmbeddingConfig._transform_response pattern; the factory get_model_config() routes any model containing "cohere" to it.
  • 17 new mock-only unit tests cover factory routing, request formatting, flat and dict response parsing (including the 2-type × 2-text case that triggered the previous P1 finding), param mapping, and error paths.
  • model_prices_and_context_window.json gains azure/gpt-5.5-2026-04-24 and azure/gpt-5.5-pro-2026-04-24, each a copy of the corresponding -04-23 entry.

Confidence Score: 5/5

Safe 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.

Important Files Changed

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

Comment on lines +120 to +127
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}
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment on lines 175 to 179
if "voyage" in model.lower():
return VoyageEmbeddingConfig()
elif "cohere" in model.lower():
return SagemakerCohereEmbeddingConfig()
else:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +5177 to 5220
"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": {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ghost

ghost commented May 22, 2026

Copy link
Copy Markdown

🤖 litellm-agent: This PR is currently BLOCKED from merge.

Score: 2/5 ❌

Why blocked:

  • 1 PR-related CI failure (Greptile gate: score 3/5 below required 4/5 — request a Greptile review (@greptileai) and resolve its comments before maintainer review.) (pr_related_failures, -2 pts)
  • Greptile 3/5 (greptile_low, -1 pts)

Details: Score docked for: 1 PR-related CI failure (Greptile gate: score 3/5 below required 4/5 — request a Greptile review (@greptileai) and resolve its comments before maintainer review.); Greptile 3/5.

Fix the issues above and push an update — the bot will re-review automatically.

Note: This bot is still in beta and might not always work as expected. Please share any feedback via Slack.

@oss-agent-shin

Copy link
Copy Markdown
Contributor Author

@greptileai Addressed all review comments in commit c392411:

  • P1 (dict embeddings): Fixed — added isinstance(embeddings, dict) detection that flattens type→list pairs, matching hosted CohereEmbeddingConfig._transform_response. Test added.
  • P2 (model detection): Explained in reply — SageMaker custom endpoints cannot use get_model_info(); heuristic is consistent with existing voyage check.
  • P2 (Azure entries): Explained in reply — intentional, fixes LIT-3215 (gpt-5.5 date mismatch).

Please re-review.

@oss-agent-shin

Copy link
Copy Markdown
Contributor Author

Closing this PR — the core SageMaker Cohere embedding format fix was already merged via #28613. The dict/list response handling I added in the latest commit is already handled by (which uses detection). The Azure gpt-5.5 entries are tracked separately in #28631.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants