Skip to content

Commit 742caf5

Browse files
committed
add documentation for anthropic web search tool
1 parent 1a2fe4e commit 742caf5

File tree

2 files changed

+259
-1
lines changed

2 files changed

+259
-1
lines changed

docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@
220220
"group": "Anthropic",
221221
"pages": [
222222
"integrations/llms/anthropic",
223-
"integrations/llms/anthropic/prompt-caching"
223+
"integrations/llms/anthropic/prompt-caching",
224+
"integrations/llms/anthropic/web-search"
224225
]
225226
},
226227
"integrations/llms/gemini",
Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
---
2+
title: "Web Search tool"
3+
---
4+
5+
Anthropic web search is fully supported in Portkey.
6+
7+
8+
### Usage
9+
<CodeGroup>
10+
```py Python
11+
from portkey_ai import Portkey
12+
13+
# Initialize the Portkey client
14+
portkey = Portkey(
15+
api_key="PORTKEY_API_KEY", # Replace with your Portkey API key
16+
virtual_key="VIRTUAL_KEY", # Add your provider's virtual key
17+
)
18+
19+
# Create the request
20+
response = portkey.chat.completions.create(
21+
model="claude-4-opus-20250514",
22+
max_tokens=3000,
23+
thinking={
24+
"type": "enabled",
25+
"budget_tokens": 2030
26+
},
27+
stream=False,
28+
tools=[
29+
{
30+
type: "computer",
31+
computer: {
32+
name: "computer_20250124", # This is the version of the tool
33+
display_width_px: 1024,
34+
display_height_px: 768,
35+
display_number: 1
36+
}
37+
},
38+
{
39+
type: "text_editor_20250429",
40+
name: "str_replace_based_edit_tool"
41+
},
42+
{
43+
type: "bash_20250124",
44+
name: "bash"
45+
}
46+
],
47+
messages=[
48+
{
49+
role: "user",
50+
content: "Save a picture of a cat to my desktop."
51+
}
52+
]
53+
)
54+
print(response)
55+
56+
```
57+
```ts NodeJS
58+
import Portkey from 'portkey-ai';
59+
60+
// Initialize the Portkey client
61+
const portkey = new Portkey({
62+
apiKey: "PORTKEY_API_KEY", // Replace with your Portkey API key
63+
virtualKey: "VIRTUAL_KEY", // Add your anthropic's virtual key
64+
strictOpenAiCompliance: false
65+
});
66+
67+
// Generate a chat completion
68+
async function getChatCompletionFunctions() {
69+
const response = await portkey.chat.completions.create({
70+
model: "claude-4-opus-20250514",
71+
max_tokens: 3000,
72+
thinking: {
73+
type: "enabled",
74+
budget_tokens: 2030
75+
},
76+
stream: false,
77+
tools: [
78+
{
79+
type: "computer",
80+
computer: {
81+
name: "computer_20250124", // This is the version of the tool
82+
display_width_px: 1024,
83+
display_height_px: 768,
84+
display_number: 1
85+
}
86+
},
87+
{
88+
type: "text_editor_20250429",
89+
name: "str_replace_based_edit_tool"
90+
},
91+
{
92+
type: "bash_20250124",
93+
name: "bash"
94+
}
95+
],
96+
"messages": [
97+
{
98+
role: "user",
99+
content: "Save a picture of a cat to my desktop."
100+
}
101+
]
102+
});
103+
console.log(response);
104+
}
105+
// Call the function
106+
getChatCompletionFunctions();
107+
```
108+
```js OpenAI NodeJS
109+
import OpenAI from 'openai';
110+
import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai'
111+
112+
const openai = new OpenAI({
113+
apiKey: 'ANTHROPIC_API_KEY', // defaults to process.env["OPENAI_API_KEY"],
114+
baseURL: PORTKEY_GATEWAY_URL,
115+
defaultHeaders: createHeaders({
116+
provider: "anthropic",
117+
apiKey: "PORTKEY_API_KEY", // defaults to process.env["PORTKEY_API_KEY"]
118+
strictOpenAiCompliance: false
119+
})
120+
});
121+
122+
// Generate a chat completion with streaming
123+
async function getChatCompletionFunctions(){
124+
const response = await openai.chat.completions.create({
125+
model: "claude-4-opus-20250514",
126+
max_tokens: 3000,
127+
thinking: {
128+
type: "enabled",
129+
budget_tokens: 2030
130+
},
131+
stream: false,
132+
tools: [
133+
{
134+
type: "computer",
135+
computer: {
136+
name: "computer_20250124", // This is the version of the tool
137+
display_width_px: 1024,
138+
display_height_px: 768,
139+
display_number: 1
140+
}
141+
},
142+
{
143+
type: "text_editor_20250429",
144+
name: "str_replace_based_edit_tool"
145+
},
146+
{
147+
type: "bash_20250124",
148+
name: "bash"
149+
}
150+
],
151+
messages: [
152+
{
153+
role: "user",
154+
content: "Save a picture of a cat to my desktop."
155+
}
156+
]
157+
});
158+
159+
console.log(response)
160+
}
161+
await getChatCompletionFunctions();
162+
```
163+
```py OpenAI Python
164+
from openai import OpenAI
165+
from portkey_ai import PORTKEY_GATEWAY_URL, createHeaders
166+
167+
openai = OpenAI(
168+
api_key='Anthropic_API_KEY',
169+
base_url=PORTKEY_GATEWAY_URL,
170+
default_headers=createHeaders(
171+
provider="anthropic",
172+
api_key="PORTKEY_API_KEY",
173+
strict_open_ai_compliance=False
174+
)
175+
)
176+
177+
178+
response = openai.chat.completions.create(
179+
model="claude-4-opus-20250514",
180+
max_tokens=3000,
181+
thinking={
182+
"type": "enabled",
183+
"budget_tokens": 2030
184+
},
185+
stream=False,
186+
tools=[
187+
{
188+
type: "computer",
189+
computer: {
190+
name: "computer_20250124", # This is the version of the tool
191+
display_width_px: 1024,
192+
display_height_px: 768,
193+
display_number: 1
194+
}
195+
},
196+
{
197+
type: "text_editor_20250429",
198+
name: "str_replace_based_edit_tool"
199+
},
200+
{
201+
type: "bash_20250124",
202+
name: "bash"
203+
}
204+
],
205+
messages=[
206+
{
207+
role: "user",
208+
content: "Save a picture of a cat to my desktop."
209+
}
210+
]
211+
)
212+
213+
print(response)
214+
```
215+
```sh cURL
216+
curl "https://api.portkey.ai/v1/chat/completions" \
217+
-H "Content-Type: application/json" \
218+
-H "x-portkey-api-key: $PORTKEY_API_KEY" \
219+
-H "x-portkey-provider: anthropic" \
220+
-H "x-api-key: $ANTHROPIC_API_KEY" \
221+
-H "x-portkey-strict-open-ai-compliance: false" \
222+
-d '{
223+
"model": "claude-4-opus-20250514",
224+
"max_tokens": 3000,
225+
"thinking": {
226+
"type": "enabled",
227+
"budget_tokens": 2030
228+
},
229+
"stream": false,
230+
"tools": [
231+
{
232+
"type": "computer",
233+
"computer": {
234+
"name": "computer_20250124",
235+
"display_width_px": 1024,
236+
"display_height_px": 768,
237+
"display_number": 1
238+
}
239+
},
240+
{
241+
"type": "text_editor_20250429",
242+
"name": "str_replace_based_edit_tool"
243+
},
244+
{
245+
"type": "bash_20250124",
246+
"name": "bash"
247+
}
248+
],
249+
"messages": [
250+
{
251+
"role": "user",
252+
"content": "Save a picture of a cat to my desktop."
253+
}
254+
]
255+
}'
256+
```
257+
</CodeGroup>

0 commit comments

Comments
 (0)