Skip to content

feat: AWS Bedrock provider adapter - #203

Open
NahumKorda wants to merge 2 commits into
knostic:masterfrom
NahumKorda:feat/bedrock-adapter
Open

feat: AWS Bedrock provider adapter#203
NahumKorda wants to merge 2 commits into
knostic:masterfrom
NahumKorda:feat/bedrock-adapter

Conversation

@NahumKorda

Copy link
Copy Markdown
Contributor

Adds bedrock as a first-class provider type — Claude on AWS Bedrock — per the roadmap's "More provider adapters" item; related to #9 and the pricing-accounting invariants of #65.

Design

The registry constructs every adapter as adapter_cls(api_key=..., base_url=...), and ProviderConfig deliberately has no other fields. Rather than widening that surface for one provider, BedrockAdapter keeps the two-kwarg constructor and delegates credentials and region entirely to the AWS SDK chain (AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY env vars, ~/.aws profiles, AWS_REGION) via anthropic.AnthropicBedrock — so openant authenticates exactly like the aws CLI on the same machine, and the diff stays Python-only (no Go or config-schema changes). api_key is accepted-and-ignored with a one-time warning, since Bedrock has no API-key auth in the pinned SDK.

The wire format is Anthropic's, so the adapter reuses the Anthropic adapter's translation helpers; anthropic.py's shared warnings take an adapter= name so reused code attributes messages correctly.

Bedrock-specific behavior

  • Model IDs are inference profiles (us.anthropic.claude-sonnet-4-6, global.anthropic.claude-haiku-4-5-20251001-v1:0, ...), passed through verbatim; IDs and pricing records in config/models.json were verified against a live Bedrock account via list-inference-profiles (us-east-1), not derived from naming conventions — the -v1:0 suffix is not uniform across profiles.
  • AccessDenied 403 → LLMAuthError with a "Model access" hint (the most common first-run failure: the model isn't enabled in the Bedrock console).
  • 400 ValidationException "model identifier is invalid" → LLMNotFoundError (Bedrock does not 404 unknown models), so the registry's init-time validate() reports a typo'd profile as such.
  • The SDK's bare RuntimeError("could not resolve credentials...") from the SigV4 signer → LLMAuthError with a pointer at the env vars; unrelated RuntimeErrors still propagate.
  • Throttling 429s report to the process-global RateLimiter, same as the reference adapters.

Testing

  • Contract harness row + 15 Bedrock-specific tests, all SDK-boundary-mocked. Full core suite passes (2 pre-existing Zig parser failures unrelated to this change, present on clean master).
  • Live-validated against a real Bedrock account: validate() and text completions on us.anthropic.claude-sonnet-4-6 and global.anthropic.claude-haiku-4-5-20251001-v1:0.

Notes for reviewers

  • Go wizard support (openant setup llm) is intentionally out of scope per the "optional" checklist item; the README documents hand-authored config for now.
  • The README's link to docs/features/llm-providers/HOW_TO_ADD_AN_ADAPTER.md is dead in the current tree (the file doesn't exist); left as-is here since it predates this PR, but happy to fix it in this PR if you'd like.

🤖 Generated with Claude Code

Add a `bedrock` provider type that runs OpenAnt scans against Claude
models on AWS Bedrock with native AWS credentials — no proxy needed.
Bedrock is on the README roadmap ("More provider adapters"); this
implements it Python-only, with no config-schema or Go CLI changes.

Design: the registry constructs every adapter as
`cls(api_key=..., base_url=...)`, and AWS needs SigV4 credentials plus
a region, which don't fit that signature. Rather than widening
ProviderConfig (and touching Go config parsing), BedrockAdapter keeps
the same constructor shape and delegates credentials and region to the
SDK's standard AWS chain (AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY env
vars or ~/.aws profile; AWS_REGION env, then boto3 session). `api_key`
is ignored with a one-time warning; `base_url` still works as a full
endpoint override (VPC endpoints, gateways).

Bedrock speaks the same Messages API through the same `anthropic` SDK
types (`anthropic.AnthropicBedrock`), so the adapter reuses the
Anthropic adapter's translation layer — blocks, stop reasons, and the
refusal -> LLMRefusalError guard — parameterizing only the warning
attribution. Bedrock-specific deltas:

- 403 AccessDenied -> LLMAuthError with a Bedrock "Model access" hint
  (the usual cause is a model not enabled for the account/region)
- 400 "model identifier is invalid" -> LLMNotFoundError (Bedrock
  reports bad model IDs as ValidationException, not 404)
- SDK's bare no-credentials RuntimeError -> LLMAuthError
- throttling 429s report to the global RateLimiter like the reference
  adapter; the 529 branch is kept harmless for Anthropic-compat
  gateways behind base_url

Model IDs are cross-region inference profiles. config/models.json
gains six bedrock records (us./global. families for opus-4-8,
sonnet-4-6, haiku-4-5) with IDs verified against a live Bedrock
account via list-inference-profiles; prices mirror the direct
Anthropic API records. Note opus-4-8 and sonnet-4-6 profiles carry no
-v1:0 suffix.

Tests: bedrock row in the contract-test ADAPTERS fixture with a
scenario factory stubbing AnthropicBedrock, plus 15 Bedrock-specific
tests (constructor plumbing, verbatim profile IDs, error mapping,
rate-limiter coordination). Live-validated: messages.create round-trip
confirmed against us.anthropic.claude-sonnet-4-6 and
global.anthropic.claude-haiku-4-5-20251001-v1:0 in us-east-1.

Go wizard support (setup.go) is deliberately out of scope; a
hand-authored config works, as the README documents.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Adds utilities/llm/providers/BEDROCK.md — prerequisites (model access
+ minimal IAM policy), the credential/region resolution chain, full
config.json example, the inference-profile ID conventions and their
suffix inconsistency, cost accounting, an error/troubleshooting
table, and current limitations — and links it from the README's
shipped-adapters table.

Placed next to the adapter code (the repo convention, cf. the parser
PARSER_PIPELINE.md files) because docs/ is gitignored.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@NahumKorda

Copy link
Copy Markdown
Contributor Author

Added a detailed usage guide in 733d628: utilities/llm/providers/BEDROCK.md — prerequisites (model access + minimal IAM policy), credential/region resolution, a full config.json example, inference-profile ID conventions, cost accounting, and a troubleshooting table. Placed next to the adapter code rather than under docs/, since docs/ is gitignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant