Obtaining an API Key
To use the OpenHands Cloud API, you’ll need to generate an API key:- Log in to your OpenHands Cloud account.
- Navigate to the Settings > API Keys page.
- Click
Create API Key. - Give your key a descriptive name (Example: “Development” or “Production”) and select
Create. - Copy the generated API key and store it securely. It will only be shown once.
API Usage Example (V1)
Starting a New Conversation
To start a new conversation with OpenHands to perform a task, make a POST request to the V1 app-conversations endpoint.- cURL
- Python (with requests)
- TypeScript/JavaScript (with fetch)
Response
The API will return a JSON object with details about the conversation start task:status field indicates the current state of the conversation startup process:
WORKING- Initial processingWAITING_FOR_SANDBOX- Waiting for sandbox to be readyPREPARING_REPOSITORY- Cloning and setting up the repositorySETTING_UP_SKILLS- Configuring agent skills and toolsREADY- Conversation is ready to useERROR- An error occurred during startup
- You provided an invalid API key.
- You provided the wrong repository name.
- You don’t have access to the repository.
Streaming Conversation Start (Optional)
For real-time updates during conversation startup, you can use the streaming endpoint:Streaming Response
The endpoint streams a JSON array incrementally. Each element represents a status update:Checking Conversation Status
After starting a conversation, you can check its status to monitor whether the agent has completed its task.The examples below show basic polling patterns. For production use, add proper error handling,
exponential backoff, and handle network failures gracefully.
Step 1: Check Start Task Status
When you start a conversation, you receive a start task ID. Poll this endpoint untilstatus becomes READY and app_conversation_id is available:
Step 2: Check Conversation Execution Status
Once you have theapp_conversation_id, check whether the agent has finished its task:
- cURL
- Python (with requests)
Status Fields
sandbox_status - The state of the sandbox environment:
STARTING- Sandbox is being created. Action: Continue polling.RUNNING- Sandbox is active. Action: Checkexecution_statusfor task progress.PAUSED- Sandbox is paused (due to rate limits or user action). Action: The sandbox will resume automatically when resources are available, or resume manually via the UI.ERROR- Sandbox encountered an error. Action: This is a terminal state. Check conversation details in the UI for error information.MISSING- Sandbox was deleted. Action: This is a terminal state. Start a new conversation if needed.
execution_status - The state of the agent’s task (available when sandbox is RUNNING):
idle- Agent is ready to receive tasks. Action: Continue polling if task was recently submitted.running- Agent is actively working. Action: Continue polling.paused- Execution is paused. Action: Continue polling; will resume automatically.waiting_for_confirmation- Agent is waiting for user confirmation. Action: This is a blocking state. The agent needs user input via the UI to proceed. Your polling loop should treat this as a terminal state or alert the user.finished- Agent has completed the task. Action: Terminal state. Task is done successfully.error- Agent encountered an error. Action: Terminal state. Check conversation in UI for error details.stuck- Agent is stuck and unable to proceed. Action: Terminal state. Manual intervention may be required.
Terminal states that should exit your polling loop:
finished, error, stuck, waiting_for_confirmation.
The waiting_for_confirmation state requires user action through the UI before the agent can continue.Complete Polling Example
Here’s a complete example that starts a conversation and polls until completion:Listing All Conversations
To list all your conversations, use the search endpoint:- cURL
- Python (with requests)
The search endpoint returns conversations in the
items array. Use next_page_id
for pagination if you have more conversations than the limit.Rate Limits
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.Migrating from V0 to V1 API
Key Differences
Migration Steps
-
Update the endpoint URL: Change from
/api/conversationsto/api/v1/app-conversations -
Update the request body:
- Change
repositorytoselected_repository - Change
initial_user_msg(string) toinitial_message(object with content array):
- Change
-
Update response handling: The V1 API returns a start task object. The conversation ID is in the
app_conversation_idfield (available when status isREADY), or use theidfield for the start task ID.
Legacy API (V0) - Deprecated
Starting a New Conversation (V0)
- cURL
- Python (with requests)
- TypeScript/JavaScript (with fetch)

