Support Bedrock application inference profile ARNs as model ids#803
Open
mattwebbio wants to merge 1 commit into
Open
Support Bedrock application inference profile ARNs as model ids#803mattwebbio wants to merge 1 commit into
mattwebbio wants to merge 1 commit into
Conversation
Application inference profiles (used for cost-allocation tagging) are invoked by
passing their ARN as the modelId. The Bedrock provider built the request path as
"/model/#{@model.id}/converse" with the id raw, so an ARN's internal "/"
(".../application-inference-profile/<id>") was parsed as a path separator in both
the request URL and the SigV4 canonical path — AWS then rejected it with
"The provided model identifier is invalid".
Percent-encode the model id's "/" so the ARN stays a single path segment.
canonical_uri re-encodes per segment, which double-encodes it as SigV4 requires for
non-S3 services, keeping the signed and sent paths consistent. No-op for ordinary
model ids (which contain no "/"); ":" version suffixes are valid path-segment
characters and are unaffected.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #803 +/- ##
=======================================
Coverage 88.47% 88.47%
=======================================
Files 122 122
Lines 5898 5900 +2
Branches 1405 1405
=======================================
+ Hits 5218 5220 +2
Misses 680 680 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
Fixes Bedrock so an application inference profile ARN can be passed as the model id.
Application inference profiles (used for cost-allocation tagging) are invoked by passing their ARN as the
modelId. An ARN contains a/:The Bedrock provider builds the request path with the id raw —
"/model/#{@model.id}/converse"— and the SigV4 signer (Bedrock::Signing#canonical_uri) splits the path on/to build the canonical URI. So the ARN's internal/is treated as a path separator in both the request URL and the signed canonical path, truncating themodelIdto.../application-inference-profile. Bedrock then rejects the call:The fix percent-encodes the model id's
/(%2F) so the ARN stays a single path segment.canonical_urithen re-encodes each segment, double-encoding it to%252F— which is exactly what SigV4 requires for non-S3 services — so the signed path and the sent path stay consistent.This is a no-op for ordinary model ids, which contain no
/. A:version suffix (e.g....-v1:0) is a valid path-segment character and is unaffected.Files:
lib/ruby_llm/providers/bedrock/chat.rb—completion_urlnow escapes the id via a newescape_model_idhelper.lib/ruby_llm/providers/bedrock/streaming.rb—stream_urlescapes the id too (converse-stream).spec/ruby_llm/providers/bedrock_spec.rb— new unit spec covering the converse URL, the converse-stream URL, an unchanged ordinary id, and the SigV4 canonical-path encoding.Type of change
Scope check
Required for new features
N/A — bug fix in an existing provider, no new public API.
Quality check
overcommit --installand all hooks passbundle exec rake vcr:record[provider_name]— N/A: this change only affects URL/path string construction; it touches no HTTP request body or response handling, and the new spec is a pure unit test (no cassette), consistent with the other top-level provider specs (vertex_ai_auth_spec.rb,ollama_spec.rb, etc.).bundle exec rspec spec/ruby_llm/providers/bedrock_spec.rb(4 examples, 0 failures);bundle exec rubocopon the changed files reports no offenses.models.json,aliases.json)AI-generated code
API changes