Skip to content

fix(sagemaker_chat): send the inference component header and honor hf_model_name - #37766

Merged
mateo-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_sagemaker_chat_inference_component_header
Aug 21, 2026
Merged

mateo-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_sagemaker_chat_inference_component_header

Conversation

@mateo-berri

@mateo-berri mateo-berri commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • sagemaker_chat never sends the inference component header
  • Endpoints backed by inference components answer 400 and fail
  • Request body names the endpoint, not the served model
  • Containers that validate the body's model answer 404

How it solves it:

  • Build the header from model_id, before the request is signed
  • Mirrors what the legacy sagemaker provider already does
  • Use hf_model_name as the body's model when set
  • Endpoints setting neither keep the exact request they send today

User Flow

Before: an operator whose model is deployed as a SageMaker inference component cannot get a single completion through without hand-editing the request

  1. They add model: sagemaker_chat/<endpoint-name> to the proxy config with model_id: <inference-component-name> and hf_model_name: <served-model-name>, then start the proxy
  2. They open https://litellm-domain/ui/?page=llm-playground, pick that model, and send "hi", which posts to https://litellm-domain/v1/chat/completions
  3. They get back a 400 reading SagemakerException - {"ErrorCode":"INFERENCE_COMPONENT_NAME_MISSING","Message":"Inference Component Name header is required for endpoints to which you plan to deploy inference components. Please include Inference Component Name header or consider using SageMaker models."}, and nothing ever reaches their container
  4. They add extra_headers: {"X-Amzn-SageMaker-Inference-Component": "<inference-component-name>"} to that model and restart, which finally gets the request past AWS
  5. Their container now answers 404 The model '<endpoint-name>' does not exist., because the request asked for the endpoint by name instead of the model the container actually serves
  6. They only get an answer by overriding the served model name on every single request

After: the same config works on the first try, with no extra_headers and nothing overridden per request

  1. They add model: sagemaker_chat/<endpoint-name> to the proxy config with model_id: <inference-component-name> and hf_model_name: <served-model-name>, then start the proxy
  2. They open https://litellm-domain/ui/?page=llm-playground, pick that model, and send "hi", which posts to https://litellm-domain/v1/chat/completions
  3. They get back a 200 carrying a real assistant message generated by the deployed model
  4. They send the same request with curl against https://litellm-domain/v1/chat/completions and see the same 200
  5. An operator on a plain endpoint that sets neither model_id nor hf_model_name sends the same request and gets the same 200 they got before this change

Relevant issues

Fixes #9909

Linear ticket

Resolves LIT-2853

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

QA ran against a live SageMaker endpoint backed by a real inference component in us-east-1, serving Qwen/Qwen2.5-0.5B-Instruct on vLLM 0.27.1. Two matched worktrees, each with its own venv, its own .env and its own random port, differing only in the commit the proxy booted from: before a66a10b1b5 (this PR's merge base), after 2ea633d223 (this PR's head). Real AWS, real GPU, no mocks.

Config under test, the same file on both legs:

model_list:
  - model_name: sagemaker-vllm
    litellm_params:
      model: sagemaker_chat/<endpoint-name>
      model_id: <inference-component-name>
      hf_model_name: Qwen/Qwen2.5-0.5B-Instruct
      aws_region_name: us-east-1
      max_tokens: 16

Before (a66a10b1b5): HTTP 400, the request never reaches the container

curl -sS -w '\nHTTP_STATUS=%{http_code}\n' http://127.0.0.1:$PORT/v1/chat/completions \
  -H 'Content-Type: application/json' -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
  -d '{"model":"sagemaker-vllm","messages":[{"role":"user","content":"Say hello in three words."}]}'
{"error":{"message":"litellm.BadRequestError: SagemakerException - {\"ErrorCode\":\"INFERENCE_COMPONENT_NAME_MISSING\",\"Message\":\"Inference Component Name header is required for endpoints to which you plan to deploy inference components. Please include Inference Component Name header or consider using SageMaker models.\"}. Received Model Group=sagemaker-vllm\nAvailable Model Group Fallbacks=None","type":null,"param":null,"code":"400"}}
HTTP_STATUS=400

Same flow through the OpenAI Python SDK (openai==2.54.0) pointed at the proxy:

CLIENT_ERROR BadRequestError status: 400
body: {'message': 'litellm.BadRequestError: SagemakerException - {"ErrorCode":"INFERENCE_COMPONENT_NAME_MISSING","Message":"Inference Component Name header is required for endpoints to which you plan to deploy inference components. Please include Inference Component Name header or consider using SageMaker models."}. Received Model Group=sagemaker-vllm\nAvailable Model Group Fallbacks=None', 'type': None, 'param': None, 'code': '400'}

After (2ea633d223): HTTP 200 and a real completion

curl -sS -w '\nHTTP_STATUS=%{http_code}\n' http://127.0.0.1:$PORT/v1/chat/completions \
  -H 'Content-Type: application/json' -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
  -d '{"model":"sagemaker-vllm","messages":[{"role":"user","content":"Say hello in three words."}]}'
{"id":"chatcmpl-85a534ec4a337f57","created":1787281556,"model":"sagemaker-vllm","object":"chat.completion","system_fingerprint":"vllm-0.27.1-889a35c9","choices":[{"finish_reason":"stop","index":0,"message":{"content":"Hello, how are you?","role":"assistant"}}],"usage":{"completion_tokens":7,"prompt_tokens":35,"total_tokens":42}}
HTTP_STATUS=200

Same flow through the OpenAI Python SDK:

