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

Closed
opened 2026-02-16 17:41:04 -05:00 by yindo · 2 comments
Owner

Originally created by @wnkz on GitHub (Dec 19, 2025).

Originally assigned to: @rekram1-node on GitHub.

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
Originally created by @wnkz on GitHub (Dec 19, 2025). Originally assigned to: @rekram1-node on GitHub. ### 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: ```typescript "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`: ```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: ```bash AWS_REGION=eu-west-1 opencode ``` ### Suggested Fix ```typescript 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
yindo closed this issue 2026-02-16 17:41:04 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Dec 19, 2025):

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] commented on GitHub (Dec 19, 2025): 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.
Author
Owner

@rekram1-node commented on GitHub (Dec 19, 2025):

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

@rekram1-node commented on GitHub (Dec 19, 2025): @wnkz our bedrock support could definitely be better, PRs welcome!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3674