[BUG] Bedrock provider: config options.region ignored for model ID prefixing
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 opencode
Suggested 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
This issue might be a duplicate of or related to existing issues. Please check:
- #4260: [FEATURE]: Support an Opencode-specific AWS profile - Requests region configuration per Bedrock provider specifically
- #2446: AWS Bedrock Provider doesn't seem to respect proxy - Related to provider options not being respected (baseURL specifically)
- #5674: Custom OpenAI-compatible provider options not being passed to API calls - Similar issue where provider options are not being passed to API
- #971: Model options are not forwarded for openai-compatible providers unless provider.name option is given - Root cause analysis of options not being forwarded
This appears to be a provider-level issue where configuration options are not being properly used/merged in the provider implementation.
Feel free to ignore if these don't address your specific case.
@wnkz our bedrock support could definitely be better, PRs welcome!