curl -sS -X POST "$BMA_BASE_URL/v1/terminal_sessions" \
-H "x-api-key: $BMA_API_KEY" \
-H "bma-workspace-id: $BMA_PROJECT_ID" \
-H "Idempotency-Key: $(uuidgen)" \
-H "content-type: application/json" \
-d '{
"machine_id": "mch_5litd6cy6bqsd6apzqg53ptiso",
"shell": "/bin/bash",
"cwd": "/home/user",
"cols": 120,
"rows": 32
}'{
"type": "terminal_session",
"id": "tsn_wi5at5l2xlf3hmcmnacvfsawnp",
"org_id": "org_ibwqit3njkb2mwquggpsns65sx",
"project_id": "proj_mvn54w6ybm4sytmuddlydotvmt",
"machine_id": "mch_5litd6cy6bqsd6apzqg53ptiso",
"state": "starting",
"shell": "/bin/bash",
"cwd": "/home/user",
"cols": 120,
"rows": 32,
"created_at": "2026-11-24T07:30:11.802546Z"
}{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "<string>",
"code": "<string>",
"bma_error_code": "<string>"
},
"request_id": "<string>"
}{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "<string>",
"code": "<string>",
"bma_error_code": "<string>"
},
"request_id": "<string>"
}Open a terminal session (body machine_id)
Records a new terminal session on a machine whose executor serves terminals and answers it in state starting. A paused machine is woken first and the call waits for a machine that is still starting. No shell runs yet: the PTY is opened on the machine when a client first connects with a ticket (POST /v1/terminal_sessions//tickets), which makes the session running. Every call opens a new session; a machine can have several. A session no client has been attached to for the idle timeout (10 minutes by default) is closed with close_reason idle_expired. Idempotency-Key is honored: a retry with the same key and body replays the first session, the same key with another body is a 400; SDK retries without a key (X-Stainless-Retry-Count 1 or more) are merged with the first request.
Authorization: Organization API key (x-api-key: bma_org_v1_...), personal access token or OAuth access token (Authorization: Bearer ...), or a signed-in dashboard session; a user credential that is not bound to one organization names it with bma-organization-id. The workspace role admin, developer or operator in the request’s workspace (bma-workspace-id or anthropic-workspace-id, else the credential’s default workspace); organization owners and admins act as workspace admins. The machine must be one the caller can see in the organization; others answer 404.
Limits:
- Request body: at most 64 KiB.
cols: 1 to 4096 (default 80);rows: 1 to 512 (default 24).shellandcwd: at most 4096 bytes each.- Waiting for a paused or starting machine: within a 20-second budget, answered at least 2 seconds before it ends.
Idempotency-Key: 1 to 255 visible ASCII characters; a completed key replays its answer for 24 hours.- Rate limit: one request of the organization’s write budget (Rate limits).
Errors (besides the common errors (401 authentication, 429 rate_limited, 500)):
| Status | error.type | error.code | Cause | Fix |
|---|---|---|---|---|
| 400 | invalid_request_error | hands_unavailable | The machine has failed or is being deleted. | Correct the request as the message describes and send it again; the same request will keep failing. |
| 400 | invalid_request_error | idempotency_key_reused | The Idempotency-Key was used with a different request. | Correct the request as the message describes and send it again; the same request will keep failing. |
| 400 | invalid_request_error | invalid_idempotency_key | Idempotency-Key is not 1 to 255 visible ASCII characters. | Correct the request as the message describes and send it again; the same request will keep failing. |
| 400 | invalid_request_error | invalid_request | cols or rows is out of range, or shell or cwd is longer than 4096 bytes. | Correct the request as the message describes and send it again; the same request will keep failing. |
| 400 | invalid_request_error | organization_required | A user credential that belongs to no single organization names none with bma-organization-id. | Correct the request as the message describes and send it again; the same request will keep failing. |
| 400 | invalid_request_error | project_required | The credential can use several workspaces and the request names none. | Correct the request as the message describes and send it again; the same request will keep failing. |
| 400 | invalid_request_error | terminal_unsupported | The machine’s executor serves no terminals. | Correct the request as the message describes and send it again; the same request will keep failing. |
| 400 | invalid_request_error | workspace_id_conflict | bma-workspace-id and anthropic-workspace-id name different workspaces. | Correct the request as the message describes and send it again; the same request will keep failing. |
| 403 | permission_error | permission_denied | The credential cannot call this API, or the workspace role does not allow opening a terminal. | Use a credential with the required role or access; retrying with the same credential will not help. |
| 404 | not_found_error | not_found | No machine with machine_id exists that the caller can see. | Check the ID and the organization or workspace it belongs to; do not retry the same request. |
| 409 | conflict_error | idempotency_key_in_use | A request with the same Idempotency-Key is still being processed. | Retry the same request after a short delay. |
| 409 | conflict_error | machine_executor_unavailable | The machine’s executor did not connect after the platform restarted it. | Wait for the Retry-After interval, then retry; the next use restarts the executor again. |
| 409 | conflict_error | machine_rebuilding | The machine is being rebuilt onto a new template. | Wait for the Retry-After interval, then retry. |
| 409 | conflict_error | machine_starting | The machine or its executor is still starting after the wait; retry after Retry-After. | Wait for the Retry-After interval, then retry. |
| 409 | conflict_error | machine_state_conflict | The machine is in a state that cannot be woken. | Re-read the resource, resolve the conflicting state, then send the request again. |
| 409 | conflict_error | machine_unavailable | The machine did not become ready within the wait. | Re-read the resource, resolve the conflicting state, then send the request again. |
curl -sS -X POST "$BMA_BASE_URL/v1/terminal_sessions" \
-H "x-api-key: $BMA_API_KEY" \
-H "bma-workspace-id: $BMA_PROJECT_ID" \
-H "Idempotency-Key: $(uuidgen)" \
-H "content-type: application/json" \
-d '{
"machine_id": "mch_5litd6cy6bqsd6apzqg53ptiso",
"shell": "/bin/bash",
"cwd": "/home/user",
"cols": 120,
"rows": 32
}'{
"type": "terminal_session",
"id": "tsn_wi5at5l2xlf3hmcmnacvfsawnp",
"org_id": "org_ibwqit3njkb2mwquggpsns65sx",
"project_id": "proj_mvn54w6ybm4sytmuddlydotvmt",
"machine_id": "mch_5litd6cy6bqsd6apzqg53ptiso",
"state": "starting",
"shell": "/bin/bash",
"cwd": "/home/user",
"cols": 120,
"rows": 32,
"created_at": "2026-11-24T07:30:11.802546Z"
}{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "<string>",
"code": "<string>",
"bma_error_code": "<string>"
},
"request_id": "<string>"
}{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "<string>",
"code": "<string>",
"bma_error_code": "<string>"
},
"request_id": "<string>"
}Headers
Body
Body of a terminal session create. Unknown fields are ignored.
Response
The new terminal session.
starting until a client first attaches and the PTY opens, then running; closed once it ended (closed, exited or idle); failed when an attach found the PTY replaced (close_reason pty_recreated). closing is not used.
starting, running, closing, closed, failed Why the session ended, absent while open. closed_by_user (the close endpoint), exited (the shell exited), idle_expired (no client attached for the idle timeout), pty_recreated (the PTY was replaced, state failed), or a reason the machine reported when it ended the PTY (closed when it gave none).