opencode icon indicating copy to clipboard operation
opencode copied to clipboard

[BUG] Bedrock provider: config options.region ignored for model ID prefixing

Open wnkz opened this issue 3 weeks ago • 2 comments

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

  1. Configure AWS credentials via profile (without AWS_REGION env var)
  2. Set region in opencode.json:
    {
      "provider": {
        "amazon-bedrock": {
          "options": {
            "region": "eu-west-1"
          }
        }
      }
    }
    
  3. Run opencode and select a Claude model
  4. Expected: Model ID prefixed with eu. based on config region
  5. Actual: Model ID prefixed with us. (default) because AWS_REGION is 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

wnkz avatar Dec 19 '25 22:12 wnkz

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.

github-actions[bot] avatar Dec 19 '25 22:12 github-actions[bot]

@wnkz our bedrock support could definitely be better, PRs welcome!

rekram1-node avatar Dec 19 '25 22:12 rekram1-node