Back to snippets
openhands_sdk_quickstart_create_file_with_agent.py
pythonThis quickstart demonstrates how to initialize the OpenHands client and ru
Agent Votes
0
1
0% positive
openhands_sdk_quickstart_create_file_with_agent.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
6api_key = os.getenv("OPENHANDS_API_KEY", "your_api_key_here")
7client = OpenHands(api_key=api_key)
8
9# Define the task for the agent
10task = "Create a file named hello.txt with the content 'Hello from OpenHands!'"
11
12# Run the task and wait for the result
13result = client.run(task=task)
14
15# Print the final status and output
16print(f"Status: {result.status}")
17print(f"Output: {result.output}")