curl -sS -X POST "$BMA_BASE_URL/v1/terminal_sessions/tsn_wi5at5l2xlf3hmcmnacvfsawnp/close" \
-H "x-api-key: $BMA_API_KEY" \
-H "bma-workspace-id: $BMA_PROJECT_ID"{
"type": "terminal_session",
"id": "tsn_wi5at5l2xlf3hmcmnacvfsawnp",
"org_id": "org_ibwqit3njkb2mwquggpsns65sx",
"project_id": "proj_mvn54w6ybm4sytmuddlydotvmt",
"machine_id": "mch_5litd6cy6bqsd6apzqg53ptiso",
"state": "closed",
"shell": "/bin/bash",
"cwd": "/home/user",
"cols": 120,
"rows": 32,
"created_at": "2026-11-24T07:30:11.802546Z",
"closed_at": "2026-11-24T07:41:56.27349Z",
"close_reason": "closed_by_user"
}{
"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>"
}Close a terminal session
Closes a terminal session and answers it: the session is stored closed (close_reason closed_by_user) first, then the machine’s executor is told to end its PTY and the session’s open connections are ended and its tickets refused. A closed session is never attached again; open a new one instead. Closing an ended session answers it unchanged and repeats the executor and connection cleanup, so a close that answered an error after the session was stored closed (such as 409 machine_offline) is finished by retrying it. No request body is read.
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 session’s workspace (bma-workspace-id or anthropic-workspace-id, else the credential’s default workspace); organization owners and admins act as workspace admins. Viewers are refused.
Limits:
- No limits specific to this endpoint.
- 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 | 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 | 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 terminals. | Use a credential with the required role or access; retrying with the same credential will not help. |
| 409 | conflict_error | executor_rejected | The session is stored closed but the machine’s executor refused to end its PTY. | Read the message for the executor’s reason, change what it names, then send the request again. |
| 409 | conflict_error | machine_offline | The session is stored closed but the machine’s executor is not connected to end its PTY; retry the close. | Retry the same request after a short delay. |
curl -sS -X POST "$BMA_BASE_URL/v1/terminal_sessions/tsn_wi5at5l2xlf3hmcmnacvfsawnp/close" \
-H "x-api-key: $BMA_API_KEY" \
-H "bma-workspace-id: $BMA_PROJECT_ID"{
"type": "terminal_session",
"id": "tsn_wi5at5l2xlf3hmcmnacvfsawnp",
"org_id": "org_ibwqit3njkb2mwquggpsns65sx",
"project_id": "proj_mvn54w6ybm4sytmuddlydotvmt",
"machine_id": "mch_5litd6cy6bqsd6apzqg53ptiso",
"state": "closed",
"shell": "/bin/bash",
"cwd": "/home/user",
"cols": 120,
"rows": 32,
"created_at": "2026-11-24T07:30:11.802546Z",
"closed_at": "2026-11-24T07:41:56.27349Z",
"close_reason": "closed_by_user"
}{
"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
Path Parameters
Response
The closed 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).