Skip to content

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

@wnkz

Description

@wnkz

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions