new-api icon indicating copy to clipboard operation
new-api copied to clipboard

feat: support custom model prefix for AWS

Open prnake opened this issue 3 months ago • 1 comments

close #1928 ,支持用户自定义

Summary by CodeRabbit

  • New Features
    • Added support for AWS authentication with regional model prefix configuration. Users can now specify AccessKey, SecretAccessKey, Region, and Model Prefix when configuring AWS channels, enabling region-specific model routing and customizable model prefix settings for enhanced AWS integration flexibility.

prnake avatar Nov 13 '25 09:11 prnake

Walkthrough

This pull request adds support for a configurable AWS model prefix to accommodate AWS Bedrock's updated cross-region deployment naming scheme (e.g., global, eu, jp, us). It introduces a new AWS secret format accepting a region-specific prefix, updates the AWS client initialization and model ID resolution logic, and extends the UI to support the new format option.

Changes

Cohort / File(s) Summary
AWS Constants and Configuration
dto/channel_settings.go
Added new constant AwsKeyTypeAKSKRegionPrefix = "ak_sk_region_prefix" to define the 4-parameter AWS secret format (AccessKey, SecretAccessKey, Region, Prefix).
AWS Adaptor Structure
relay/channel/aws/adaptor.go
Added public field ModelPrefix string to the Adaptor struct to carry prefix information through AWS requests.
AWS Client Initialization and Model Routing
relay/channel/aws/relay-aws.go
Reworked newAwsClient to return (client, modelPrefix, hasCustomPrefix, error) and handle the new 4-parameter secret format. Updated doAwsClientRequest to store prefix in adaptor and conditionally route model IDs with custom prefix or region-derived prefix. Extended awsModelCrossRegion to accept and prioritize a configurable prefix parameter.
UI Configuration
web/src/components/table/channels/modals/EditChannelModal.jsx
Added new AWS key format option ak_sk_region_prefix with label "AccessKey / SecretAccessKey / Region / Prefix" and updated conditional prompts to guide users on the new 4-parameter format.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Modal as EditChannelModal
    participant Backend as relay-aws.go
    participant AWS as AWS Bedrock

    Client->>Modal: Select AWS channel config
    Modal->>Modal: Choose ak_sk_region_prefix format
    Modal->>Backend: Submit config with (ak, sk, region, prefix)
    
    Backend->>Backend: newAwsClient()
    Backend->>Backend: Parse 4-param secret
    Backend->>Backend: Extract modelPrefix from param
    Backend->>Backend: Set hasCustomPrefix = true
    Backend->>Backend: Create AWS client with region + credentials
    Backend->>Backend: Return (client, modelPrefix, true, nil)
    
    Backend->>Backend: doAwsClientRequest()
    Backend->>Backend: Receive modelPrefix & hasCustomPrefix
    Backend->>Backend: Store a.ModelPrefix = modelPrefix
    
    alt hasCustomPrefix is true
        Backend->>Backend: awsModelId = modelPrefix + "." + awsModelId
    else hasCustomPrefix is false
        Backend->>Backend: awsModelCrossRegion(awsModelId, regionPrefix, "")
        Backend->>Backend: Use region-derived prefix if empty configured
    end
    
    Backend->>AWS: Call with adjusted awsModelId
    AWS-->>Backend: Response
    Backend-->>Client: Success

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Areas requiring attention:
    • Logic flow in newAwsClient for secret format parsing and prefix extraction; verify all four format branches (2-param, 3-param, 4-param, and default) are correctly handled
    • Interaction between hasCustomPrefix flag and cross-region routing logic in doAwsClientRequest to ensure prefix precedence is correct
    • Consistency of prefix parameter propagation through awsModelCrossRegion and verify backward compatibility for existing 2-param and 3-param formats
    • UI prompt strings and placeholder logic in EditChannelModal to ensure user guidance is clear for the new format

Suggested reviewers

  • seefs001

Poem

🐰 A prefix hops through regions far, Global, JP, EU—what a par! Bedrock routes with newfound grace, Four parameters find their place. Config, adaptor, modal sync— The AWS model maze, now linked! 🌐

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: support custom model prefix for AWS' accurately reflects the main change: enabling users to configure custom model prefixes (global, eu, jp, us) for AWS Bedrock models.
Linked Issues check ✅ Passed The PR implements support for custom AWS model prefixes as required by issue #1928, enabling users to specify region prefixes (global, eu, jp, us) via a new ak_sk_region_prefix secret format.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing custom model prefix support: new constant, struct field, secret format handling, model ID resolution logic, and UI updates for the new format.
✨ Finishing touches
  • [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Nov 13 '25 09:11 coderabbitai[bot]