Repository navigation
fix(sagemaker_chat): send the inference component header and honor hf_model_name - #37766
Conversation
…_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 SummaryThis PR updates the SageMaker chat adapter to support inference-component deployments and served-model names.
Confidence Score: 5/5The 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.
|
| 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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
bugbot run |
There was a problem hiding this comment.
✅ 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.
TLDR
Problem this solves:
sagemaker_chatnever sends the inference component headerHow it solves it:
model_id, before the request is signedsagemakerprovider already doeshf_model_nameas the body's model when setUser Flow
Before: an operator whose model is deployed as a SageMaker inference component cannot get a single completion through without hand-editing the request
model: sagemaker_chat/<endpoint-name>to the proxy config withmodel_id: <inference-component-name>andhf_model_name: <served-model-name>, then start the proxySagemakerException - {"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 containerextra_headers: {"X-Amzn-SageMaker-Inference-Component": "<inference-component-name>"}to that model and restart, which finally gets the request past AWSThe model '<endpoint-name>' does not exist., because the request asked for the endpoint by name instead of the model the container actually servesAfter: the same config works on the first try, with no
extra_headersand nothing overridden per requestmodel: sagemaker_chat/<endpoint-name>to the proxy config withmodel_id: <inference-component-name>andhf_model_name: <served-model-name>, then start the proxymodel_idnorhf_model_namesends the same request and gets the same 200 they got before this changeRelevant issues
Fixes #9909
Linear ticket
Resolves LIT-2853
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
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@greptileaito 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-Instructon vLLM 0.27.1. Two matched worktrees, each with its own venv, its own.envand its own random port, differing only in the commit the proxy booted from: beforea66a10b1b5(this PR's merge base), after2ea633d223(this PR's head). Real AWS, real GPU, no mocks.Config under test, the same file on both legs:
Before (
a66a10b1b5): HTTP 400, the request never reaches the containerSame flow through the OpenAI Python SDK (
openai==2.54.0) pointed at the proxy:After (
2ea633d223): HTTP 200 and a real completionSame flow through the OpenAI Python SDK:
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.
model_id+hf_model_namemodel_idonlyhf_model_nameonlyThe
model_idonly 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_namefix does not, and this run did not pretend otherwise. vLLM 0.27.1's/invocationsroute ignores the request body'smodeloutright: 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 themodel_idonly leg sends the endpoint name and the leg withhf_model_namesendsQwen/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_nameconfig key is dead, silently ignoredmodelechoes the proxy alias, not the served modelmodel_idoverrides the configured inference componentextra_headersoverrode it more freely stillType
🐛 Bug Fix
Caveats (if any)
hf_model_nameonly affectssagemaker_chat, not the legacy providermodel_id, the key the legacy provider already usesFinal Attestation
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_chatwork with SageMaker inference-component endpoints and containers that validate the served model name.When
model_idis set,validate_environmentnow addsX-Amzn-SageMaker-Inference-Componentbefore SigV4 so the header is signed (matching the legacysagemakerprovider). Whenhf_model_nameis set,transform_requestoverwrites the request body'smodelwith 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.