Skip to content

feat(bedrock): support Bearer token auth for Bedrock-compatible proxies - #33340

Open
vidgewong wants to merge 1 commit into
NousResearch:mainfrom
vidgewong:feat/bedrock-bearer-token-auth
Open

feat(bedrock): support Bearer token auth for Bedrock-compatible proxies#33340
vidgewong wants to merge 1 commit into
NousResearch:mainfrom
vidgewong:feat/bedrock-bearer-token-auth

Conversation

@vidgewong

Copy link
Copy Markdown

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 accept Authorization: Bearer <token> instead of SigV4-signed requests.

This PR adds support for this pattern without affecting existing workflows.

Changes

  • agent/anthropic_adapter.py: When both AWS_BEARER_TOKEN_BEDROCK and ANTHROPIC_BEDROCK_BASE_URL env vars are set, creates a subclass of AnthropicBedrock that overrides _prepare_request() to inject Bearer auth instead of SigV4 signing. When these vars are not set, behavior is unchanged.

  • agent/bedrock_adapter.py: Extends is_anthropic_bedrock_model() to also match claude-* model names (Anthropic native format), not just anthropic.claude-* (Bedrock foundation model IDs). Proxies often use the shorter name format.

Safety

  • Both changes are additive and gated behind environment variable checks
  • Existing Bedrock (SigV4), Anthropic native, and OpenRouter flows are unaffected
  • The Bearer path only activates when both AWS_BEARER_TOKEN_BEDROCK and ANTHROPIC_BEDROCK_BASE_URL are set simultaneously

Use 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:

# ~/.hermes/config.yaml
model:
  default: claude-opus-4.6
  provider: bedrock
# ~/.hermes/.env
AWS_BEARER_TOKEN_BEDROCK=<your-token>
ANTHROPIC_BEDROCK_BASE_URL=https://your-proxy.example.com

Test Plan

  • Verified Bearer token auth works with a corporate Bedrock proxy
  • Verified standard SigV4 Bedrock path is not affected (env vars unset)
  • Verified non-Bedrock providers (Anthropic native, OpenRouter) unaffected

@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have provider/bedrock AWS Bedrock (boto3, IAM) comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels May 27, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Likely duplicate of #17162, which adds the same Bearer token auth for Bedrock-compatible proxies to the same files (agent/anthropic_adapter.py, agent/bedrock_adapter.py). Also related to #24507 (Converse API routing for bearer auth) and #26531 (api_mode detection fix for bearer). The approach differs slightly (#17162 uses SDK api_key param vs this PR's _prepare_request override), but the feature is the same.

@vidgewong
vidgewong force-pushed the feat/bedrock-bearer-token-auth branch from d635345 to 7eb3e8e Compare May 27, 2026 16:41
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>
@vidgewong
vidgewong force-pushed the feat/bedrock-bearer-token-auth branch 4 times, most recently from 52e7e53 to 4e7b21a Compare May 27, 2026 16:55

@lordbuffcloud lordbuffcloud left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@vidgewong

Copy link
Copy Markdown
Author

Hi, is there anything else needed for this to be merged?

@RamsAI-bot

Copy link
Copy Markdown

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 + AWS_BEARER_TOKEN_BEDROCKAWS_BEARER_TOKEN promotion) and #28085 (auxiliary dual-path Converse client). They were verified to compose cleanly (cherry-pick, 0 conflicts) and together cover both the main loop and auxiliary tasks (title generation / compression; vision still has a separate gap).

Relative to this PR: this targets a different use case — Bedrock-compatible corporate proxies via ANTHROPIC_BEDROCK_BASE_URL — so it's complementary to the native-Bedrock fixes above rather than overlapping.

@RamsAI-bot

Copy link
Copy Markdown

Update — the aux vision gap noted in my comment above is now resolved by #28085's second commit (acd5de2da), verified working against real bearer-token Bedrock. So #24507 + #28085 (in full) now cover the main loop and all aux tasks — title generation, compression, and vision — under AWS_BEARER_TOKEN_BEDROCK.

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:813 omits max_retries=0. Current main deliberately disables SDK retries at agent/anthropic_adapter.py:865-867, with coverage at tests/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_request override at agent/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=0 and add branch-specific tests for the bearer header, custom URL, unset-env SigV4 behavior, and claude-* 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])},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@teknium1 teknium1 added sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have provider/bedrock AWS Bedrock (boto3, IAM) sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants