Anyone hitting the below error when running claude code?
⎿ API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"The request body is not valid JSON: invalid high surrogate in string: line 47 column 5162 (char 45482)"}}
As the error says, you must provide the ID of an inference profile and not the model for this particular model. The easiest way to do this is to provide the ID of a system-defined inference profile for this model. You can find it by invoking this awscli command with the correct credentials defined in the environment (or set via standard flags):
aws bedrock list-inference-profiles
You will see this one in the JSON list:
{
"inferenceProfileName": "US Anthropic Claude 3.5 Sonnet v2",
"description": "Routes requests to Anthropic Claude 3.5 Sonnet v2 in us-west-2, us-east-1 and us-east-2.",
"inferenceProfileArn": "arn:aws:bedrock:us-east-1:381492273274:inference-profile/us.anthropic.claude-3-5-sonnet-20241022-v2:0",
"models": [
{
"modelArn": "arn:aws:bedrock:us-west-2::foundation-model/anthropic.claude-3-5-sonnet-20241022-v2:0"
},
{
"modelArn": "arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-5-sonnet-20241022-v2:0"
},
{
"modelArn": "arn:aws:bedrock:us-east-2::foundation-model/anthropic.claude-3-5-sonnet-20241022-v2:0"
}
],
"inferenceProfileId": "us.anthropic.claude-3-5-sonnet-20241022-v2:0",
"status": "ACTIVE",
"type": "SYSTEM_DEFINED"
}
Modify the invoke_model line in your code to specify the ID or ARN of the inference profile instead:
response = bedrock_runtime.invoke_model(
body=body,
modelId="us.anthropic.claude-3-5-sonnet-20241022-v2:0",
)
You can add the ARN of an Inference profile to your modelID itself while invoking the model.
response = bedrock_client.invoke_model(
modelId="arn:aws:bedrock:us-east-1::model/your-bedrock-model-arn"
prompt="Your prompt here"
)
Has anyone seen this error before?
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"input length and `max_tokens` exceed context limit: 199926 + 21333 > 200000, decrease input length or `max_tokens` and try again"}}What's strange is that I'm not one of those crazy Claude Code users that have it running in multiple terminals ...etc
A single terminal, and give it simple instructions one after the other.
What I had told it was:
Let's now add integration tests. They should sit under the following directory: <directory-path> We use Test Containers for integration tests. Take a look at existing tests for conventions and libraries used.
And I got that error.