Skip to content

Add bedrock model ID fallback#817

Open
hschne wants to merge 1 commit into
crmne:mainfrom
hschne:main
Open

Add bedrock model ID fallback#817
hschne wants to merge 1 commit into
crmne:mainfrom
hschne:main

Conversation

@hschne

@hschne hschne commented Jun 22, 2026

Copy link
Copy Markdown

What this does

Fix Bedrock Converse non-streaming responses so Message#model_id falls back to the request model when Bedrock omits modelId.

Why

Bedrock Converse responses do not include modelId, so non-streaming messages currently get model_id: nil. That prevents Message#cost from resolving pricing, even though the request model is known. Streaming already falls back to @model.id; this makes non-streaming match that behavior.

Reproduction

require 'ruby_llm'

RubyLLM.configure do |config|
  config.bedrock_api_key = ENV.fetch('AWS_ACCESS_KEY_ID')
  config.bedrock_secret_key = ENV.fetch('AWS_SECRET_ACCESS_KEY')
  config.bedrock_session_token = ENV['AWS_SESSION_TOKEN']
  config.bedrock_region = ENV.fetch('AWS_REGION')
end

message = RubyLLM.chat(model: 'openai.gpt-oss-120b-1:0', provider: :bedrock).ask('Say hi in one sentence.')

puts "model_id: #{message.model_id.inspect}"
puts "input_tokens: #{message.input_tokens.inspect}"
puts "output_tokens: #{message.output_tokens.inspect}"
puts "cost_total: #{message.cost.total.inspect}"

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
    • For provider changes: Re-recorded VCR cassettes with bundle exec rake vcr:record[provider_name]
    • All tests pass: bundle exec rspec
  • I updated documentation if needed
  • I didn't modify auto-generated files manually (models.json, aliases.json)

AI-generated code

  • I used AI tools to help write this code
  • I have reviewed and understand all generated code (required if above is checked)

API changes

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

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.42%. Comparing base (f2e806d) to head (26b98a9).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #817      +/-   ##
==========================================
+ Coverage   81.38%   81.42%   +0.04%     
==========================================
  Files         165      165              
  Lines        7361     7361              
  Branches     1220     1220              
==========================================
+ Hits         5991     5994       +3     
+ Misses        875      874       -1     
+ Partials      495      493       -2     

☔ View full report in Codecov by Harness.
📢 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.

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.

1 participant