feat: Support requestMetadata in Bedrock Converse API #14570
+393
−37
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Title
feat: Support requestMetadata in Bedrock Converse API
Relevant issues
Fixes #14562
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/
directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit
Type
🆕 New Feature
Changes
What this PR does
Adds support for AWS Bedrock Converse API
requestMetadata
parameter in LiteLLM SDK, enabling users to attach arbitrary metadata to requests for logging, traceability, and cost attribution in multi-cloud environments.Problem being solved
Currently, the
requestMetadata
field is ignored when sending Bedrock API requests through LiteLLM, preventing users from adding metadata for observability and operational use cases. This feature request (#14562) aims to provide the same functionality as labels in Vertex AI, allowing metadata that is not influenced by prompt content to be attached to requests for accurate traceability.Core Implementation
litellm/types/llms/bedrock.py:223
): AddedrequestMetadata: Optional[Dict[str, str]]
field toCommonRequestObject
litellm/llms/bedrock/chat/converse_transformation.py:207
): Addedrequest_metadata
toget_supported_openai_params()
litellm/llms/bedrock/chat/converse_transformation.py:123-195
): Implemented comprehensive validation following AWS Bedrock constraints:[a-zA-Z0-9\s:_@$#=/+,.-]
litellm/llms/bedrock/chat/converse_transformation.py:517-520, 843-845
): Mapsrequest_metadata
parameter to top-levelrequestMetadata
field in Bedrock API requestTesting
test_converse_transformation.py:1595-1601
): Verifiesrequest_metadata
appears in supported parameterstest_converse_transformation.py:1604-1641
): Ensures proper mapping to top-levelrequestMetadata
fieldtest_converse_transformation.py:1644-1734
): Comprehensive validation of AWS constraints including:How to verify it
Automated Verification
poetry run pytest tests/test_litellm/llms/bedrock/chat/test_converse_transformation.py -k "request_metadata" -v
test_request_metadata_parameter_support
,test_request_metadata_transformation
,test_request_metadata_validation
✅poetry run ruff check litellm/llms/bedrock/chat/converse_transformation.py
✅Manual Verification
request_metadata
parameter and verify it appears in Bedrock API requestBreaking changes
None - this is a purely additive feature that maintains full backward compatibility.
Migration required
None - existing code continues to work unchanged. Users can optionally start using the new
request_metadata
parameter.Usage Example
The
request_metadata
will be included in the Bedrock API request as a top-levelrequestMetadata
field, enabling proper logging and traceability.Related issues/PRs
Next Steps