CLIENT_SUCCESS
{
  "id": "chatcmpl-a1d61b3484d8b9c5",
  "choices": [{"finish_reason": "stop", "index": 0,
               "message": {"content": "Hello! How can I help you today?", "role": "assistant"}}],
  "created": 1787281555,
  "model": "sagemaker-vllm",
  "object": "chat.completion",
  "system_fingerprint": "vllm-0.27.1-889a35c9",
  "usage": {"completion_tokens": 10, "prompt_tokens": 35, "total_tokens": 45}
}

Regression legs, so nothing changes for endpoints that set neither key

Every row below is the same curl and the same SDK call, only the config differs. The 400s are the correct result: an endpoint that requires the header still says it is missing, rather than a new "Inference Component ... not found" error, which is what AWS answers when a wrong header is actually sent.

Config Before After
model_id + hf_model_name 400 missing 200
model_id only 400 missing 200
neither key 400 missing 400 missing
hf_model_name only 400 missing 400 missing

The model_id only row is the reporter's exact config from #9909, and it flips on the header change alone.

One half is not provable on this rig, stated plainly

The header fix proves itself end to end above. The hf_model_name fix does not, and this run did not pretend otherwise. vLLM 0.27.1's /invocations route ignores the request body's model outright: sending the endpoint name, and then outright nonsense, both returned 200, and the response always echoes back the served model. So the client sees the same 200 whether or not the body was rewritten. The difference appears only in the outbound request, where the model_id only leg sends the endpoint name and the leg with hf_model_name sends Qwen/Qwen2.5-0.5B-Instruct. That is wire evidence rather than something an end user observes, so it is flagged here instead of being presented as proof. The regression tests in this PR assert it on the wire directly. Users whose container does validate the body's model see it as the 404 in the User Flow above; this rig's container is not one of them.

Things the QA legs saw that the diff does not show

  • inference_component_name config key is dead, silently ignored
  • Config keys leak into the outbound JSON body generally
  • This PR neither causes nor worsens either; both predate it
  • Response model echoes the proxy alias, not the served model
  • Request-body model_id overrides the configured inference component
  • Before this PR extra_headers overrode it more freely still

Type

🐛 Bug Fix

Caveats (if any)

  • hf_model_name only affects sagemaker_chat, not the legacy provider
  • Header value comes from model_id, the key the legacy provider already uses

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Note

Medium Risk
Changes signed AWS request headers and outbound JSON for SageMaker chat. Behavior is gated on optional params, but a wrong header or body model would 400/404 live endpoints.

Overview
Makes sagemaker_chat work with SageMaker inference-component endpoints and containers that validate the served model name.

When model_id is set, validate_environment now adds X-Amzn-SageMaker-Inference-Component before SigV4 so the header is signed (matching the legacy sagemaker provider). When hf_model_name is set, transform_request overwrites the request body's model with that served name instead of the endpoint name. Endpoints that set neither keep the previous request shape.

Tests drive a real completion() through a capturing HTTP client and assert the signed header and body rewrite, plus the no-op cases.

Reviewed by Cursor Bugbot for commit 2ea633d. Bugbot is set up for automated code reviews on this repo. Configure here.

…_model_name

sagemaker_chat never put X-Amzn-SageMaker-Inference-Component on the request, so any endpoint
backed by inference components answered 400 INFERENCE_COMPONENT_NAME_MISSING and the call never
reached the container. The legacy sagemaker provider has built that header from model_id since
#8889, and this brings the chat provider in line. It goes on in validate_environment, which runs
before the request is SigV4-signed, so the signature covers it

The request body also always named the endpoint rather than the served model, which containers
that validate the body's model answer with a 404. hf_model_name now becomes the body's model
when it is set, and endpoints that do not set it keep sending exactly what they send today
@greptile-apps

greptile-apps Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR updates the SageMaker chat adapter to support inference-component deployments and served-model names.

  • Adds the configured model_id as a signed X-Amzn-SageMaker-Inference-Component header.
  • Uses hf_model_name for the request body’s model while retaining the endpoint name for routing.
  • Adds isolated transport tests for configured and unset behavior.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete blocking or non-blocking defects identified in the changed paths.

The configured inference-component name is added before signing, the served-model override affects only the body while endpoint routing remains unchanged, and unset parameters preserve prior behavior.

Important Files Changed

Filename Overview
litellm/llms/sagemaker/chat/transformation.py Adds provider-scoped header and request-body transformations while preserving existing behavior when the new configuration values are unset.
tests/test_litellm/llms/sagemaker/test_sagemaker_chat_transformation.py Adds network-isolated regression coverage that captures the signed outbound headers and serialized request body.

Reviews (1): Last reviewed commit: "fix(sagemaker_chat): send the inference ..." | Re-trigger Greptile

@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 2ea633d. Configure here.

@codspeed

codspeed Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_sagemaker_chat_inference_component_header (2ea633d) with litellm_internal_staging (65b4ac0)1

Open in CodSpeed

Footnotes

  1. No successful run was found on litellm_internal_staging (354f497) during the generation of this report, so eb6296e was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@mateo-berri
mateo-berri enabled auto-merge August 21, 2026 03:48
@mateo-berri
mateo-berri merged commit e17988f into litellm_internal_staging Aug 21, 2026
76 checks passed
@mateo-berri
mateo-berri deleted the litellm_sagemaker_chat_inference_component_header branch August 21, 2026 04:01
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.

[Bug]: sagemaker_chat provider does not correctly pass the model_id for the SageMaker Inference Component

2 participants