Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@
"group": "Anthropic",
"pages": [
"integrations/llms/anthropic",
"integrations/llms/anthropic/prompt-caching"
"integrations/llms/anthropic/prompt-caching",
"integrations/llms/anthropic/computer-use"
]
},
"integrations/llms/gemini",
Expand Down
258 changes: 258 additions & 0 deletions integrations/llms/anthropic/computer-use.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
---
title: "Computer use tool"
---

Anthropic computer use is fully supported in Portkey.
For more information on the computer use tool, please refer to the [Anthropic documentation](https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/computer-use-tool).


### Usage
<CodeGroup>
```py Python
from portkey_ai import Portkey

# Initialize the Portkey client
portkey = Portkey(
api_key="PORTKEY_API_KEY", # Replace with your Portkey API key
virtual_key="VIRTUAL_KEY", # Add your provider's virtual key
)

# Create the request
response = portkey.chat.completions.create(
model="claude-4-opus-20250514",
max_tokens=3000,
thinking={
"type": "enabled",
"budget_tokens": 2030
},
stream=False,
tools=[
{
type: "computer",
computer: {
name: "computer_20250124", # This is the version of the tool
display_width_px: 1024,
display_height_px: 768,
display_number: 1
}
},
{
type: "text_editor_20250429",
name: "str_replace_based_edit_tool"
},
{
type: "bash_20250124",
name: "bash"
}
],
messages=[
{
role: "user",
content: "Save a picture of a cat to my desktop."
}
]
)
print(response)

```
```ts NodeJS
import Portkey from 'portkey-ai';

// Initialize the Portkey client
const portkey = new Portkey({
apiKey: "PORTKEY_API_KEY", // Replace with your Portkey API key
virtualKey: "VIRTUAL_KEY", // Add your anthropic's virtual key
strictOpenAiCompliance: false
});

// Generate a chat completion
async function getChatCompletionFunctions() {
const response = await portkey.chat.completions.create({
model: "claude-4-opus-20250514",
max_tokens: 3000,
thinking: {
type: "enabled",
budget_tokens: 2030
},
stream: false,
tools: [
{
type: "computer",
computer: {
name: "computer_20250124", // This is the version of the tool
display_width_px: 1024,
display_height_px: 768,
display_number: 1
}
},
{
type: "text_editor_20250429",
name: "str_replace_based_edit_tool"
},
{
type: "bash_20250124",
name: "bash"
}
],
"messages": [
{
role: "user",
content: "Save a picture of a cat to my desktop."
}
]
});
console.log(response);
}
// Call the function
getChatCompletionFunctions();
```
```js OpenAI NodeJS
import OpenAI from 'openai';
import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai'

const openai = new OpenAI({
apiKey: 'ANTHROPIC_API_KEY', // defaults to process.env["OPENAI_API_KEY"],
baseURL: PORTKEY_GATEWAY_URL,
defaultHeaders: createHeaders({
provider: "anthropic",
apiKey: "PORTKEY_API_KEY", // defaults to process.env["PORTKEY_API_KEY"]
strictOpenAiCompliance: false
})
});

// Generate a chat completion with streaming
async function getChatCompletionFunctions(){
const response = await openai.chat.completions.create({
model: "claude-4-opus-20250514",
max_tokens: 3000,
thinking: {
type: "enabled",
budget_tokens: 2030
},
stream: false,
tools: [
{
type: "computer",
computer: {
name: "computer_20250124", // This is the version of the tool
display_width_px: 1024,
display_height_px: 768,
display_number: 1
}
},
{
type: "text_editor_20250429",
name: "str_replace_based_edit_tool"
},
{
type: "bash_20250124",
name: "bash"
}
],
messages: [
{
role: "user",
content: "Save a picture of a cat to my desktop."
}
]
});

console.log(response)
}
await getChatCompletionFunctions();
```
```py OpenAI Python
from openai import OpenAI
from portkey_ai import PORTKEY_GATEWAY_URL, createHeaders

openai = OpenAI(
api_key='Anthropic_API_KEY',
base_url=PORTKEY_GATEWAY_URL,
default_headers=createHeaders(
provider="anthropic",
api_key="PORTKEY_API_KEY",
strict_open_ai_compliance=False
)
)


response = openai.chat.completions.create(
model="claude-4-opus-20250514",
max_tokens=3000,
thinking={
"type": "enabled",
"budget_tokens": 2030
},
stream=False,
tools=[
{
type: "computer",
computer: {
name: "computer_20250124", # This is the version of the tool
display_width_px: 1024,
display_height_px: 768,
display_number: 1
}
},
{
type: "text_editor_20250429",
name: "str_replace_based_edit_tool"
},
{
type: "bash_20250124",
name: "bash"
}
],
messages=[
{
role: "user",
content: "Save a picture of a cat to my desktop."
}
]
)

print(response)
```
```sh cURL
curl "https://api.portkey.ai/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "x-portkey-api-key: $PORTKEY_API_KEY" \
-H "x-portkey-provider: anthropic" \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "x-portkey-strict-open-ai-compliance: false" \
-d '{
"model": "claude-4-opus-20250514",
"max_tokens": 3000,
"thinking": {
"type": "enabled",
"budget_tokens": 2030
},
"stream": false,
"tools": [
{
"type": "computer",
"computer": {
"name": "computer_20250124",
"display_width_px": 1024,
"display_height_px": 768,
"display_number": 1
}
},
{
"type": "text_editor_20250429",
"name": "str_replace_based_edit_tool"
},
{
"type": "bash_20250124",
"name": "bash"
}
],
"messages": [
{
"role": "user",
"content": "Save a picture of a cat to my desktop."
}
]
}'
```
</CodeGroup>