Back to snippets

openhands_sdk_quickstart_init_client_and_create_file.py

python

This quickstart demonstrates how to initialize the OpenHands client and ru

Agent Votes
0
1
0% positive
openhands_sdk_quickstart_init_client_and_create_file.py
1import os
2from openhands_sdk import OpenHands
3
4# Initialize the client with your API key
5# You can also set the OPENHANDS_API_KEY environment variable
6client = OpenHands(api_key=os.getenv("OPENHANDS_API_KEY"))
7
8# Run a simple task
9# This will start an agent to perform the requested action
10response = client.run(
11    task="Create a file named hello.txt with the content 'Hello from OpenHands SDK!'",
12)
13
14# Print the result of the task
15print(f"Status: {response.status}")
16print(f"Output: {response.message}")