---
title: "Close a terminal"
description: "Ends a terminal session. With if_idle=true a shell still running programs is kept and 409 names them."
canonical: "https://www.cool.computer/docs/api-reference/terminals/close-a-terminal"
---
# Close a terminal

> Ends a terminal session. With if_idle=true a shell still running programs is kept and 409 names them.

```http
DELETE https://api.cool.computer/api/computers/{id}/terminals/{pty_id}
```

Ends a terminal session. With if_idle=true a shell still running programs is kept and 409 names them. Callers: an account bearer of the owner or of someone the computer is shared with.

## Authorization

- A Cool Computers API key, user access token, or claimed agent access token in the Authorization header. Follow https://www.cool.computer/auth.md for agent registration and https://www.cool.computer/authentication.md for direct user credentials.

## Parameters

- `id` (path, string, at least 1 characters, required): The computer's name, such as agent-atlas, or its id (cmp_…). Every caller may use either, the computer's own runtime token included.
- `pty_id` (path, string, pattern `^cmp_[0-9a-f]{24}\.pty\.[0-9a-f]{32}$`, required): Terminal identity, \<computer_id>.pty.\<32 lowercase hex>.
- `if_idle` (query, boolean): Close only when the shell runs nothing else.

## Responses

- `204`: The terminal was closed.
- `400`: Bad Request.
- `401`: Unauthorized.
- `402`: Payment Required. `pro_required`: VMs need Pro; start Pro with cool billing upgrade, or fix a lapsed subscription with cool billing portal, or use the Account page.
- `403`: Forbidden.
- `404`: Not Found. `computer_not_found`: the computer does not exist or is not yours.
- `409`: Conflict. With if_idle=true the shell still runs programs: the body is application/json naming them in running; end it without if_idle to close it anyway.
  - `application/json` (object)
    - `detail` (string, required)
    - `running` (array of string, required): The programs the shell still runs.
- `429`: Too Many Requests. If the problem code is api_request_rate_exceeded, wait for Retry-After seconds; other problem codes describe a separate limit.
- `500`: Internal Server Error.
- `502`: Bad Gateway.
- `503`: Service Unavailable. `computer_starting` means the computer is starting, or stopped and being started again; wait for Retry-After seconds, then retry. Otherwise inspect the problem code and resolution.
- `default`: A machine-readable API error with a stable code and recovery instruction.

An error is an `application/problem+json` document with a stable `code`; [API errors](/docs/api-reference/errors) says how to handle one.

## Example

```sh
curl -X DELETE "https://api.cool.computer/api/computers/$PARAM_ID/terminals/$PARAM_PTY_ID" \
  -H "authorization: Bearer $TOKEN"
```
