Repository navigation
fix(aws): percent-encode the model id in Bedrock and SageMaker URLs - #826
Open
beriki770-ship-it wants to merge 1 commit into
Open
beriki770-ship-it wants to merge 1 commit into
beriki770-ship-it wants to merge 1 commit into
Conversation
get_url() put the model id into the path as-is. Bedrock accepts ARNs there (provisioned throughput, application inference profiles), and the "/" in an ARN split it into two path segments. Encode the id as one segment, the same URL boto3's bedrock-runtime client builds.
chrikrah
approved these changes
Nov 9, 2026
chrikrah
left a comment
There was a problem hiding this comment.
@beriki770-ship-it The encoded URL equals the one boto3 sends from invoke_model, which was the claim to check. Nothing here blocks a merge from my side.
# git archive f62335c (base a37a6cf), Python 3.12 venv + boto3, cohere.__file__ printed from the export
$ pytest -q tests/test_aws_client_unit.py
11 passed # f62335c
2 failed, 9 passed # aws_client.py from a37a6cf, tests kept (the ARN and hook cases)
# boto3 bedrock-runtime invoke_model(modelId=...), URL captured in before-send, vs get_url() at f62335c
ARN with ":" and "/", "us.cohere.embed-v4:0", "cohere.embed-english-v3", "my model/x" -> identical on all four
non-blocking: us.cohere.embed-v4:0 now goes out as us.cohere.embed-v4%3A0. boto3 sends the same, so I'd keep it, but test_plain_model_ids_are_unchanged only pins cohere.embed-english-v3. Could it also pin us.cohere.embed-v4:0 with its %3A form, so that change is on record?
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.
get_url()insrc/cohere/aws_client.pyputs the model id into the path as-is. Bedrock also takes an ARN as the model id (provisioned throughput, application inference profiles), and the/in an ARN splits it into two path segments:The fix percent-encodes the id as one segment (
quote(model, safe="")) for Bedrock and SageMaker. With it the URL, and the canonical URI botocore's SigV4 signer computes, match whatboto3.client("bedrock-runtime").invoke_model(modelId=...)produces for a plain id, a cross-region profile id with:and an ARN. I checked that offline with fake credentials (repro script: https://gist.github.com/beriki770-ship-it/61d651c04994d799967e5306c3e08bb1). I have no AWS account, so I did not run it against live Bedrock.Tests: 3 mocked tests in
tests/test_aws_client_unit.py(ARN becomes one encoded segment; plain ids unchanged; the request hook sends and signs the encoded URL). 2 fail on main, all pass with the fix. Fullpytest -n 8 .withoutCO_API_KEY: the remaining failures are the live API tests in test_client.py, test_client_v2.py and test_async_client.py, same set on main.mypy .clean;ruff check .shows no new findings.Note
Medium Risk
Changes URL construction and SigV4 signing for all AWS runtime calls; low behavioral risk for simple model ids but critical for ARN-based model ids.
Overview
Fixes broken Bedrock/SageMaker requests when the model id is an ARN (provisioned throughput or application inference profiles). Unencoded
:and/in the id were treated as extra path segments, so URLs and SigV4 canonical paths did not match what boto3 sends.get_url()now builds a single path segment withurllib.parse.quote(model, safe="")for both Bedrock and SageMaker; plain model names are unchanged. The request hook still stripsmodelfrom the JSON body but now rewrites and signs the encoded URL.Adds mocked unit tests for ARN encoding, unchanged plain ids, and hook URL/signing behavior.
Reviewed by Cursor Bugbot for commit f62335c. Bugbot is set up for automated code reviews on this repo. Configure here.