Skip to content

Commit 64b8aaa

Browse files
authored
Merge branch 'main' into agent_bug_fix
2 parents d3a5bfb + 2a9baeb commit 64b8aaa

File tree

2 files changed

+341
-1
lines changed

2 files changed

+341
-1
lines changed

docs/remote_inference_blueprints/bedrock_connector_anthropic_claude3.7_blueprint.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ Sample response:
324324
{
325325
"type": "thinking",
326326
"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"
327+
"signature": "<THOUGHT_SIGNATURE>"
328328
},
329329
{
330330
"type": "text",
Lines changed: 340 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,340 @@
1+
# Bedrock connector blueprint example for Claude 4 models
2+
3+
Anthropic's Claude 4 models are now available on Amazon Bedrock. For more details, check out this [blog](https://www.aboutamazon.com/news/aws/anthropic-claude-4-opus-sonnet-amazon-bedrock).
4+
5+
Similar to Claude 3.7 Sonnet, Claude 4 offers both standard mode and [extended thinking mode](https://www.anthropic.com/news/visible-extended-thinking). Extended thinking mode directs the model to think more deeply about trickier questions by creating `thinking` content blocks for its internal reasoning. This also provides transparency into Claude's thought process before it delivers a final answer.
6+
7+
This blueprint will cover both the standard mode and the extended thinking mode.
8+
9+
## 1. Add connector endpoint to trusted URLs:
10+
11+
Note: This step is only necessary for OpenSearch versions prior to 2.11.0.
12+
13+
```json
14+
PUT /_cluster/settings
15+
{
16+
"persistent": {
17+
"plugins.ml_commons.trusted_connector_endpoints_regex": [
18+
"^https://bedrock-runtime\\..*[a-z0-9-]\\.amazonaws\\.com/.*$"
19+
]
20+
}
21+
}
22+
```
23+
24+
## 2. Standard mode
25+
26+
If you would like to use the extended thinking mode, skip to [section 3](#section3).
27+
### 2.1 Create connector
28+
29+
If you are using self-managed Opensearch, you should supply AWS credentials:
30+
31+
Note:
32+
1. Users need to use an [inference profile](https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-support.html) to invoke this model. The profile IDs for Claude Sonnet 4 and Claude Opus 4 are `us.anthropic.claude-sonnet-4-20250514-v1:0` and `us.anthropic.claude-opus-4-20250514-v1:0` respectively, for three available US regions `us-east-1`, `us-east-2` and `us-west-2`.
33+
34+
```json
35+
POST /_plugins/_ml/connectors/_create
36+
{
37+
"name": "Amazon Bedrock claude v4",
38+
"description": "Test connector for Amazon Bedrock claude v4",
39+
"version": 1,
40+
"protocol": "aws_sigv4",
41+
"credential": {
42+
"access_key": "<PLEASE ADD YOUR AWS ACCESS KEY HERE>",
43+
"secret_key": "<PLEASE ADD YOUR AWS SECRET KEY HERE>",
44+
"session_token": "<PLEASE ADD YOUR AWS SECURITY TOKEN HERE>"
45+
},
46+
"parameters": {
47+
"region": "<PLEASE ADD YOUR AWS REGION HERE>",
48+
"service_name": "bedrock",
49+
"max_tokens": 8000,
50+
"temperature": 1,
51+
"anthropic_version": "bedrock-2023-05-31",
52+
"model": "us.anthropic.claude-sonnet-4-20250514-v1:0"
53+
},
54+
"actions": [
55+
{
56+
"action_type": "predict",
57+
"method": "POST",
58+
"headers": {
59+
"content-type": "application/json"
60+
},
61+
"url": "https://bedrock-runtime.${parameters.region}.amazonaws.com/model/${parameters.model}/invoke",
62+
"request_body": "{ \"anthropic_version\": \"${parameters.anthropic_version}\", \"max_tokens\": ${parameters.max_tokens}, \"temperature\": ${parameters.temperature}, \"messages\": ${parameters.messages} }"
63+
}
64+
]
65+
}
66+
```
67+
68+
If using AWS Opensearch Service, you can provide an IAM role arn that allows access to the bedrock service.
69+
Refer to this [AWS doc](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/ml-amazon-connector.html)
70+
71+
```json
72+
POST /_plugins/_ml/connectors/_create
73+
{
74+
"name": "Amazon Bedrock claude v4",
75+
"description": "Test connector for Amazon Bedrock claude v4",
76+
"version": 1,
77+
"protocol": "aws_sigv4",
78+
"credential": {
79+
"roleArn": "<PLEASE ADD YOUR AWS ROLE ARN HERE>"
80+
},
81+
"parameters": {
82+
"region": "<PLEASE ADD YOUR AWS REGION HERE>",
83+
"service_name": "bedrock",
84+
"max_tokens": 8000,
85+
"temperature": 1,
86+
"anthropic_version": "bedrock-2023-05-31",
87+
"model": "us.anthropic.claude-sonnet-4-20250514-v1:0"
88+
},
89+
"actions": [
90+
{
91+
"action_type": "predict",
92+
"method": "POST",
93+
"headers": {
94+
"content-type": "application/json"
95+
},
96+
"url": "https://bedrock-runtime.${parameters.region}.amazonaws.com/model/${parameters.model}/invoke",
97+
"request_body": "{ \"anthropic_version\": \"${parameters.anthropic_version}\", \"max_tokens\": ${parameters.max_tokens}, \"temperature\": ${parameters.temperature}, \"messages\": ${parameters.messages} }"
98+
}
99+
]
100+
}
101+
```
102+
103+
Sample response:
104+
```json
105+
{
106+
"connector_id":"5kxp_5YBIvu8EdWRQuez"
107+
}
108+
```
109+
110+
### 2.2 Register model
111+
112+
```json
113+
POST /_plugins/_ml/models/_register?deploy=true
114+
{
115+
"name": "anthropic.claude-v4",
116+
"function_name": "remote",
117+
"description": "claude v4 model",
118+
"connector_id": "5kxp_5YBIvu8EdWRQuez"
119+
}
120+
```
121+
122+
Sample response:
123+
```json
124+
{
125+
"task_id":"6kxq_5YBIvu8EdWRwedJ",
126+
"status":"CREATED",
127+
"model_id":"7Exq_5YBIvu8EdWRwefI"
128+
}
129+
```
130+
131+
### 2.3 Test model inference
132+
133+
```json
134+
POST /_plugins/_ml/models/7Exq_5YBIvu8EdWRwefI/_predict
135+
{
136+
"parameters": {
137+
"messages": [
138+
{
139+
"role": "user",
140+
"content": [
141+
{
142+
"type": "text",
143+
"text": "hello world"
144+
}
145+
]
146+
}
147+
]
148+
}
149+
}
150+
```
151+
152+
Sample response:
153+
```json
154+
{
155+
"inference_results": [{
156+
"output": [{
157+
"name": "response",
158+
"dataAsMap": {
159+
"id": "msg_bdrk_017wv2bnUmKroe7C48MHdu32",
160+
"type": "message",
161+
"role": "assistant",
162+
"model": "claude-sonnet-4-20250514",
163+
"content": [{
164+
"type": "text",
165+
"text": "Hello! Nice to meet you. How are you doing today? Is there anything I can help you with?"
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": 25.0
174+
}
175+
}
176+
}],
177+
"status_code": 200
178+
}]
179+
}
180+
```
181+
182+
## <a id="section3"></a>3. Extended thinking mode
183+
184+
Extended thinking mode allows Claude 4 to perform more in-depth reasoning before providing a response. Note that `budget_tokens` can be specified in parameters, which determines the number of tokens Claude can use for its internal reasoning process. See Claude [documentation](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking#how-to-use-extended-thinking) for more details.
185+
186+
### 3.1 Create connector
187+
188+
```json
189+
POST /_plugins/_ml/connectors/_create
190+
{
191+
"name": "Amazon Bedrock claude v4",
192+
"description": "Test connector for Amazon Bedrock claude v4",
193+
"version": 1,
194+
"protocol": "aws_sigv4",
195+
"credential": {
196+
"access_key": "<PLEASE ADD YOUR AWS ACCESS KEY HERE>",
197+
"secret_key": "<PLEASE ADD YOUR AWS SECRET KEY HERE>",
198+
"session_token": "<PLEASE ADD YOUR AWS SECURITY TOKEN HERE>"
199+
},
200+
"parameters": {
201+
"region": "<PLEASE ADD YOUR AWS REGION HERE>",
202+
"service_name": "bedrock",
203+
"max_tokens": 8000,
204+
"temperature": 1,
205+
"anthropic_version": "bedrock-2023-05-31",
206+
"model": "us.anthropic.claude-sonnet-4-20250514-v1:0",
207+
"budget_tokens": 1024
208+
},
209+
"actions": [
210+
{
211+
"action_type": "predict",
212+
"method": "POST",
213+
"headers": {
214+
"content-type": "application/json"
215+
},
216+
"url": "https://bedrock-runtime.${parameters.region}.amazonaws.com/model/${parameters.model}/invoke",
217+
"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} } }"
218+
}
219+
]
220+
}
221+
```
222+
223+
If using the AWS Opensearch Service, you can provide an IAM role arn that allows access to the bedrock service.
224+
Refer to this [AWS doc](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/ml-amazon-connector.html)
225+
226+
```json
227+
POST /_plugins/_ml/connectors/_create
228+
{
229+
"name": "Amazon Bedrock claude v4",
230+
"description": "Test connector for Amazon Bedrock claude v4",
231+
"version": 1,
232+
"protocol": "aws_sigv4",
233+
"credential": {
234+
"roleArn": "<PLEASE ADD YOUR AWS ROLE ARN HERE>"
235+
},
236+
"parameters": {
237+
"region": "<PLEASE ADD YOUR AWS REGION HERE>",
238+
"service_name": "bedrock",
239+
"max_tokens": 8000,
240+
"temperature": 1,
241+
"anthropic_version": "bedrock-2023-05-31",
242+
"model": "us.anthropic.claude-sonnet-4-20250514-v1:0",
243+
"budget_tokens": 1024
244+
},
245+
"actions": [
246+
{
247+
"action_type": "predict",
248+
"method": "POST",
249+
"headers": {
250+
"content-type": "application/json"
251+
},
252+
"url": "https://bedrock-runtime.${parameters.region}.amazonaws.com/model/${parameters.model}/invoke",
253+
"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} } }"
254+
}
255+
]
256+
}
257+
```
258+
259+
Sample response:
260+
```json
261+
{
262+
"connector_id":"DEx5_5YBIvu8EdWRTOiq"
263+
}
264+
```
265+
266+
### 3.2 Register model:
267+
268+
```json
269+
POST /_plugins/_ml/models/_register?deploy=true
270+
{
271+
"name": "anthropic.claude-v4",
272+
"function_name": "remote",
273+
"description": "claude v4 model with extended thinking",
274+
"connector_id": "DEx5_5YBIvu8EdWRTOiq"
275+
}
276+
```
277+
278+
Sample response:
279+
```json
280+
{
281+
"task_id":"DUx6_5YBIvu8EdWRLuj1",
282+
"status":"CREATED",
283+
"model_id":"Dkx6_5YBIvu8EdWRL-gO"
284+
}
285+
```
286+
287+
### 3.3 Test model inference
288+
289+
```json
290+
POST /_plugins/_ml/models/Dkx6_5YBIvu8EdWRL-gO/_predict
291+
{
292+
"parameters": {
293+
"messages": [
294+
{
295+
"role": "user",
296+
"content": [
297+
{
298+
"type": "text",
299+
"text": "hello world"
300+
}
301+
]
302+
}
303+
]
304+
}
305+
}
306+
```
307+
308+
Sample response:
309+
```json
310+
{
311+
"inference_results": [{
312+
"output": [{
313+
"name": "response",
314+
"dataAsMap": {
315+
"id": "msg_bdrk_0117MNj2HVP7dXmeDGeCSQaL",
316+
"type": "message",
317+
"role": "assistant",
318+
"model": "claude-sonnet-4-20250514",
319+
"content": [{
320+
"type": "thinking",
321+
"thinking": "The user has sent me a simple \"hello world\" message. This is a classic, friendly greeting that's often used as a first program or test message in programming and casual conversation. I should respond in a warm, welcoming way.",
322+
"signature": "<THOUGHT_SIGNATURE>"
323+
}, {
324+
"type": "text",
325+
"text": "Hello! It's nice to meet you. How are you doing today? Is there anything I can help you with?"
326+
}],
327+
"stop_reason": "end_turn",
328+
"stop_sequence": null,
329+
"usage": {
330+
"input_tokens": 37.0,
331+
"cache_creation_input_tokens": 0.0,
332+
"cache_read_input_tokens": 0.0,
333+
"output_tokens": 84.0
334+
}
335+
}
336+
}],
337+
"status_code": 200
338+
}]
339+
}
340+
```

0 commit comments

Comments
 (0)