How to Intermediate · 3 min read

How to use computer use tool

Quick answer
Use the OpenAI Python SDK with the tools parameter specifying a computer_20241022 tool and include betas=["computer-use-2024-10-22"] in your chat completion request. This enables the AI model to perform computer interactions like screenshots or file manipulations.

PREREQUISITES

  • Python 3.8+
  • OpenAI API key (free tier works)
  • pip install openai>=1.0

Setup

Install the latest openai Python package and set your OpenAI API key as an environment variable.

bash
pip install --upgrade openai

Step by step

This example shows how to call the OpenAI chat completion API with the computer use tool enabled. The tools parameter defines the computer tool with display dimensions, and the betas parameter activates the computer use beta feature.

python
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

tools = [{
    "type": "computer_20241022",
    "name": "computer",
    "display_width_px": 1024,
    "display_height_px": 768
}]

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Take a screenshot of the desktop."}],
    tools=tools,
    betas=["computer-use-2024-10-22"]
)

print(response.choices[0].message.content)
output
Screenshot saved as screenshot.png

Common variations

  • Use different models like gpt-4o-mini or gpt-4o depending on your needs.
  • Adjust display_width_px and display_height_px to match your virtual screen size.
  • Use async calls with asyncio and await for non-blocking execution.
python
import os
import asyncio
from openai import OpenAI

async def main():
    client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
    tools = [{
        "type": "computer_20241022",
        "name": "computer",
        "display_width_px": 1280,
        "display_height_px": 720
    }]
    response = await client.chat.completions.acreate(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": "Open the calculator app."}],
        tools=tools,
        betas=["computer-use-2024-10-22"]
    )
    print(response.choices[0].message.content)

asyncio.run(main())
output
Calculator app opened successfully.

Troubleshooting

  • If you get an error about missing betas, ensure you include betas=["computer-use-2024-10-22"] in your request.
  • If the tool calls are not recognized, verify your API key has access to beta features.
  • Check that tools parameter uses "type": "computer_20241022" exactly; other values will not work.

Key Takeaways

  • Always include the computer use tool in the tools parameter with correct type and display size.
  • Enable the computer use beta by adding betas=["computer-use-2024-10-22"] in your chat completion call.
  • Use the OpenAI Python SDK v1+ with environment variable API keys for secure and up-to-date integration.
Verified 2026-04 · gpt-4o, gpt-4o-mini
Verify ↗