Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/opencode/src/cli/cmd/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ export const ProvidersLoginCommand = effectCmd({
"Amazon Bedrock authentication priority:\n" +
" 1. Bearer token (AWS_BEARER_TOKEN_BEDROCK or /connect)\n" +
" 2. AWS credential chain (profile, access keys, IAM roles, EKS IRSA)\n\n" +
"Configure via opencode.json options (profile, region, endpoint) or\n" +
"Configure via opencode.json options (profile, region, endpoint), the /connect region prompt, or\n" +
"AWS environment variables (AWS_PROFILE, AWS_REGION, AWS_ACCESS_KEY_ID, AWS_WEB_IDENTITY_TOKEN_FILE).",
)
}
Expand Down
28 changes: 28 additions & 0 deletions packages/opencode/src/plugin/amazon-bedrock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { Hooks, PluginInput } from "@opencode-ai/plugin"

export async function AmazonBedrockAuthPlugin(_input: PluginInput): Promise<Hooks> {
const prompts = !process.env.AWS_REGION
? [
{
type: "text" as const,
key: "region",
message: "Enter your AWS region for Bedrock",
placeholder: "e.g. us-east-1",
validate: (value: string) => (value.length > 0 ? undefined : "Required"),
},
]
: []

return {
auth: {
provider: "amazon-bedrock",
methods: [
{
type: "api",
label: "Bedrock API key",
prompts,
},
],
},
}
}
2 changes: 2 additions & 0 deletions packages/opencode/src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { CopilotAuthPlugin } from "./github-copilot/copilot"
import { gitlabAuthPlugin as GitlabAuthPlugin } from "opencode-gitlab-auth"
import { PoeAuthPlugin } from "opencode-poe-auth"
import { CloudflareAIGatewayAuthPlugin, CloudflareWorkersAuthPlugin } from "./cloudflare"
import { AmazonBedrockAuthPlugin } from "./amazon-bedrock"
import { AzureAuthPlugin } from "./azure"
import { DigitalOceanAuthPlugin } from "./digitalocean"
import { XaiAuthPlugin } from "./xai"
Expand Down Expand Up @@ -72,6 +73,7 @@ function internalPlugins(flags: RuntimeFlags.Info): PluginInstance[] {
CopilotAuthPlugin,
GitlabAuthPlugin,
PoeAuthPlugin,
AmazonBedrockAuthPlugin,
CloudflareWorkersAuthPlugin,
CloudflareAIGatewayAuthPlugin,
AzureAuthPlugin,
Expand Down
5 changes: 3 additions & 2 deletions packages/opencode/src/provider/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,11 @@ function custom(dep: CustomDep): Record<string, CustomLoader> {
const auth = yield* dep.auth("amazon-bedrock")
const env = yield* dep.env()

// Region precedence: 1) config file, 2) env var, 3) default
// Region precedence: 1) config file, 2) env var, 3) /connect metadata, 4) default
const configRegion = providerConfig?.options?.region
const envRegion = env["AWS_REGION"]
const defaultRegion = configRegion ?? envRegion ?? "us-east-1"
const authRegion = auth?.type === "api" ? auth.metadata?.region : undefined
const defaultRegion = configRegion ?? envRegion ?? authRegion ?? "us-east-1"

// Profile: config file takes precedence over env var
const configProfile = providerConfig?.options?.profile
Expand Down
11 changes: 11 additions & 0 deletions packages/opencode/test/provider/amazon-bedrock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ it.instance("Bedrock: falls back to AWS_REGION env var when no config region", (
}),
)

it.instance("Bedrock: falls back to region stored by connect prompt", () =>
Effect.gen(function* () {
yield* withAuthJson(
JSON.stringify({ "amazon-bedrock": { type: "api", key: "test-bearer-token", metadata: { region: "eu-west-1" } } }),
)
const providers = yield* list
expect(providers[ProviderV2.ID.amazonBedrock]).toBeDefined()
expect(providers[ProviderV2.ID.amazonBedrock].options?.region).toBe("eu-west-1")
}),
)

it.instance(
"Bedrock: loads when bearer token from auth.json is present",
() =>
Expand Down
10 changes: 6 additions & 4 deletions packages/web/src/content/docs/providers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,19 @@ To use Amazon Bedrock with OpenCode:

#### Environment Variables (Quick Start)

Set one of these environment variables while running opencode:
If you use `/connect` or `opencode auth login amazon-bedrock`, OpenCode
prompts for your Bedrock API key and region. You can also set credentials
with environment variables. Bedrock needs a region, set with `AWS_REGION`:

```bash
# Option 1: Using AWS access keys
AWS_ACCESS_KEY_ID=XXX AWS_SECRET_ACCESS_KEY=YYY opencode
AWS_REGION=us-east-1 AWS_ACCESS_KEY_ID=XXX AWS_SECRET_ACCESS_KEY=YYY opencode

# Option 2: Using named AWS profile
AWS_PROFILE=my-profile opencode
AWS_REGION=us-east-1 AWS_PROFILE=my-profile opencode

# Option 3: Using Bedrock bearer token
AWS_BEARER_TOKEN_BEDROCK=XXX opencode
AWS_REGION=us-east-1 AWS_BEARER_TOKEN_BEDROCK=XXX opencode
```

Or add them to your bash profile:
Expand Down
Loading