-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
feat: Support requestMetadata in Bedrock Converse API #14570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Support requestMetadata in Bedrock Converse API #14570
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
document this param @timelfrink
also ideally - shouldn't we have a consistent param for such values across gemini / bedrock?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added to docs.
Not sure if you want to have one param for this. I think we should follow the provider's native API parameter names (like AWS's requestMetadata and Google's labels) rather than forcing artificial uniformity. What you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i trust your instinct
- Test requestMetadata parameter support in get_supported_openai_params - Test transformation to top-level field in Bedrock API request - Test validation of AWS constraints: max 16 items, key/value length limits - Test character set validation for keys and values - Cover edge cases including empty values and special characters - Ensure compatibility with existing test patterns
- Add requestMetadata field to CommonRequestObject type definition - Support request_metadata parameter in get_supported_openai_params - Add comprehensive validation for AWS Bedrock constraints: * Maximum 16 key-value pairs * Key length 1-256 characters * Value length 0-256 characters * Character set validation [a-zA-Z0-9\s:_@0=/+,.-] - Transform request_metadata to top-level requestMetadata field in API request - Maintain backward compatibility with existing functionality - Enable metadata logging and traceability for multi-cloud environments
- Split _transform_request_helper into smaller focused methods - Extract _prepare_request_params for parameter preparation logic - Extract _process_tools_and_beta for tool processing logic - Resolve PLR0915 (too many statements) linting issue - Maintain all existing functionality and test compatibility
… params - Change parameter from request_metadata to requestMetadata to match camelCase convention - Consistent with guardrailConfig and performanceConfig naming pattern - Update all references in transformation code and error messages - Update tests and documentation to use correct parameter name - Fix type checking for parameter validation
04ed11a
to
27a37ce
Compare
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
): AddedrequestMetadata
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
): MapsrequestMetadata
parameter to top-levelrequestMetadata
field in Bedrock API requestTesting
test_converse_transformation.py:1595-1601
): VerifiesrequestMetadata
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 "requestMetadata" -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
requestMetadata
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
requestMetadata
parameter.Usage Example
The
requestMetadata
will be included in the Bedrock API request as a top-levelrequestMetadata
field, enabling proper logging and traceability.Related issues/PRs
Next Steps