issues providing bedrock auth
I have been having issues setting up opencode to use bedrock... I have set the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as env variables preloaded in the session by my .zshrc ... this didn't work so i tried to create a profile in ~/.aws/config and the same error occurs. I cannot get opencode to pick up these credentials and properly authenticate me with bedrock, but I hope im doing something stupid. Any tips for what I'm missing...?
To get OpenCode working with AWS Bedrock, I had to explicitly set these environment variables — OpenCode expects them to be present:
# AWS Bedrock setup for OpenCode
alias opencode-bedrock='AWS_PROFILE=default AWS_REGION=us-east-1 opencode'
Note: my AWS credentials were already configured via the AWS CLI, but OpenCode still requires these to be set explicitly for the auth flow to work.
Reference: https://github.com/sst/opencode/blob/67480e5a1c71a0b65467a724a7b7afa828f93168/packages/opencode/src/cli/cmd/auth.ts#L130
i pushed a fix for this yesterday - can you try again
+1 on not being able to get bedrock working. I'll clone and get this running locally tomorrow to debug. Our setup:
- AWS SSO with AWS_PROFILE set
- Tried with and without AWS_REGION - we use us-east-1 for everything
Tried some custom opencode.json setups from issues here, no luck. OpenAI "just works" with a key in .env
❯ opencode run hey --print-logs
INFO 2025-07-01T21:09:02 +35ms service=default version=0.1.173 args=run,hey,--print-logs opencode
INFO 2025-07-01T21:09:02 +0ms service=app cwd=/<path> creating
INFO 2025-07-01T21:09:02 +3ms service=app git=/<path> git
INFO 2025-07-01T21:09:02 +1ms service=bus type=storage.write subscribing
INFO 2025-07-01T21:09:02 +0ms service=app name=bus registering service
INFO 2025-07-01T21:09:02 +0ms service=format init
INFO 2025-07-01T21:09:02 +0ms service=bus type=file.edited subscribing
INFO 2025-07-01T21:09:02 +0ms service=config.hooks init
INFO 2025-07-01T21:09:02 +0ms service=bus type=file.edited subscribing
INFO 2025-07-01T21:09:02 +0ms service=bus type=session.idle subscribing
INFO 2025-07-01T21:09:02 +0ms service=app name=lsp registering service
INFO 2025-07-01T21:09:02 +1ms service=lsp initializing
INFO 2025-07-01T21:09:02 +1ms service=app name=file.watcher registering service
INFO 2025-07-01T21:09:02 +4ms service=session id=ses_8382d9fa1ffeWroAGhqIbKVeun version=0.1.173 title=New Session - 2025-07-01T21:09:02.687Z time=[object Object] created
INFO 2025-07-01T21:09:02 +0ms service=app name=session registering service
INFO 2025-07-01T21:09:02 +0ms service=app name=storage registering service
INFO 2025-07-01T21:09:02 +0ms service=storage path=/<path> init
INFO 2025-07-01T21:09:02 +4ms service=bus type=storage.write publishing
INFO 2025-07-01T21:09:02 +0ms service=app name=config registering service
INFO 2025-07-01T21:09:02 +1ms service=config loaded
INFO 2025-07-01T21:09:02 +0ms service=bus type=session.updated publishing
█▀▀█ █▀▀█ █▀▀ █▀▀▄ █▀▀ █▀▀█ █▀▀▄ █▀▀
█░░█ █░░█ █▀▀ █░░█ █░░ █░░█ █░░█ █▀▀
▀▀▀▀ █▀▀▀ ▀▀▀ ▀ ▀ ▀▀▀ ▀▀▀▀ ▀▀▀ ▀▀▀
> hey
INFO 2025-07-01T21:09:02 +1ms service=app name=provider registering service
INFO 2025-07-01T21:09:02 +2ms service=models.dev refreshing
INFO 2025-07-01T21:09:02 +0ms service=provider init
INFO 2025-07-01T21:09:02 +86ms service=provider providerID=amazon-bedrock found
@ amazon-bedrock/anthropic.claude-sonnet-4-20250514-v1:0
INFO 2025-07-01T21:09:02 +1ms service=bus type=message.part.updated subscribing
INFO 2025-07-01T21:09:02 +0ms service=session session=ses_8382d9fa1ffeWroAGhqIbKVeun chatting
INFO 2025-07-01T21:09:02 +1ms service=provider providerID=amazon-bedrock modelID=anthropic.claude-sonnet-4-20250514-v1:0 getModel
INFO 2025-07-01T21:09:02 +0ms service=provider status=started providerID=amazon-bedrock getSDK
INFO 2025-07-01T21:09:02 +11ms service=lsp.client id=typescript starting client
INFO 2025-07-01T21:09:02 +0ms service=lsp.client id=typescript sending initialize
INFO 2025-07-01T21:09:02 +29ms service=provider status=completed duration=40 providerID=amazon-bedrock getSDK
INFO 2025-07-01T21:09:02 +0ms service=provider providerID=amazon-bedrock modelID=anthropic.claude-sonnet-4-20250514-v1:0 found
INFO 2025-07-01T21:09:02 +1ms service=session sessionID=ses_8382d9fa1ffeWroAGhqIbKVeun locking
INFO 2025-07-01T21:09:02 +8ms service=bus type=storage.write publishing
INFO 2025-07-01T21:09:02 +0ms service=bus type=message.updated publishing
INFO 2025-07-01T21:09:02 +54ms service=lsp.client initialized
INFO 2025-07-01T21:09:02 +95ms service=lsp.client id=pyright starting client
INFO 2025-07-01T21:09:02 +1ms service=lsp.client id=pyright sending initialize
INFO 2025-07-01T21:09:04 +1958ms service=bus type=storage.write publishing
INFO 2025-07-01T21:09:04 +0ms service=bus type=session.updated publishing
INFO 2025-07-01T21:09:07 +3043ms service=lsp initialized
Seems like an issue with the underlying ai SDK. This works for me: packages/opencode/src/provider/provider.ts
const credentialsProvider = fromNodeProviderChain()
return {
autoload: true,
options: {
...(await credentialsProvider()),
region,
},
};
i just tried with export AWS_PROFILE=myprofile and it worked - is there any chance you have invalid credentials somewhere like ~/.aws/credentials
Nothing configured elsewhere, SSO only. Is your profile SSO as well?
yeah it's sso and i make sure i login before i start opencode and it works
is there anything else aws related in env?
trying to use this at work, where we also do sso for aws access. just setting the profile doesn't work, even after I've logged in on the command line. The normal way we have to use it is via vscode, where we put in the start url, etc, and then have to copy the full connect url and run it in the browser where we are logged into aws, and allow Q access. Assuming this isn't a normal flow, guessing that isn't covered yet by opencode? Not sure, still digging. Just wanted to add this as a data point.
does aws sts get-caller-identity work?
It does, and now I think the issue is going to be the it's a different id being used in vscode. get-caller-identity is showing my normal cli logged in user, but we have that alternate login method via vscode. I'll have to find time to do more digging on that. it should be possible to bridge the two.
Nothing crazy, and the cli works. I've had issues with fromNodeProviderChain in the past. I'll crack a beer over the weekend and take a closer look. AWS isn't giving us any more Sonnet 4 tokens per minute, so Bedrock is pretty useless at this point anyway.
I am able to call aws sts get-caller-identity and get the right auth response, this is also via sso. I have also tried explictly running export AWS_REGION=us-east-1 before opencode auth and it is always the same response...
> opencode auth login
┌ Add credential
│
◇ Select provider
│ Amazon Bedrock
│
● Amazon bedrock can be configured with standard AWS environment variables like AWS_PROFILE or AWS_ACCESS_KEY_ID
│
└ Done
@thdxr echo $AWS_PROFILE also shows the correct AWS profile name so I know it is set for the system, I can run other aws commands.
@reedbender for Bedrock you authenticate by setting the env variables. No need to call opencode auth login. You will always get this message.
https://github.com/sst/opencode/blob/a272b58fe988addc5c0d18bbaba2b09fac1d9fef/packages/opencode/src/cli/cmd/auth.ts#L121-L127
Try running the model.
opencode run hi --print-logs --model amazon-bedrock/anthropic.claude-sonnet-4-20250514-v1:0
when I run opencode run hi --print-logs --model amazon-bedrock/anthropic.claude-sonnet-4-20250514-v1:0 I get:
ERROR 2025-07-08T13:33:13 +4ms service=default name=ResolveMessage message=Cannot find module '/home/samuel/.cache/opencode/node_modules/@aws-sdk/credential-providers' from '/$bunfs/root/opencode' code=ERR_MODULE_NOT_FOUND specifier=/home/samuel/.cache/opencode/node_modules/@aws-sdk/credential-providers referrer=/$bunfs/root/opencode importKind=import-statement fatal
Error: Unexpected error, check log file at for more details
which makes sense:
[15:33:13] ~ (t480) $ ls ~/.cache/opencode/node_modules/
@ai-sdk/ eventsource-parser/ nanoid/ @standard-schema/ zod-to-json-schema/
.bin/ json-schema/ secure-json-parse/ zod/
EDIT: I ran rm -rf ~/.cache/opencode and it solved itself on the next run🤷
I have managed to duplicate the vscode auth flow, in a script, and have it down to exporting AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN. not AWS_PROFILE tho. still getting denied when trying to run a query. Does it need to be turned into an actual profile?
Had the same issue after exporting $AWS_PROFILE to be the name of the current profile I need, and then testing with something like aws s3 ls --profile=$AWS_PROFILE, opencode still failed to display. Once I deleted rm -rf ~/.cache/opencode as mentioned by @SamuelNorbury then all works and the opencode GUI is displayed.
I can run opencode run hi --print-logs --model amazon-bedrock/anthropic.claude-sonnet-4-20250514-v1:0 successfully after logging into my aws profile with sso. I can also verify with echo $AWS_PROFILE that the profile is properly set. But then when I launch opencode with the tui, I can see that bedrock is the selected model but it fails to validate permission to access... even though I'd just demonstrated in the cli that it could auth and connect to the bedrock endpoint
@reedbender for Bedrock you authenticate by setting the env variables. No need to call
opencode auth login. You will always get this message.opencode/packages/opencode/src/cli/cmd/auth.ts
Lines 121 to 127 in a272b58
if (provider === "amazon-bedrock") { prompts.log.info( "Amazon bedrock can be configured with standard AWS environment variables like AWS_PROFILE or AWS_ACCESS_KEY_ID", ) prompts.outro("Done") return } Try running the model.
opencode run hi --print-logs --model amazon-bedrock/anthropic.claude-sonnet-4-20250514-v1:0
Thanks for this suggestion @superandrew213, it was useful to see at least that my aws sso is at least recognized by opencode and the model endpoint can be reached