-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Closed
Description
Description
The Amazon Bedrock provider's getModel function ignores the options.region from config when determining the region prefix for model IDs. It uses a closure-captured value from AWS_REGION env var instead.
Disclaimer: This bug was discovered and analyzed using OpenCode.
Root Cause
In packages/opencode/src/provider/provider.ts, the amazon-bedrock custom loader captures the region in a closure:
"amazon-bedrock": async () => {
const awsRegion = await Env.get("AWS_REGION")
const region = awsRegion ?? "us-east-1" // captured here
return {
options: { region, ... },
async getModel(sdk: any, modelID: string, _options?: Record<string, any>) {
// Uses closure-captured `region`, ignores `_options.region`
let regionPrefix = region.split("-")[0]
// ...
},
}
}The _options parameter contains the merged provider options (including user's config options.region), but it's ignored.
Steps to Reproduce
- Configure AWS credentials via profile (without
AWS_REGIONenv var) - Set region in
opencode.json:{ "provider": { "amazon-bedrock": { "options": { "region": "eu-west-1" } } } } - Run
opencodeand select a Claude model - Expected: Model ID prefixed with
eu.based on config region - Actual: Model ID prefixed with
us.(default) becauseAWS_REGIONis unset
Workaround
Set AWS_REGION environment variable:
AWS_REGION=eu-west-1 opencodeSuggested Fix
async getModel(sdk: any, modelID: string, options?: Record<string, any>) {
const effectiveRegion = options?.region ?? region
if (modelID.startsWith("global.")) {
return sdk.languageModel(modelID)
}
let regionPrefix = effectiveRegion.split("-")[0]
// ... rest of logic using effectiveRegion instead of region
}Environment
- OpenCode version: latest
- OS: macOS
- AWS auth: SSO via profile
Metadata
Metadata
Assignees
Labels
No labels