Skip to content

Add bedrock model ID fallback#817

Merged
crmne merged 1 commit into
crmne:mainfrom
hschne:main
Jul 7, 2026
Merged

Add bedrock model ID fallback#817
crmne merged 1 commit into
crmne:mainfrom
hschne:main

Conversation

@hschne

@hschne hschne commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

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 83.24%. Comparing base (1080a38) to head (f205774).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #817      +/-   ##
==========================================
- Coverage   83.30%   83.24%   -0.07%     
==========================================
  Files         172      172              
  Lines        8267     8267              
  Branches     1343     1343              
==========================================
- Hits         6887     6882       -5     
- Misses        886      888       +2     
- Partials      494      497       +3     

☔ 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.

@crmne crmne merged commit b24d560 into crmne:main Jul 7, 2026
23 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