Skip to content

Conversation

ESegundoRolon
Copy link
Contributor

What this does

Support region-aware inference profiles for AWS Bedrock

Problem

The current implementation hardcodes us. prefix for all Bedrock inference
profile models, causing failures when using cross-region inference in
non-US regions like EU, AP, or CA.

  • Error encountered:
    The provided model identifier is invalid. (RubyLLM::BadRequestError)

This occurs because:

  1. EU regions expect for example eu.anthropic.claude-sonnet-4-20250514-v1:0
  2. But the library sends us.anthropic.claude-sonnet-4-20250514-v1:0
  3. AWS Bedrock rejects the incorrect region prefix

Solution

Updated model_id_with_region method to dynamically extract the region
prefix from the configured bedrock_region:

  • eu-west-3 → eu. prefix
  • us-east-1 → us. prefix
  • ap-south-1 → ap. prefix
  • ca-central-1 → ca. prefix

Changes Made

Core Fix

File: lib/ruby_llm/providers/bedrock/models.rb

  • Modified model_id_with_region to use dynamic region prefix
  • Added inference_profile_region_prefix helper method
  • Uses first two characters of bedrock_region as prefix
  • Maintains backwards compatibility with us default

Tests Added

File: spec/ruby_llm/providers/bedrock/models_spec.rb

  • Comprehensive tests for different AWS regions (US, EU, AP, CA)
  • Tests for edge cases (empty/nil regions)
  • Tests for both inference profile and on-demand models
  • Ensures backwards compatibility

Testing

  • ✅ US regions continue to work (us. prefix)
  • ✅ EU regions now work (eu. prefix)
  • ✅ AP/CA regions supported (ap./ca. prefixes)
  • ✅ ON_DEMAND models unaffected
  • ✅ Backwards compatible with existing configurations

Breaking Changes

None. This change is fully backwards compatible.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Performance improvement

Scope check

  • I read the Contributing Guide
  • This aligns with RubyLLM's focus on LLM communication
  • This isn't application-specific logic that belongs in user code
  • This benefits most users, not just my specific use case

Quality check

  • I ran overcommit --install and all hooks pass
  • I tested my changes thoroughly
  • I updated documentation if needed
  • I didn't modify auto-generated files manually (models.json, aliases.json)

API changes

  • Breaking change
  • New public methods/classes
  • Changed method signatures
  • No API changes

@crmne
Copy link
Owner

crmne commented Aug 29, 2025

Hey @ESegundoRolon thanks for this. The CI is failing. Are you sure you run overcommit --install?

@ESegundoRolon
Copy link
Contributor Author

@crmne Hey! Sorry for the late response

It should be good now 👍

Copy link

codecov bot commented Sep 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.65%. Comparing base (32611af) to head (921fb82).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #338   +/-   ##
=======================================
  Coverage   84.65%   84.65%           
=======================================
  Files          35       35           
  Lines        1825     1825           
  Branches      492      492           
=======================================
  Hits         1545     1545           
  Misses        280      280           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@crmne crmne merged commit 791f28b into crmne:main Sep 6, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants