feat(bedrock): support Bearer token auth for Bedrock-compatible proxies - #33340
feat(bedrock): support Bearer token auth for Bedrock-compatible proxies#33340vidgewong wants to merge 1 commit into
Conversation
|
Likely duplicate of #17162, which adds the same Bearer token auth for Bedrock-compatible proxies to the same files ( |
d635345 to
7eb3e8e
Compare
When AWS_BEARER_TOKEN_BEDROCK and ANTHROPIC_BEDROCK_BASE_URL are both set, use Bearer auth instead of SigV4 signing. Also match "claude-*" model names so proxies using Anthropic native names route correctly. Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
52e7e53 to
4e7b21a
Compare
lordbuffcloud
left a comment
There was a problem hiding this comment.
LGTM. The Bearer-token branch for Bedrock-compatible proxies is small and targeted, and the model-classification tweak for bare proxy names lines up with the intended routing path. I smoke-tested the new branch locally with a mocked AnthropicBedrock SDK: it produced an Authorization: Bearer header and preserved the existing default headers/timeouts, and the bedrock model-detection tests still passed.
|
Hi, is there anything else needed for this to be merged? |
|
For anyone tracking bearer-token Bedrock support: the two PRs that look closest to a complete fix for native Bedrock are #24507 (main-loop Converse routing + Relative to this PR: this targets a different use case — Bedrock-compatible corporate proxies via |
|
Update — the aux vision gap noted in my comment above is now resolved by #28085's second commit ( |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for targeting the corporate Bedrock-proxy case; current main still lacks this specific AnthropicBedrock bearer path.
Problems
- The new bearer constructor at
agent/anthropic_adapter.py:813omitsmax_retries=0. Current main deliberately disables SDK retries atagent/anthropic_adapter.py:865-867, with coverage attests/agent/test_anthropic_adapter.py:219-224; this branch should preserve that behavior. - The PR changes only production files and has no regression coverage for the custom URL/auth branch. It also relies on the SDK-private
_prepare_requestoverride atagent/anthropic_adapter.py:803-804. - The endpoint is exposed only through a new non-secret environment variable. Bedrock already has a config surface (
hermes_cli/config.py:1523-1529); related #17162 is useful reference for a config-backed endpoint spanning Anthropic and Converse paths.
Suggested changes
- Preserve
max_retries=0and add branch-specific tests for the bearer header, custom URL, unset-env SigV4 behavior, andclaude-*routing. - Move the endpoint into Bedrock configuration/docs and validate the supported SDK auth mechanism rather than leaving a private-method override untested.
Automated hermes-sweeper review.
| aws_secret_key="unused", | ||
| base_url=custom_base_url, | ||
| timeout=Timeout(timeout=900.0, connect=10.0), | ||
| default_headers={"anthropic-beta": ",".join([*_COMMON_BETAS, _CONTEXT_1M_BETA])}, |
There was a problem hiding this comment.
Please pass max_retries=0 here as well. Current main disables Anthropic SDK retries for the normal Bedrock client (agent/anthropic_adapter.py:865-867) so Hermes's outer retry loop remains authoritative; the bearer branch otherwise regresses that invariant.
Summary
Some enterprise environments expose Bedrock-compatible endpoints behind corporate proxies that authenticate via Bearer tokens rather than AWS SigV4. These proxies use the same path format (
/model/{model}/invoke) but acceptAuthorization: Bearer <token>instead of SigV4-signed requests.This PR adds support for this pattern without affecting existing workflows.
Changes
agent/anthropic_adapter.py: When bothAWS_BEARER_TOKEN_BEDROCKandANTHROPIC_BEDROCK_BASE_URLenv vars are set, creates a subclass ofAnthropicBedrockthat overrides_prepare_request()to inject Bearer auth instead of SigV4 signing. When these vars are not set, behavior is unchanged.agent/bedrock_adapter.py: Extendsis_anthropic_bedrock_model()to also matchclaude-*model names (Anthropic native format), not justanthropic.claude-*(Bedrock foundation model IDs). Proxies often use the shorter name format.Safety
AWS_BEARER_TOKEN_BEDROCKandANTHROPIC_BEDROCK_BASE_URLare set simultaneouslyUse Case
Enterprise users whose IT provides a Bedrock-compatible API gateway (e.g.
genai-nexus.api.corpinter.net) with Bearer token auth can now use Hermes without needing direct AWS credentials:Test Plan