Skip to content

feat(cli): add AWS Bedrock as a supported provider#1015

Open
rutgoff wants to merge 3 commits into
Zoo-Code-Org:mainfrom
rutgoff:feat/cli-bedrock-provider
Open

feat(cli): add AWS Bedrock as a supported provider#1015
rutgoff wants to merge 3 commits into
Zoo-Code-Org:mainfrom
rutgoff:feat/cli-bedrock-provider

Conversation

@rutgoff

@rutgoff rutgoff commented Jul 25, 2026

Copy link
Copy Markdown

Related GitHub Issue

Refs: #635

Description

Adds AWS Bedrock as a supported provider in the ZooCode CLI, bringing it to parity
with the VS Code extension for the most common enterprise AWS use case.

Motivation: The CLI previously supported five providers (anthropic, openai-native,
gemini, openrouter, vercel-ai-gateway) but not Bedrock — the default choice for
enterprise AWS users. The extension's AwsBedrockHandler (src/api/providers/bedrock.ts)
already implements the full Bedrock auth stack; the CLI only needed the plumbing to
resolve credentials from the environment and populate the corresponding
RooCodeSettings fields.

How (key implementation details):

File Change
apps/cli/src/types/types.ts Added "bedrock" to the supportedProviders array
apps/cli/src/lib/utils/provider.ts Added bedrock to envVarMap and a full case "bedrock" in getProviderSettings() (region resolution, cross-region inference auto-detect, and the four auth modes)
apps/cli/src/commands/cli/run.ts Relaxed the mandatory-API-key check for Bedrock; validates that at least one credential source is available before failing
apps/cli/src/index.ts Made the --provider help text dynamic from supportedProviders instead of a hardcoded string

Authentication modes (mirrors AwsBedrockHandler):

  1. Bearer token / API key--api-key or AWS_BEDROCK_API_KEY (LiteLLM proxy / Bedrock gateway) → sets awsUseApiKey + awsApiKey.
  2. AWS ProfileAWS_PROFILE → sets awsUseProfile + awsProfile.
  3. Direct credentialsAWS_ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY (+ optional AWS_SESSION_TOKEN).
  4. Default credential chain — falls through to the AWS SDK default chain (IMDS, ECS task role, SSO, etc.).

Region resolves from AWS_REGIONAWS_DEFAULT_REGIONus-east-1. When the model ID
carries a regional inference-profile prefix (us., eu., apac.),
awsUseCrossRegionInference is enabled automatically.

Usage:

# Profile-based auth (most common for enterprise)
AWS_PROFILE=my-profile AWS_REGION=us-east-1 roo --provider bedrock "hello"

# Direct credentials
AWS_ACCESS_KEY_ID=AKIA... AWS_SECRET_ACCESS_KEY=... AWS_REGION=us-east-1 \
  roo --provider bedrock --model "us.anthropic.claude-sonnet-4-5-20250929-v1:0" "hello"

# Bearer token (LiteLLM proxy / Bedrock gateway)
AWS_BEDROCK_API_KEY=your-key roo --provider bedrock "hello"

Test Procedure

Verified locally on the CI-pinned toolchain (Node 20.20.2, pnpm 10.8.1):

  • Unit testspnpm turbo run test --filter=@roo-code/cli529 passed / 1 skipped (37 test files passed, 1 skipped).
  • Lintpnpm turbo run lint --filter=@roo-code/cli → clean (eslint src --ext .ts --max-warnings=0, 0 warnings).
  • Type-checkpnpm turbo run check-types --filter=@roo-code/cli → clean (tsc --noEmit).
  • Buildpnpm turbo run build --filter=@roo-code/cli → clean (tsup).
  • Help text--provider help now dynamically lists: API provider (anthropic, bedrock, openai-native, gemini, openrouter, vercel-ai-gateway).

To reproduce:

pnpm install
pnpm turbo run lint check-types test build --filter=@roo-code/cli

Pre-Submission Checklist

  • Issue Linked: This PR references issue CLI version? #635.
  • Scope: Changes are focused and Bedrock-only (4 files, +56/-5).
  • Self-Review: Performed a thorough self-review; no debug statements, TODOs, or secrets.
  • Testing: Feature is exercised by the existing CLI provider/type test suites (all passing); no Bedrock-specific unit test was added since the change is credential-plumbing over the already-tested AwsBedrockHandler. Happy to add targeted getProviderSettings("bedrock", …) cases if you'd like.
  • Documentation Impact: Considered (see below).
  • Contribution Guidelines: Read and followed.

Screenshots / Videos

N/A — no UI changes (CLI-only).

Documentation Updates

  • No documentation updates are strictly required for this repo. If desired, I'm happy to add a note about the bedrock provider and its four auth modes to the CLI docs / docs repository.

