gateway
gateway copied to clipboard
Fix/support provider specific fields for bedrock in snake case
Author Description
So, portkey node SDK converts input parameters in chat.completions requests into snake_case, when I originally added transforms for additionalModelRequestFields, it was in camelCase, it was tested with the REST API and the python sdk, but not the node sdk
Summary By MatterAI
π What Changed
This PR adds support for snake_case versions of provider-specific fields for AWS Bedrock in addition to the existing camelCase versions. The change was necessary because the Portkey Node SDK converts all input parameters in chat.completions requests into snake_case format, which was causing issues with the additionalModelRequestFields and other parameters.
π Impact of the Change
This change ensures compatibility with the Portkey Node SDK by supporting both camelCase and snake_case parameter formats. It maintains backward compatibility while fixing the issue with the Node SDK integration.
π Total Files Changed
2 files changed with 46 additions and 4 deletions:
- src/providers/bedrock/chatComplete.ts: +34, -0
- src/providers/bedrock/utils.ts: +12, -4
π§ͺ Test Added
N/A
π Security Vulnerabilities
No security vulnerabilities introduced.
Type of Change
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation update
- [ ] Refactoring (no functional changes)
How Has This Been Tested?
- [ ] Unit Tests
- [ ] Integration Tests
- [x] Manual Testing
Screenshots (if applicable)
N/A
Checklist
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
Related Issues
Issue with Portkey Node SDK converting parameters to snake_case
Quality Recommendations
-
Consider adding unit tests to verify the snake_case parameter handling works correctly
-
Add documentation comments to explain why both camelCase and snake_case versions are supported
-
Consider creating a utility function to handle the duplicate parameter checking pattern that appears in multiple transform functions
Sequence Diagram
sequenceDiagram
participant Client
participant PortkeyNodeSDK
participant Gateway
participant BedrockProvider
participant AWSBedrock
Client->>PortkeyNodeSDK: chat.completions request
Note over PortkeyNodeSDK: Converts parameters to snake_case
PortkeyNodeSDK->>Gateway: Forward request with snake_case params
Gateway->>BedrockProvider: Process request
Note over BedrockProvider: Now supports both camelCase and snake_case:
Note over BedrockProvider: - additionalModelRequestFields
Note over BedrockProvider: - additional_model_request_fields
Note over BedrockProvider: - guardrailConfig
Note over BedrockProvider: - guardrail_config
BedrockProvider->>BedrockProvider: Transform parameters
Note over BedrockProvider: transformAdditionalModelRequestFields()
Note over BedrockProvider: transformAnthropicAdditionalModelRequestFields()
Note over BedrockProvider: transformCohereAdditionalModelRequestFields()
Note over BedrockProvider: transformAI21AdditionalModelRequestFields()
BedrockProvider->>AWSBedrock: Send properly formatted request
AWSBedrock->>BedrockProvider: Return response
BedrockProvider->>Gateway: Process response
Gateway->>PortkeyNodeSDK: Return formatted response
PortkeyNodeSDK->>Client: Return final response
So, portkey node SDK converts input parameters in chat.completions requests into snake_case, when I originally added transforms for additionalModelRequestFields, it was in camelCase, it was tested with the REST API and the python sdk, but not the node sdk
Summary By MatterAI 
π What Changed
- Updated
BedrockChatCompletionsParamsinterface to include snake_case versions ofadditionalModelRequestFieldsandguardrailConfig. - Added corresponding configuration entries in
BedrockConverseChatCompleteConfigand provider-specific configs (Anthropic, Cohere, AI21) to handle the new snake_case parameters. - Modified transformation functions in
src/providers/bedrock/utils.ts(transformAdditionalModelRequestFields,transformAnthropicAdditionalModelRequestFields, etc.) to prioritize camelCase but fall back to snake_case versions when initializingadditionalModelRequestFields. - Refactored the configuration for
anthropic_beta(specifically for Anthropic models on Bedrock) to route it through thetransformAnthropicAdditionalModelRequestFieldsfunction, treating it as part of the additional model request fields.
π Impact of the Change
- Enables users interacting with the Gateway via SDKs that automatically convert parameters to snake_case (like
portkey-node-sdk) to successfully pass Bedrock-specific fields (additionalModelRequestFields,guardrailConfig,anthropic_beta, etc.). - Increases flexibility by supporting both camelCase and snake_case for these specific parameters.
- Introduces redundancy in interface definitions and configuration mapping.
- Potentially introduces a bug where
anthropic_betamight not be correctly included in the final request payload under certain conditions due to the refactoring.
π Total Files Changed
- 2 files changed (
src/providers/bedrock/chatComplete.ts,src/providers/bedrock/utils.ts).
π§ͺ Test Added
- N/A (No specific tests mentioned or added in the provided PR data).
πSecurity Vulnerabilities
- N/A (No security vulnerabilities detected in the changed code).
Description
See Summary By MatterAI above.
Motivation
To support Bedrock provider-specific fields (like additionalModelRequestFields, guardrailConfig, anthropic_beta) when passed in snake_case, primarily due to portkey-node-sdk converting all parameters to snake_case.
Type of Change
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation update
- [x] Refactoring (no functional changes)
How Has This Been Tested?
- [ ] Unit Tests
- [ ] Integration Tests
- [x] Manual Testing (Implied based on PR description mentioning testing with REST API and Python SDK previously, and this fix addressing Node SDK)
Screenshots (if applicable)
N/A
Checklist
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [x] New and existing unit tests pass locally with my changes
Related Issues
N/A
Sequence Diagram
sequenceDiagram
participant SDK as SDK (e.g., portkey-node-sdk)
participant Gateway as Gateway API
participant BedrockProvider as src/providers/bedrock/chatComplete.ts
participant BedrockUtils as src/providers/bedrock/utils.ts
participant BedrockAPI as AWS Bedrock API
SDK->>Gateway: POST /v1/chat/completions (payload with snake_case params, e.g., additional_model_request_fields, guardrail_config, anthropic_beta)
Gateway->>BedrockProvider: mapRequestParams(payload)
Note over BedrockProvider: Interface BedrockChatCompletionsParams now accepts both camelCase and snake_case variants (e.g., additionalModelRequestFields, additional_model_request_fields).
Note over BedrockProvider: Config objects (e.g., BedrockConverseChatCompleteConfig) now have entries for snake_case params, mapping them to internal logic/transforms.
BedrockProvider->>BedrockUtils: transformAdditionalModelRequestFields(params)
BedrockUtils->>BedrockUtils: Initialize additionalModelRequestFields = params.additionalModelRequestFields || params.additional_model_request_fields || {}
BedrockUtils->>BedrockProvider: Return transformedFields
Note over BedrockProvider: For anthropic_beta, config now points to transformAnthropicAdditionalModelRequestFields.
BedrockProvider->>BedrockUtils: transformAnthropicAdditionalModelRequestFields(params)
BedrockUtils->>BedrockUtils: Initialize additionalModelRequestFields = params.additionalModelRequestFields || params.additional_model_request_fields || {}
BedrockUtils->>BedrockUtils: Add top_k, top_p if present in params
Note over BedrockUtils: Potential issue: anthropic_beta from top-level params might not be merged here.
BedrockUtils->>BedrockProvider: Return transformed Anthropic fields
BedrockProvider->>BedrockAPI: InvokeModel / Converse API call (with transformed parameters)
BedrockAPI->>BedrockProvider: Response
BedrockProvider->>Gateway: Formatted Response
Gateway->>SDK: Response
Summary By MatterAI 
π What Changed
- Updated Bedrock provider interfaces and configurations (
src/providers/bedrock/chatComplete.ts) to accept provider-specific parameters (likeadditionalModelRequestFields,guardrailConfig) in bothcamelCaseandsnake_case. - Modified utility functions (
src/providers/bedrock/utils.ts) to correctly retrieve these parameters regardless of the case used in the input, prioritizingcamelCaseif both are provided. - Adjusted the mapping for
anthropic_betato be handled viaadditionalModelRequestFieldsfor Anthropic models on Bedrock.
π Impact of the Change
- Ensures compatibility with clients like
portkey-node-sdkthat automatically convert request parameters tosnake_case. - Allows users to send Bedrock-specific parameters using either naming convention without errors.
- Maintains backward compatibility for clients sending
camelCaseparameters.
π Total Files Changed
- 2 files changed (
src/providers/bedrock/chatComplete.ts,src/providers/bedrock/utils.ts)
π§ͺ Test Added
- N/A (Based on PR description, testing appears to have been manual or via existing integration tests. No new specific unit tests were mentioned for the case handling logic.)
πSecurity Vulnerabilities
- No security vulnerabilities detected in the changes.
Motivation
So, portkey node SDK converts input parameters in chat.completions requests into snake_case, when I originally added transforms for additionalModelRequestFields, it was in camelCase, it was tested with the REST API and the python sdk, but not the node sdk
Type of Change
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation update
- [ ] Refactoring (no functional changes)
How Has This Been Tested?
- [ ] Unit Tests
- [ ] Integration Tests
- [x] Manual Testing (Implied from PR description context)
Screenshots (if applicable)
N/A
Checklist
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [x] New and existing unit tests pass locally with my changes
Related Issues
N/A
Sequence Diagram
sequenceDiagram
participant Client as Client (e.g., portkey-node-sdk)
participant Gateway as Portkey Gateway
participant BedrockProvider as Bedrock Provider Logic
participant BedrockAPI as AWS Bedrock API
Client->>Gateway: POST /v1/chat/completions (payload with snake_case params like additional_model_request_fields, guardrail_config)
Gateway->>BedrockProvider: processChatComplete(payload)
Note over Gateway,BedrockProvider: Config maps snake_case params (e.g., additional_model_request_fields) to internal camelCase (additionalModelRequestFields)
BedrockProvider->>BedrockProvider: transform*AdditionalModelRequestFields(params)
Note over BedrockProvider: Util function checks for params.camelCase || params.snake_case || {}
BedrockProvider->>BedrockProvider: Construct Bedrock API Request (using transformed params)
BedrockProvider->>BedrockAPI: InvokeModel / Converse API Call
BedrockAPI-->>BedrockProvider: API Response
BedrockProvider-->>Gateway: Formatted Response
Gateway-->>Client: Final Response