How to beginner · 3 min read

How to use computer use with Claude API

Quick answer
To use computer use with the Claude API, enable the feature by specifying the appropriate model and system instructions in your Anthropic SDK call. Use anthropic.Anthropic client with messages.create and set system to enable computer use capabilities.

PREREQUISITES

  • Python 3.8+
  • Anthropic API key
  • pip install anthropic>=0.20

Setup

Install the Anthropic Python SDK and set your API key as an environment variable.

  • Install the SDK: pip install anthropic>=0.20
  • Set your API key in your environment: export ANTHROPIC_API_KEY='your_api_key' (Linux/macOS) or setx ANTHROPIC_API_KEY "your_api_key" (Windows)
bash
pip install anthropic>=0.20

Step by step

Use the Anthropic SDK to create a chat completion request with computer use enabled by specifying the system prompt accordingly. Below is a complete example that sends a prompt to Claude with computer use enabled.

python
import os
import anthropic

client = anthropic.Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])

system_prompt = "You are Claude, an AI assistant with computer use enabled. You can execute code and access external tools as needed."

messages = [{"role": "user", "content": "Calculate the factorial of 6 using Python."}]

response = client.messages.create(
    model="claude-3-5-haiku-20241022",
    max_tokens=500,
    system=system_prompt,
    messages=messages
)

print(response.content[0].text)
output
720

Common variations

You can customize the model or use different Anthropic models like claude-3-5-haiku-20241022 for lighter tasks. For asynchronous usage, use Python's asyncio with the Anthropic client. Streaming responses are not currently supported in the official SDK.

python
import asyncio
import os
import anthropic

async def main():
    client = anthropic.Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
    system_prompt = "You are Claude with computer use enabled."
    messages = [{"role": "user", "content": "List files in the current directory."}]
    response = await client.messages.acreate(
        model="claude-3-5-haiku-20241022",
        max_tokens=300,
        system=system_prompt,
        messages=messages
    )
    print(response.content[0].text)

asyncio.run(main())
output
file1.txt\nscript.py\ndata.csv

Troubleshooting

If you receive authentication errors, verify your ANTHROPIC_API_KEY environment variable is set correctly. If the model does not respond with computer use capabilities, ensure you are using a model version that supports it and that your system prompt explicitly enables computer use. For rate limits, consider retrying after a delay.

Key Takeaways

  • Use the Anthropic SDK with the system parameter to enable computer use in Claude.
  • Set your API key securely via environment variables to authenticate requests.
  • Choose the appropriate Claude model that supports computer use features for best results.
Verified 2026-04 · claude-3-5-haiku-20241022
Verify ↗