Skip to content

Commit d07729f

Browse files
committed
feat(cli): add AWS Bedrock as a supported provider
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.)*
1 parent d1f3999 commit d07729f

4 files changed

Lines changed: 56 additions & 5 deletions

File tree

apps/cli/src/commands/cli/run.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,28 @@ export async function run(promptArg: string | undefined, flagOptions: FlagOption
190190
extensionHostOptions.apiKey = flagOptions.apiKey || getApiKeyFromEnv(extensionHostOptions.provider)
191191

192192
if (!extensionHostOptions.apiKey) {
193-
console.error(`[CLI] Error: No API key provided. Use --api-key or set the appropriate environment variable.`)
194-
console.error(`[CLI] For ${extensionHostOptions.provider}, set ${getEnvVarName(extensionHostOptions.provider)}`)
195-
196-
process.exit(1)
193+
if (extensionHostOptions.provider === "bedrock") {
194+
// Bedrock can authenticate via AWS credential chain without an explicit API key.
195+
// Validate that at least one credential source is available.
196+
const hasProfile = !!process.env.AWS_PROFILE
197+
const hasDirectCreds = !!(process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY)
198+
if (!hasProfile && !hasDirectCreds) {
199+
console.error(`[CLI] Error: No credentials found for Bedrock. Provide one of:`)
200+
console.error(` --api-key or AWS_BEDROCK_API_KEY (bearer token / API key mode)`)
201+
console.error(` AWS_PROFILE (profile-based auth)`)
202+
console.error(` AWS_ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY (direct credentials)`)
203+
console.error(` Or ensure a default credential chain is available (IMDS, ECS task role, etc.)`)
204+
process.exit(1)
205+
}
206+
} else {
207+
console.error(
208+
`[CLI] Error: No API key provided. Use --api-key or set the appropriate environment variable.`,
209+
)
210+
console.error(
211+
`[CLI] For ${extensionHostOptions.provider}, set ${getEnvVarName(extensionHostOptions.provider)}`,
212+
)
213+
process.exit(1)
214+
}
197215
}
198216

199217
if (!fs.existsSync(extensionHostOptions.workspacePath)) {

apps/cli/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Command } from "commander"
22

33
import { DEFAULT_FLAGS } from "@/types/constants.js"
4+
import { supportedProviders } from "@/types/index.js"
45
import { VERSION } from "@/lib/utils/version.js"
56
import { run, logout, status, listCommands, listModes, listModels, listSessions, upgrade } from "@/commands/index.js"
67

@@ -35,7 +36,7 @@ program
3536
.option("-d, --debug", "Enable debug output (includes detailed debug information)", false)
3637
.option("-a, --require-approval", "Require manual approval for actions", false)
3738
.option("-k, --api-key <key>", "API key for the LLM provider")
38-
.option("--provider <provider>", "API provider (anthropic, openai-native, gemini, openrouter, etc.)")
39+
.option("--provider <provider>", `API provider (${supportedProviders.join(", ")})`)
3940
.option("-m, --model <model>", "Model to use", DEFAULT_FLAGS.model)
4041
.option("--mode <mode>", "Mode to start in (code, architect, ask, debug, etc.)", DEFAULT_FLAGS.mode)
4142
.option("--terminal-shell <path>", "Absolute path to shell executable for inline terminal commands")

apps/cli/src/lib/utils/provider.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { SupportedProvider } from "@/types/index.js"
44

55
const envVarMap: Record<SupportedProvider, string> = {
66
anthropic: "ANTHROPIC_API_KEY",
7+
bedrock: "AWS_BEDROCK_API_KEY",
78
"openai-native": "OPENAI_API_KEY",
89
gemini: "GOOGLE_API_KEY",
910
openrouter: "OPENROUTER_API_KEY",
@@ -31,6 +32,36 @@ export function getProviderSettings(
3132
if (apiKey) config.apiKey = apiKey
3233
if (model) config.apiModelId = model
3334
break
35+
case "bedrock":
36+
config.awsRegion = process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION || "us-east-1"
37+
if (model) {
38+
config.apiModelId = model
39+
// Auto-enable cross-region inference when model ID has a regional prefix
40+
// (e.g. "us.", "eu.", "apac.") — these are cross-region inference profiles
41+
// that require awsUseCrossRegionInference to be set.
42+
if (/^(us|eu|apac)\./.test(model)) {
43+
config.awsUseCrossRegionInference = true
44+
}
45+
}
46+
47+
if (apiKey) {
48+
// Bearer token / API key mode (LiteLLM proxy, Bedrock gateway)
49+
config.awsUseApiKey = true
50+
config.awsApiKey = apiKey
51+
} else if (process.env.AWS_PROFILE) {
52+
// Profile-based auth
53+
config.awsUseProfile = true
54+
config.awsProfile = process.env.AWS_PROFILE
55+
} else if (process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY) {
56+
// Direct credentials from env
57+
config.awsAccessKey = process.env.AWS_ACCESS_KEY_ID
58+
config.awsSecretKey = process.env.AWS_SECRET_ACCESS_KEY
59+
if (process.env.AWS_SESSION_TOKEN) {
60+
config.awsSessionToken = process.env.AWS_SESSION_TOKEN
61+
}
62+
}
63+
// else: fall through to default credential chain (SDK handles IMDS, ECS task role, etc.)
64+
break
3465
case "openai-native":
3566
if (apiKey) config.openAiNativeApiKey = apiKey
3667
if (model) config.apiModelId = model

apps/cli/src/types/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { OutputFormat } from "./json-events.js"
33

44
export const supportedProviders = [
55
"anthropic",
6+
"bedrock",
67
"openai-native",
78
"gemini",
89
"openrouter",

0 commit comments

Comments
 (0)