Additional Notes

  • No dependency changes. This PR adds no packages. Bedrock's AWS SDK dependencies live with the existing AwsBedrockHandler in the core package; the CLI's tsup externals already keep the Anthropic Bedrock SDK external. "bedrock" is already a valid ProviderName in @roo-code/types, and the default model follows bedrockDefaultModelId (anthropic.claude-sonnet-4-5-20250929-v1:0) when none is specified.
  • Changeset: intentionally omitted per our maintainer-managed changeset convention — happy to add one if you'd prefer it included.
  • Attribution: Refs #635 chosen over Closes #635 so the broader "CLI version?" tracking issue can stay open for further parity work.

Get in Touch

Discord username available on request.

(Content added by Kenzie, LLM-based artificial assistant, on behalf of Rowena Day.)

Summary by CodeRabbit

  • New Features
    • Added Amazon Bedrock as a supported CLI provider, including region/model handling, cross-region inference auto-enable, and credential configuration (API key, profile, or direct AWS credentials).
    • Updated the --provider option to display a dynamically generated list of supported providers.
  • Bug Fixes
    • Made API-key validation provider-aware to avoid an early hard-fail for Bedrock when apiKey is not provided.
  • Tests
    • Expanded provider utility tests for Bedrock environment variables, authentication/credential priority rules, and region/cross-region inference behavior.

Add Bedrock to the CLI's supported providers with full AWS authentication
stack support:

- Bearer token / API key (AWS_BEDROCK_API_KEY or --api-key)
- AWS Profile (AWS_PROFILE env var)
- Direct credentials (AWS_ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY)
- Default credential chain fallthrough (IMDS, ECS task role, etc.)

Also makes the --provider help text dynamically list all supported
providers from the supportedProviders array instead of a hardcoded string.

The existing AwsBedrockHandler in src/api/providers/bedrock.ts already
handles all auth modes — the CLI just needed to populate the RooCodeSettings
fields correctly and relax the API key requirement for Bedrock (which can
auth without an explicit key).

*(Content added by Kenzie, LLM-based artificial assistant, on behalf of Rowena Day.)*
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0cb3882f-b507-4e46-a8ea-1406418c9fdf

📥 Commits

Reviewing files that changed from the base of the PR and between 63aa435 and 226281b.

📒 Files selected for processing (1)
  • apps/cli/src/lib/utils/__tests__/provider.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/cli/src/lib/utils/tests/provider.test.ts

📝 Walkthrough

Walkthrough

The CLI adds Bedrock as a supported provider, configures AWS region, model, inference, and credential settings, validates Bedrock credentials separately, and derives provider help text from the supported provider list.

Changes

Bedrock CLI Support

Layer / File(s) Summary
Bedrock provider configuration
apps/cli/src/types/types.ts, apps/cli/src/lib/utils/provider.ts, apps/cli/src/lib/utils/__tests__/provider.test.ts
Adds Bedrock to supported providers and configures and tests AWS region, model, cross-region inference, API-key, profile, direct credential, and default credential-chain handling.
CLI provider validation and help
apps/cli/src/index.ts, apps/cli/src/commands/cli/run.ts
Generates provider help text dynamically and skips the upfront API-key failure for Bedrock while retaining it for other providers.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant CLI
  participant getProviderSettings
  participant AWSSDKCredentialChain
  User->>CLI: Select bedrock provider
  CLI->>getProviderSettings: Build Bedrock configuration
  getProviderSettings->>AWSSDKCredentialChain: Resolve API key, profile, direct credentials, or default chain
  AWSSDKCredentialChain-->>getProviderSettings: Credential configuration
  getProviderSettings-->>CLI: Return region, model, inference, and credentials
Loading

Possibly related issues

  • #124: Adds related Bedrock provider settings, although that issue focuses on model discovery and runtime limits rather than CLI authentication.

Suggested labels: awaiting-review

