Support Bedrock application inference profile ARNs as model ids#803
Support Bedrock application inference profile ARNs as model ids#803mattwebbio wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #803 +/- ##
==========================================
- Coverage 81.90% 81.89% -0.01%
==========================================
Files 169 169
Lines 7713 7715 +2
Branches 1284 1284
==========================================
+ Hits 6317 6318 +1
Misses 884 884
- Partials 512 513 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
8ef5bb5 to
5bfc269
Compare
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.
5bfc269 to
528c2df
Compare
|
Rebased this onto current Happy to adjust anything — e.g. fold the escaping somewhere else or tighten the tests — if there's a shape you'd prefer. |
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 Converse protocol builds the request path with the id raw —
"/model/#{@model.id}/converse"— and the SigV4 signer (Bedrock::Auth#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 (rebased onto current
mainafter the Converse refactor, so the escaping now lives in the sharedProtocols::Converserather than the oldBedrock::Chat/Streaming):lib/ruby_llm/protocols/converse/chat.rb—completion_urlnow escapes the id via a newescape_model_idhelper.lib/ruby_llm/protocols/converse/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(14 examples, 0 failures — the 4 new path-encoding examples alongside the existing Bedrock specs);bundle exec rubocopon the changed files reports no offenses.models.json,aliases.json)AI-generated code
API changes