claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Bedrock, 3.7

Open leotac opened this issue 10 months ago • 7 comments

Environment

  • Platform (select one):
    • [ ] Anthropic API
    • [X] AWS Bedrock
    • [ ] Google Vertex AI
  • Claude CLI version:0.2.48 (Claude Code)
  • Operating System: macOS
  • Terminal: iTerm2

Bug Description

Claude Code doesn't seem to work with Sonnet 3.7. It does work with Sonnet 3.5, while, I get a 403 error with 3.7.

Steps to Reproduce

  1. This works correctly with 3.5: ANTHROPIC_MODEL='us.anthropic.claude-3-5-sonnet-20241022-v2:0' CLAUDE_CODE_USE_BEDROCK=1 DISABLE_PROMPT_CACHING=1 claude
  2. This does not work: ANTHROPIC_MODEL='us.anthropic.claude-3-7-sonnet-20250219-v1:0' CLAUDE_CODE_USE_BEDROCK=1 DISABLE_PROMPT_CACHING=1 claude and I get: API Error: 403 You don't have access to the model with the specified model ID

However, claude 3.7 is indeed enabled and working in a python shell, as in the following example:

import boto3
bedrock = boto3.client(service_name='bedrock-runtime')
response = bedrock.invoke_model(
                modelId='us.anthropic.claude-3-7-sonnet-20250219-v1:0',
                body=json.dumps(
                    {
                        "anthropic_version": "bedrock-2023-05-31",
                        "max_tokens": 2000,
                        "messages": [
                            {
                                "role": "user",
                                "content": [{"type": "text", "text": "Hello"}],
                            }
                        ],
                    }
                ),
            )
print(json.loads(response.get("body").read())["content"][0]["text"])

That returns:

Hello! How can I assist you today?

leotac avatar Mar 18 '25 17:03 leotac

You are in the wrong AWS region, check your AWS_REGION_NAME and AWS_DEFAULT_REGION environment variables.

mark-os avatar Mar 20 '25 13:03 mark-os

Not sure I understand. Explicitly setting the region/default region doesn't help.

This works (with 3.5): ANTHROPIC_MODEL='us.anthropic.claude-3-5-sonnet-20241022-v2:0' CLAUDE_CODE_USE_BEDROCK=1 DISABLE_PROMPT_CACHING=1 AWS_REGION_NAME='us-west-2' AWS_DEFAULT_REGION='us-west-2' claude

This works (with 3.7): a python script that calls claude 3.7 with boto3, called with AWS_REGION_NAME='us-west-2' AWS_DEFAULT_REGION='us-west-2', or explicitly specifiying region_name='us-west-2' when instantiating the client.

This doesn't (with 3.7): ANTHROPIC_MODEL='us.anthropic.claude-3-7-sonnet-20250219-v1:0' CLAUDE_CODE_USE_BEDROCK=1 DISABLE_PROMPT_CACHING=1 AWS_REGION_NAME='us-west-2' AWS_DEFAULT_REGION='us-west-2' claude

claude 3.7 also works with other tools such as Aider.

leotac avatar Mar 20 '25 14:03 leotac

Hi @leotac , not sure if this is useful, but I was having some similar errors. I enabled all models in all regions I had access to. I am sure this was overkill, but it resolved my issue. I likely just needed specific models in US regions.

My default region was also us-west-2.

ppearcy avatar Mar 31 '25 19:03 ppearcy

I just got this command to work for a single instance deployed to us-east-2 and region=us-east-2 in my .aws/config file: AWS_REGION='us-east-2' ANTHROPIC_MODEL='us.anthropic.claude-3-7-sonnet-20250219-v1:0' CLAUDE_CODE_USE_BEDROCK=1 CLAUDE_CODE_DEBUG=1 DISABLE_PROMPT_CACHING=1 claude

bfeeley35 avatar Apr 30 '25 16:04 bfeeley35

I just got this command to work for a single instance deployed to us-east-2 and region=us-east-2 in my .aws/config file: AWS_REGION='us-east-2' ANTHROPIC_MODEL='us.anthropic.claude-3-7-sonnet-20250219-v1:0' CLAUDE_CODE_USE_BEDROCK=1 CLAUDE_CODE_DEBUG=1 DISABLE_PROMPT_CACHING=1 claude

Works for me

arpagon avatar May 13 '25 15:05 arpagon

It seems us.anthropic.claude-3-7-sonnet-20250219-v1:0 routes to us-east-2. I'm trying to figure out why and how to avoid it. But I also got this to work from us-east-2 and fail from us-east-1

guilleojeda avatar May 14 '25 15:05 guilleojeda

I just got this command to work for a single instance deployed to us-east-2 and region=us-east-2 in my .aws/config file: AWS_REGION='us-east-2' ANTHROPIC_MODEL='us.anthropic.claude-3-7-sonnet-20250219-v1:0' CLAUDE_CODE_USE_BEDROCK=1 CLAUDE_CODE_DEBUG=1 DISABLE_PROMPT_CACHING=1 claude

Unfortunately does not work for me

hutchisr avatar May 22 '25 18:05 hutchisr

You are in the wrong AWS region, check your AWS_REGION_NAME and AWS_DEFAULT_REGION environment variables.

FYI, this ended up being a very trivial env variable issue. Blindly following this comment I initially set AWS_DEFAULT_REGION and AWS_REGION_NAME. But the variable that should be set is AWS_REGION 😅 Doing that, everything works (assuming of course the model is enabled in that region).

leotac avatar May 27 '25 15:05 leotac

You are in the wrong AWS region, check your AWS_REGION_NAME and AWS_DEFAULT_REGION environment variables.

FYI, this ended up being a very trivial env variable issue. Blindly following this comment I initially set AWS_DEFAULT_REGION and AWS_REGION_NAME. But the variable that should be set is AWS_REGION 😅 Doing that, everything works (assuming of course the model is enabled in that region).

I am so sorry. I really thought AWS_REGION was not a valid environment variable. If I get a chance I'll try and track down where that came from in the first place, but it feels like different packages use one of the 3 and so you may need to set all 3 depending on what you're doing.

mark-os avatar Aug 08 '25 15:08 mark-os

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

github-actions[bot] avatar Aug 16 '25 14:08 github-actions[bot]