Suggested reviewers: edelauna

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main change: adding AWS Bedrock support to the CLI.
Description check ✅ Passed It includes the issue reference, implementation summary, test procedure, checklist, and docs notes required by the template.
Linked Issues check ✅ Passed The PR delivers a relevant CLI slice of the linked issue by adding Bedrock support and related credential plumbing for outside-VSCode use.
Out of Scope Changes check ✅ Passed All code changes are in scope for Bedrock provider support, help text updates, and accompanying tests.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
apps/cli/src/commands/cli/run.ts 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/cli/src/commands/cli/run.ts`:
- Around line 198-204: Remove the environment-only credential rejection in the
Bedrock preflight block guarded by !hasProfile && !hasDirectCreds. Allow
execution to continue so the downstream AWS credential resolver can use the
default credential chain, including IMDS, ECS task roles, IRSA, and
shared-profile defaults, and report failures only when resolution actually
fails.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 38fc5bee-2b83-4d28-87dd-099002397947

📥 Commits

Reviewing files that changed from the base of the PR and between d1f3999 and d07729f.

📒 Files selected for processing (4)
  • apps/cli/src/commands/cli/run.ts
  • apps/cli/src/index.ts
  • apps/cli/src/lib/utils/provider.ts
  • apps/cli/src/types/types.ts

Comment thread apps/cli/src/commands/cli/run.ts Outdated
Address PR Zoo-Code-Org#1015 review feedback.

FIX 1 (CodeRabbit): the Bedrock branch in run.ts previously hard-failed with process.exit(1) when neither AWS_PROFILE nor static AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY were set. That rejected the AWS SDK default credential chain (IMDS / EC2 instance profile, ECS task role, IRSA/web-identity, SSO, shared-config default) before the resolver ever ran, defeating advertised auth mode Zoo-Code-Org#4. Extract a providerRequiresApiKey() helper (false for bedrock, true otherwise) and gate the API-key requirement on it, so Bedrock proceeds and AwsBedrockHandler surfaces a real error only if credential resolution actually fails. Non-bedrock providers keep the identical missing-API-key error and exit.

FIX 2 (codecov): add hermetic vitest coverage for getProviderSettings bedrock path (all 4 auth modes, priority ordering, region resolution, cross-region inference auto-enable) and providerRequiresApiKey. provider.test.ts goes from 4 to 27 tests.

Also add JSDoc to providerRequiresApiKey and getProviderSettings describing the four Bedrock auth modes.

*(Content added by Kenzie, LLM-based artificial assistant, on behalf of Rowena Day.)*

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
apps/cli/src/lib/utils/__tests__/provider.test.ts (1)

5-13: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover AWS_BEDROCK_API_KEY retrieval.

The new environment variable is cleared but never exercised. Add a getApiKeyFromEnv("bedrock") case after setting AWS_BEDROCK_API_KEY, so the advertised environment-based API-key path cannot regress unnoticed.

Proposed test
+	it("should return API key from environment variable for bedrock", () => {
+		process.env.AWS_BEDROCK_API_KEY = "test-bedrock-key"
+		expect(getApiKeyFromEnv("bedrock")).toBe("test-bedrock-key")
+	})

As per coding guidelines, use package-local unit tests for pure logic, parsing, state transitions, validation, serialization, request construction, retry decisions, and error handling.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/cli/src/lib/utils/__tests__/provider.test.ts` around lines 5 - 13, Add
coverage in the provider environment-variable tests for AWS_BEDROCK_API_KEY: set
the variable, call getApiKeyFromEnv("bedrock"), and assert the returned key,
placing this case after the variable is configured while preserving the existing
cleanup behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@apps/cli/src/lib/utils/__tests__/provider.test.ts`:
- Around line 5-13: Add coverage in the provider environment-variable tests for
AWS_BEDROCK_API_KEY: set the variable, call getApiKeyFromEnv("bedrock"), and
assert the returned key, placing this case after the variable is configured
while preserving the existing cleanup behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 90b582e8-73b2-498a-b5cb-6b9259a28f46

📥 Commits

Reviewing files that changed from the base of the PR and between d07729f and 63aa435.

📒 Files selected for processing (3)
  • apps/cli/src/commands/cli/run.ts
  • apps/cli/src/lib/utils/__tests__/provider.test.ts
  • apps/cli/src/lib/utils/provider.ts

@rutgoff

rutgoff commented Jul 25, 2026

Copy link
Copy Markdown
Author

Both points addressed:

AWS default credential chain (Major). Fixed in 63aa4356b by removing that env-cred gate for Bedrock and introducing a small providerRequiresApiKey() helper, so Bedrock now proceeds and lets AwsBedrockHandler resolve credentials via the AWS SDK default chain — surfacing an error only if resolution actually fails. The other three auth modes (bearer/API key, AWS_PROFILE, direct access keys) are unchanged, and non-Bedrock providers keep their existing missing-API-key behavior.

Patch coverage. Added hermetic unit tests for the Bedrock getProviderSettings path, all four auth modes plus priority ordering, region resolution, and cross-region-inference auto-enable for us./eu./apac. model prefixes; and a getApiKeyFromEnv("bedrock") case per the follow-up nitpick.

(Content added by Kenzie, LLM-based artificial assistant, on behalf of Rowena Day.)

@rutgoff rutgoff mentioned this pull request Jul 25, 2026
@github-actions github-actions Bot added the awaiting-review PR changes are ready and waiting for maintainer re-review label Jul 25, 2026

@edelauna edelauna 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 the contribution, happy to review - however we've never "Released" the cli under zoo, and there's been some debate as to whether to just remove this package. Curious what your use case with the cli is.

I was kind of thinking eventually this package might get refactored into some kind of background daemon to support the vs-code extension vs as an interactive TUI

// Auto-enable cross-region inference when model ID has a regional prefix
// (e.g. "us.", "eu.", "apac.") — these are cross-region inference profiles
// that require awsUseCrossRegionInference to be set.
if (/^(us|eu|apac)\./.test(model)) {

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.

This regex only covers us., eu., and apac. prefixes, but AWS_INFERENCE_PROFILE_MAPPING in packages/types/src/providers/bedrock.ts defines 8 prefixes: au., jp., ug., us., eu., apac., ca., sa.. A model like au.anthropic.claude-3-5-sonnet-20241022-v2:0 will silently get awsUseCrossRegionInference = false, causing a ResourceNotFoundException with no indication of why.

Would it make sense to derive this from the existing mapping rather than maintaining a parallel regex?

Suggested change
if (/^(us|eu|apac)\./.test(model)) {
if (AWS_INFERENCE_PROFILE_MAPPING.some(([, prefix]) => model.startsWith(prefix))) {

config.awsSessionToken = process.env.AWS_SESSION_TOKEN
}
}
// else: fall through to default credential chain (SDK handles IMDS, ECS task role, etc.)

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.

If a user switches auth modes between CLI runs — e.g. from AWS_PROFILE in run 1 to direct AWS_ACCESS_KEY_ID credentials in run 2 — awsUseProfile=true can persist in ~/.vscode-mock/global-storage/global-state.json from run 1. The Bedrock handler checks awsUseProfile before awsAccessKey (bedrock.ts line 282), so run 2 silently authenticates with the stale profile instead of the new direct credentials.

Would explicitly clearing the non-winning flags fix this?

// environment variables, so we must not hard-fail here — we let execution
// continue and allow the downstream AwsBedrockHandler to resolve credentials and
// surface a real error only if resolution actually fails.
if (!extensionHostOptions.apiKey && providerRequiresApiKey(extensionHostOptions.provider)) {

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.

Is there a test covering this new branch? run.test.ts currently only tests --prompt-file file I/O — nothing exercises the providerRequiresApiKey gate. It would be good to confirm that (a) a non-Bedrock provider without an API key still exits with 1, and (b) a Bedrock provider without any key or AWS env vars proceeds past this point.

expect(getApiKeyFromEnv("openai-native")).toBe("test-openai-key")
})

it("should return API key from environment variable for bedrock", () => {

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.

Minor hermiticity note: the getApiKeyFromEnv describe block (above this test) only does process.env = { ...originalEnv } without scrubbing AWS keys — so on a machine with AWS_BEDROCK_API_KEY exported in the shell, future "returns undefined" assertions for bedrock could be non-deterministic. The getProviderSettings block below correctly scrubs AWS_ENV_KEYS in its beforeEach; worth applying the same pattern here.

expect(config.awsUseApiKey).toBe(true)
expect(config.awsApiKey).toBe("bearer-token-123")
// API-key mode must not enable profile or direct-credential fields.
expect(config.awsUseProfile).toBeUndefined()

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.

These suppression assertions use .toBeUndefined(), which passes whether the key is absent from the object or explicitly set to undefined — both look the same in JS. A mutation that writes config.awsUseProfile = undefined instead of leaving the key unset would pass all of these.

expect(config).not.toHaveProperty('awsUseProfile') asserts the key is genuinely absent.

@rutgoff

rutgoff commented Jul 26, 2026

Copy link
Copy Markdown
Author

Thanks for the contribution, happy to review - however we've never "Released" the cli under zoo, and there's been some debate as to whether to just remove this package. Curious what your use case with the cli is.

I was kind of thinking eventually this package might get refactored into some kind of background daemon to support the vs-code extension vs as an interactive TUI

@edelauna my use case is a shell script calling the CLI to replicate the /loop behavior of other harnesses (Claude Code, etc) for doing repeat LLM tasks (scheduled summarization, data analysis of changing datasets, etc). This does fit well with "some kind of background daemon" and I'd love for the VS-Code plugin to have the functionality I'm using this for. The CLI already works mind you, I was primarily adding my needed model provider access method (AWS Bedrock API key).

@github-actions github-actions Bot added awaiting-author PR is waiting for the author to address requested changes and removed awaiting-review PR changes are ready and waiting for maintainer re-review labels Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-author PR is waiting for the author to address requested changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants