OpenHands Cloud provides a REST API that allows you to programmatically interact with OpenHands. This guide explains how to obtain an API key and use the API to start conversations and retrieve their status.
curl -X POST "https://app.all-hands.dev/api/conversations" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "initial_user_msg": "Check whether there is any incorrect information in the README.md file and send a PR to fix it if so.", "repository": "yourusername/your-repo" }'
Copy
Ask AI
import requestsapi_key = "YOUR_API_KEY"url = "https://app.all-hands.dev/api/conversations"headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}data = { "initial_user_msg": "Check whether there is any incorrect information in the README.md file and send a PR to fix it if so.", "repository": "yourusername/your-repo"}response = requests.post(url, headers=headers, json=data)conversation = response.json()print(f"Conversation Link: https://app.all-hands.dev/conversations/{conversation['conversation_id']}")print(f"Status: {conversation['status']}")
Copy
Ask AI
const apiKey = "YOUR_API_KEY";const url = "https://app.all-hands.dev/api/conversations";const headers = { "Authorization": `Bearer ${apiKey}`, "Content-Type": "application/json"};const data = { initial_user_msg: "Check whether there is any incorrect information in the README.md file and send a PR to fix it if so.", repository: "yourusername/your-repo"};async function startConversation() { try { const response = await fetch(url, { method: "POST", headers: headers, body: JSON.stringify(data) }); const conversation = await response.json(); console.log(`Conversation Link: https://app.all-hands.dev/conversations/${conversation.id}`); console.log(`Status: ${conversation.status}`); return conversation; } catch (error) { console.error("Error starting conversation:", error); }}startConversation();
If you have too many conversations running at once, older conversations will be paused to limit the number of concurrent conversations.
If you’re running into issues and need a higher limit for your use case, please contact us at contact@all-hands.dev.