|
| 1 | +# Bedrock connector blueprint example for Claude 3.7 model |
| 2 | + |
| 3 | +Anthropic's Claude 3.7 Sonnet model is now available on Amazon Bedrock. For more details, check out this [blog](https://aws.amazon.com/blogs/aws/anthropics-claude-3-7-sonnet-the-first-hybrid-reasoning-model-is-now-available-in-amazon-bedrock/). |
| 4 | + |
| 5 | +Claude 3.7 is Anthropic's first hybrid reasoning model, supporting two modes: standard and extended thinking. This doc covers both modes. |
| 6 | + |
| 7 | +## 1. Add connector endpoint to trusted URLs: |
| 8 | + |
| 9 | +Note: This step is only necessary for OpenSearch versions prior to 2.11.0. |
| 10 | + |
| 11 | +```json |
| 12 | +PUT /_cluster/settings |
| 13 | +{ |
| 14 | + "persistent": { |
| 15 | + "plugins.ml_commons.trusted_connector_endpoints_regex": [ |
| 16 | + "^https://bedrock-runtime\\..*[a-z0-9-]\\.amazonaws\\.com/.*$" |
| 17 | + ] |
| 18 | + } |
| 19 | +} |
| 20 | +``` |
| 21 | + |
| 22 | +## 2. Standard mode |
| 23 | +### 2.1 Create connector |
| 24 | + |
| 25 | +If you are using self-managed Opensearch, you should supply AWS credentials: |
| 26 | + |
| 27 | +Note: |
| 28 | +1. User needs to use [inference profile](https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-support.html) for invocation of this model. We can see the profile ID for Claude 3.7 is `us.anthropic.claude-3-7-sonnet-20250219-v1:0` for three available US regions `us-east-1`, `us-east-2`, `us-west-2`. |
| 29 | + |
| 30 | +```json |
| 31 | +POST /_plugins/_ml/connectors/_create |
| 32 | +{ |
| 33 | + "name": "Amazon Bedrock claude v3.7", |
| 34 | + "description": "Test connector for Amazon Bedrock claude v3.7", |
| 35 | + "version": 1, |
| 36 | + "protocol": "aws_sigv4", |
| 37 | + "credential": { |
| 38 | + "access_key": "<PLEASE ADD YOUR AWS ACCESS KEY HERE>", |
| 39 | + "secret_key": "<PLEASE ADD YOUR AWS SECRET KEY HERE>", |
| 40 | + "session_token": "<PLEASE ADD YOUR AWS SECURITY TOKEN HERE>" |
| 41 | + }, |
| 42 | + "parameters": { |
| 43 | + "region": "<PLEASE ADD YOUR AWS REGION HERE>", |
| 44 | + "service_name": "bedrock", |
| 45 | + "max_tokens": 8000, |
| 46 | + "temperature": 1, |
| 47 | + "anthropic_version": "bedrock-2023-05-31", |
| 48 | + "model": "us.anthropic.claude-3-7-sonnet-20250219-v1:0" |
| 49 | + }, |
| 50 | + "actions": [ |
| 51 | + { |
| 52 | + "action_type": "predict", |
| 53 | + "method": "POST", |
| 54 | + "headers": { |
| 55 | + "content-type": "application/json" |
| 56 | + }, |
| 57 | + "url": "https://bedrock-runtime.${parameters.region}.amazonaws.com/model/${parameters.model}/invoke", |
| 58 | + "request_body": "{ \"anthropic_version\": \"${parameters.anthropic_version}\", \"max_tokens\": ${parameters.max_tokens}, \"temperature\": ${parameters.temperature}, \"messages\": ${parameters.messages} }" |
| 59 | + } |
| 60 | + ] |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +If using the AWS Opensearch Service, you can provide an IAM role arn that allows access to the bedrock service. |
| 65 | +Refer to this [AWS doc](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/ml-amazon-connector.html) |
| 66 | + |
| 67 | +```json |
| 68 | +POST /_plugins/_ml/connectors/_create |
| 69 | +{ |
| 70 | + "name": "Amazon Bedrock claude v3.7", |
| 71 | + "description": "Test connector for Amazon Bedrock claude v3.7", |
| 72 | + "version": 1, |
| 73 | + "protocol": "aws_sigv4", |
| 74 | + "credential": { |
| 75 | + "roleArn": "<PLEASE ADD YOUR AWS ROLE ARN HERE>" |
| 76 | + }, |
| 77 | + "parameters": { |
| 78 | + "region": "<PLEASE ADD YOUR AWS REGION HERE>", |
| 79 | + "service_name": "bedrock", |
| 80 | + "max_tokens": 8000, |
| 81 | + "temperature": 1, |
| 82 | + "anthropic_version": "bedrock-2023-05-31", |
| 83 | + "model": "us.anthropic.claude-3-7-sonnet-20250219-v1:0" |
| 84 | + }, |
| 85 | + "actions": [ |
| 86 | + { |
| 87 | + "action_type": "predict", |
| 88 | + "method": "POST", |
| 89 | + "headers": { |
| 90 | + "content-type": "application/json" |
| 91 | + }, |
| 92 | + "url": "https://bedrock-runtime.${parameters.region}.amazonaws.com/model/${parameters.model}/invoke", |
| 93 | + "request_body": "{ \"anthropic_version\": \"${parameters.anthropic_version}\", \"max_tokens\": ${parameters.max_tokens}, \"temperature\": ${parameters.temperature}, \"messages\": ${parameters.messages} }" |
| 94 | + } |
| 95 | + ] |
| 96 | +} |
| 97 | +``` |
| 98 | + |
| 99 | +Sample response: |
| 100 | +```json |
| 101 | +{ |
| 102 | + "connector_id": "fa5tP5UBX2k07okSp89B" |
| 103 | +} |
| 104 | +``` |
| 105 | + |
| 106 | +### 2.2 Register model |
| 107 | + |
| 108 | +```json |
| 109 | +POST /_plugins/_ml/models/_register?deploy=true |
| 110 | +{ |
| 111 | + "name": "anthropic.claude-v3.7", |
| 112 | + "function_name": "remote", |
| 113 | + "description": "claude v3.7 model", |
| 114 | + "connector_id": "fa5tP5UBX2k07okSp89B" |
| 115 | +} |
| 116 | +``` |
| 117 | + |
| 118 | +Sample response: |
| 119 | +```json |
| 120 | +{ |
| 121 | + "task_id": "fq5uP5UBX2k07okSFM__", |
| 122 | + "status": "CREATED", |
| 123 | + "model_id": "f65uP5UBX2k07okSFc8P" |
| 124 | +} |
| 125 | +``` |
| 126 | + |
| 127 | +### 2.3 Test model inference |
| 128 | + |
| 129 | +```json |
| 130 | +POST /_plugins/_ml/models/f65uP5UBX2k07okSFc8P/_predict |
| 131 | +{ |
| 132 | + "parameters": { |
| 133 | + "messages": [ |
| 134 | + { |
| 135 | + "role": "user", |
| 136 | + "content": [ |
| 137 | + { |
| 138 | + "type": "text", |
| 139 | + "text": "hello world" |
| 140 | + } |
| 141 | + ] |
| 142 | + } |
| 143 | + ] |
| 144 | + } |
| 145 | +} |
| 146 | +``` |
| 147 | + |
| 148 | +Sample response: |
| 149 | +```json |
| 150 | +{ |
| 151 | + "inference_results": [ |
| 152 | + { |
| 153 | + "output": [ |
| 154 | + { |
| 155 | + "name": "response", |
| 156 | + "dataAsMap": { |
| 157 | + "id": "msg_bdrk_012spGFGr4CcD1PWb2TSfYut", |
| 158 | + "type": "message", |
| 159 | + "role": "assistant", |
| 160 | + "model": "claude-3-7-sonnet-20250219", |
| 161 | + "content": [ |
| 162 | + { |
| 163 | + "type": "text", |
| 164 | + "text": "Hello! It's nice to meet you. How can I help you today?" |
| 165 | + } |
| 166 | + ], |
| 167 | + "stop_reason": "end_turn", |
| 168 | + "stop_sequence": null, |
| 169 | + "usage": { |
| 170 | + "input_tokens": 9.0, |
| 171 | + "cache_creation_input_tokens": 0.0, |
| 172 | + "cache_read_input_tokens": 0.0, |
| 173 | + "output_tokens": 19.0 |
| 174 | + } |
| 175 | + } |
| 176 | + } |
| 177 | + ], |
| 178 | + "status_code": 200 |
| 179 | + } |
| 180 | + ] |
| 181 | +} |
| 182 | +``` |
| 183 | + |
| 184 | +## 3. Extended thinking mode |
| 185 | + |
| 186 | +Extended thinking mode allows Claude 3.7 to perform more in-depth reasoning before providing a response. |
| 187 | + |
| 188 | +### 3.1 Create connector |
| 189 | + |
| 190 | +```json |
| 191 | +POST /_plugins/_ml/connectors/_create |
| 192 | +{ |
| 193 | + "name": "Amazon Bedrock claude v3.7", |
| 194 | + "description": "Test connector for Amazon Bedrock claude v3.7", |
| 195 | + "version": 1, |
| 196 | + "protocol": "aws_sigv4", |
| 197 | + "credential": { |
| 198 | + "access_key": "<PLEASE ADD YOUR AWS ACCESS KEY HERE>", |
| 199 | + "secret_key": "<PLEASE ADD YOUR AWS SECRET KEY HERE>", |
| 200 | + "session_token": "<PLEASE ADD YOUR AWS SECURITY TOKEN HERE>" |
| 201 | + }, |
| 202 | + "parameters": { |
| 203 | + "region": "<PLEASE ADD YOUR AWS REGION HERE>", |
| 204 | + "service_name": "bedrock", |
| 205 | + "max_tokens": 8000, |
| 206 | + "temperature": 1, |
| 207 | + "anthropic_version": "bedrock-2023-05-31", |
| 208 | + "model": "us.anthropic.claude-3-7-sonnet-20250219-v1:0", |
| 209 | + "budget_tokens": 1024 |
| 210 | + }, |
| 211 | + "actions": [ |
| 212 | + { |
| 213 | + "action_type": "predict", |
| 214 | + "method": "POST", |
| 215 | + "headers": { |
| 216 | + "content-type": "application/json" |
| 217 | + }, |
| 218 | + "url": "https://bedrock-runtime.${parameters.region}.amazonaws.com/model/${parameters.model}/invoke", |
| 219 | + "request_body": "{ \"anthropic_version\": \"${parameters.anthropic_version}\", \"max_tokens\": ${parameters.max_tokens}, \"temperature\": ${parameters.temperature}, \"messages\": ${parameters.messages}, \"thinking\": {\"type\": \"enabled\", \"budget_tokens\": ${parameters.budget_tokens} } }" |
| 220 | + } |
| 221 | + ] |
| 222 | +} |
| 223 | +``` |
| 224 | + |
| 225 | +If using the AWS Opensearch Service, you can provide an IAM role arn that allows access to the bedrock service. |
| 226 | +Refer to this [AWS doc](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/ml-amazon-connector.html) |
| 227 | + |
| 228 | +```json |
| 229 | +POST /_plugins/_ml/connectors/_create |
| 230 | +{ |
| 231 | + "name": "Amazon Bedrock claude v3.7", |
| 232 | + "description": "Test connector for Amazon Bedrock claude v3.7", |
| 233 | + "version": 1, |
| 234 | + "protocol": "aws_sigv4", |
| 235 | + "credential": { |
| 236 | + "roleArn": "<PLEASE ADD YOUR AWS ROLE ARN HERE>" |
| 237 | + }, |
| 238 | + "parameters": { |
| 239 | + "region": "<PLEASE ADD YOUR AWS REGION HERE>", |
| 240 | + "service_name": "bedrock", |
| 241 | + "max_tokens": 8000, |
| 242 | + "temperature": 1, |
| 243 | + "anthropic_version": "bedrock-2023-05-31", |
| 244 | + "model": "us.anthropic.claude-3-7-sonnet-20250219-v1:0", |
| 245 | + "budget_tokens": 1024 |
| 246 | + }, |
| 247 | + "actions": [ |
| 248 | + { |
| 249 | + "action_type": "predict", |
| 250 | + "method": "POST", |
| 251 | + "headers": { |
| 252 | + "content-type": "application/json" |
| 253 | + }, |
| 254 | + "url": "https://bedrock-runtime.${parameters.region}.amazonaws.com/model/${parameters.model}/invoke", |
| 255 | + "request_body": "{ \"anthropic_version\": \"${parameters.anthropic_version}\", \"max_tokens\": ${parameters.max_tokens}, \"temperature\": ${parameters.temperature}, \"messages\": ${parameters.messages}, \"thinking\": {\"type\": \"enabled\", \"budget_tokens\": ${parameters.budget_tokens} } }" |
| 256 | + } |
| 257 | + ] |
| 258 | +} |
| 259 | +``` |
| 260 | + |
| 261 | +Sample response: |
| 262 | +```json |
| 263 | +{ |
| 264 | + "connector_id": "1652P5UBX2k07okSys_J" |
| 265 | +} |
| 266 | +``` |
| 267 | + |
| 268 | +### 3.2 Register model: |
| 269 | + |
| 270 | +```json |
| 271 | +POST /_plugins/_ml/models/_register?deploy=true |
| 272 | +{ |
| 273 | + "name": "anthropic.claude-v3.7", |
| 274 | + "function_name": "remote", |
| 275 | + "description": "claude v3.7 model", |
| 276 | + "connector_id": "1652P5UBX2k07okSys_J" |
| 277 | +} |
| 278 | +``` |
| 279 | + |
| 280 | +Sample response: |
| 281 | +```json |
| 282 | +{ |
| 283 | + "task_id": "5K53P5UBX2k07okSXc-7", |
| 284 | + "status": "CREATED", |
| 285 | + "model_id": "5a53P5UBX2k07okSXc_M" |
| 286 | +} |
| 287 | +``` |
| 288 | + |
| 289 | +### 3.3 Test model inference |
| 290 | + |
| 291 | +```json |
| 292 | +POST /_plugins/_ml/models/5a53P5UBX2k07okSXc_M/_predict |
| 293 | +{ |
| 294 | + "parameters": { |
| 295 | + "messages": [ |
| 296 | + { |
| 297 | + "role": "user", |
| 298 | + "content": [ |
| 299 | + { |
| 300 | + "type": "text", |
| 301 | + "text": "hello world" |
| 302 | + } |
| 303 | + ] |
| 304 | + } |
| 305 | + ] |
| 306 | + } |
| 307 | +} |
| 308 | +``` |
| 309 | + |
| 310 | +Sample response: |
| 311 | +```json |
| 312 | +{ |
| 313 | + "inference_results": [ |
| 314 | + { |
| 315 | + "output": [ |
| 316 | + { |
| 317 | + "name": "response", |
| 318 | + "dataAsMap": { |
| 319 | + "id": "msg_bdrk_01TqgZsyqsxhNGAGVjRjCP6N", |
| 320 | + "type": "message", |
| 321 | + "role": "assistant", |
| 322 | + "model": "claude-3-7-sonnet-20250219", |
| 323 | + "content": [ |
| 324 | + { |
| 325 | + "type": "thinking", |
| 326 | + "thinking": "This is a simple greeting phrase \"hello world\" which is often the first program someone writes when learning a new programming language. The person could be:\n1. Simply greeting me casually\n2. Making a reference to programming\n3. Testing if I'm working\n\nI'll respond with a friendly greeting that acknowledges the \"hello world\" phrase and its connection to programming culture, while being conversational.", |
| 327 | + "signature": "EqgBCkYQARgCIkBAw8igmzDbjCXk1nLyWHFoS46Pi0VzkRj0IOySgDccftUjmMHmfM7nEWxPnjsgT3SEpFDDcS4Sj5gAiWjbejGTEgyCZKvfxX/J+ss/cM8aDH7t4SO42Cmpg+heNyIw2jyV6CD0lsx+mJAh6CuJtxXrfrp/VAu8FERnH2JTovSm0U3KYf+vRwfJNMdb3AsnKhAFuA24st/+8w6g5Xwxdqce" |
| 328 | + }, |
| 329 | + { |
| 330 | + "type": "text", |
| 331 | + "text": "Hello! It's nice to meet you. \"Hello world\" is such a classic phrase - it's often the first program many people write when learning to code! How are you doing today? Is there something I can help you with?" |
| 332 | + } |
| 333 | + ], |
| 334 | + "stop_reason": "end_turn", |
| 335 | + "stop_sequence": null, |
| 336 | + "usage": { |
| 337 | + "input_tokens": 37.0, |
| 338 | + "cache_creation_input_tokens": 0.0, |
| 339 | + "cache_read_input_tokens": 0.0, |
| 340 | + "output_tokens": 143.0 |
| 341 | + } |
| 342 | + } |
| 343 | + } |
| 344 | + ], |
| 345 | + "status_code": 200 |
| 346 | + } |
| 347 | + ] |
| 348 | +} |
| 349 | +``` |
0 commit comments