Skip to content

feat: add Amazon Bedrock as alternative AI provider (AI_PROVIDER flag)#20

Open
tobigs wants to merge 4 commits intoserithemage:mainfrom
tobigs:pr/bedrock-api
Open

feat: add Amazon Bedrock as alternative AI provider (AI_PROVIDER flag)#20
tobigs wants to merge 4 commits intoserithemage:mainfrom
tobigs:pr/bedrock-api

Conversation

@tobigs
Copy link
Copy Markdown

@tobigs tobigs commented Mar 26, 2026

Summary

Adds AI_PROVIDER environment variable (anthropic | bedrock, default anthropic) enabling Amazon Bedrock as an alternative AI backend — no API key required, uses IAM role credentials.

Changes

Shared

  • New packages/shared/src/provider-config.tsresolveProviderConfig() validates and defaults provider/model, resolveBedrockModel() derives the correct Bedrock CRIS model ID from AWS_REGION (eu/us/apac geographic prefixes)

Lambda path (packages/lambda-agent/)

  • config-init.ts: conditional SSM skip, disable bedrockDiscovery (model selection is explicit), parameterised provider/api/model
  • agent-runner.ts: wire provider config into the agent
  • handler.ts: pass AI_PROVIDER and AI_MODEL from env

Fargate path (packages/container/)

  • patch-config.ts: inject Bedrock LLM config, disable discovery, add AWS_PROFILE workaround

CDK (packages/cdk/)

  • secrets-stack.ts: skip AnthropicApiKey SSM param when AI_PROVIDER=bedrock
  • compute-stack.ts, lambda-agent-stack.ts: provision bedrock:InvokeModel IAM permissions (always, to avoid drift on switch)
  • .env.example: document AI_PROVIDER and AI_MODEL

Docs & tests — 27 new unit tests for resolveProviderConfig and resolveBedrockModel; docs/deployment.md §10 AI Provider Configuration guide; CLAUDE.md updated.

Test plan

  • Unit tests: all pass (including 27 new provider-config tests)
  • E2E CDK synth pass
# Bedrock — AnthropicApiKey param should be absent
AI_PROVIDER=bedrock npx cdk synth 2>&1 | grep -i "anthropic"
# Expected: no AnthropicApiKey output

# Anthropic (default) — key should be present
npx cdk synth 2>&1 | grep -i "anthropic"
npx vitest run packages/container/__tests__/patch-config.test.ts
npx vitest run packages/lambda-agent/__tests__/config-init.test.ts
npx vitest run packages/shared/__tests__/provider-config.test.ts

🤖 Generated with Claude Code

Tobias and others added 4 commits March 26, 2026 18:04
Add environment-variable-driven provider selection (AI_PROVIDER, AI_MODEL)
enabling Bedrock's bedrock-converse-stream API via IAM role credentials.

- Add shared provider-config module with validation and defaults
- Lambda path: conditional SSM skip, Bedrock discovery, parameterized provider/api/model
- Fargate path: Bedrock LLM config, discovery, AWS_PROFILE workaround
- CDK: Bedrock IAM permissions (always provisioned), conditional Anthropic secret
- Document AI_PROVIDER and AI_MODEL in .env.example
…very

- resolveBedrockModel() derives CRIS prefix from AWS_REGION at runtime:
  eu-* → eu., us-*/ca-* → us., ap-* → apac., unknown → no prefix
- bedrockDiscovery always disabled in Lambda config init — model
  selection is explicit; dynamic discovery caused wrong provider path
  errors (anthropic/ prefix on Bedrock CRIS profile IDs)
- 27 new unit tests covering resolveCrisPrefix, resolveBedrockModel,
  resolveProviderConfig for all region groups and AI_MODEL override
- docs: deployment.md + CLAUDE.md updated to reflect CRIS resolution

Fixes: Unknown model: anthropic/eu.anthropic.claude-sonnet-4-20250514-v1:0

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…el.primary

OpenClaw v2026.2.13 does not have a top-level 'llm' key. Set the model
via agents.defaults.model.primary in provider/model format, delete any
legacy llm section, and disable bedrockDiscovery to avoid ~56s startup scan.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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