> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.asi1.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.asi1.ai/_mcp/server.

# Cancel a response

POST https://api.asi1.ai/v1/responses/{response_id}/cancel

Cancels a response that is still queued or in progress, and returns it with status `cancelled`. Cancelling a response that has already finished returns it unchanged. A cancelled response's event stream ends with `response.incomplete`.

Reference: https://docs.asi1.ai/api-reference/responses/cancel-a-response

## Authentication

- `Authorization` header (bearer token, required) — Your ASI:One API key, sent as `Authorization: Bearer <api_key>`.

## Request

### Path parameters

- `response_id` (string, required) — The id of the response, as returned when it was created. A malformed id returns a 400; an id that does not exist returns a 404.

## Response

### 200

The cancelled response object.

- `id` (string, optional)
- `object` (string, optional)
- `status` (enum, optional) — Lifecycle status. `queued` and `in_progress` mean the run is still going; `completed`, `failed`, `cancelled` and `incomplete` are terminal.
  - Allowed values: `queued`, `in_progress`, `completed`, `failed`, `cancelled`, `incomplete`
- `model` (string, optional)
- `output` (list of ResponseObjectOutputItems, optional)
- `usage` (ResponseObjectUsage, optional, nullable) — Token usage for the response. Null on a response cancelled before it finished.

## Errors

### 400 Bad Request Error

The request was malformed, or a parameter was missing or invalid.

- `error` (ErrorError, required)

### 401 Unauthorized Error

The API key is missing or invalid.

- `error` (ErrorError, required)

### 404 Not Found Error

The requested model or resource does not exist.

- `error` (ErrorError, required)

### 500 Internal Server Error

An unexpected error occurred while handling the request.

- `error` (ErrorError, required)

### 502 Bad Gateway Error

An upstream service failed while handling the request.

- `error` (ErrorError, required)

### 504 Gateway Timeout Error

The model did not respond in time. Retry the request.

- `error` (ErrorError, required)

## Types

### ResponseObjectOutputItems

### ResponseObjectUsage

Token usage for the response. Null on a response cancelled before it finished.

- `input_tokens` (integer, optional)
- `input_tokens_details` (ResponseObjectUsageInputTokensDetails, optional) — Breakdown of the input tokens.
- `output_tokens` (integer, optional)
- `output_tokens_details` (ResponseObjectUsageOutputTokensDetails, optional) — Breakdown of the output tokens.
- `total_tokens` (integer, optional)

### ErrorError

- `message` (string, required) — A human-readable description of the problem.
- `status` (integer, required) — The HTTP status code, repeated in the body so it is available on streamed errors.
- `type` (string, optional) — The error category, derived from the status code. Usually one of `invalid_request_error`, `authentication_error`, `permission_error`, `rate_limit_error`, `server_error`.
- `param` (string, optional, nullable) — The request field the error relates to, when it maps to one. Nested fields use dot notation, for example `messages.0.content`.
- `code` (string, optional) — A stable machine-readable code, for example `invalid_api_key` or `model_not_found`.
- `data` (map from string to any, optional) — Additional structured detail, when available.

### ResponseObjectUsageInputTokensDetails

Breakdown of the input tokens.

- `cached_tokens` (integer, optional) — Input tokens served from cache. These still count toward `input_tokens`.

### ResponseObjectUsageOutputTokensDetails

Breakdown of the output tokens.

- `reasoning_tokens` (integer, optional) — Tokens spent reasoning before answering. `0` when the model did not reason.

## Examples

**Response**

```json
{
  "id": "resp_ffbdb0b00b324505b1a46b92d4e1f5d2",
  "object": "response",
  "status": "completed",
  "model": "asi1",
  "output": [
    {}
  ],
  "usage": {
    "input_tokens": 1,
    "input_tokens_details": {
      "cached_tokens": 1
    },
    "output_tokens": 1,
    "output_tokens_details": {
      "reasoning_tokens": 1
    },
    "total_tokens": 1
  }
}
```

**SDK Code**

```python
import requests

url = "https://api.asi1.ai/v1/responses/response_id/cancel"

headers = {"Authorization": "Bearer <token>"}

response = requests.post(url, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.asi1.ai/v1/responses/response_id/cancel';
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.asi1.ai/v1/responses/response_id/cancel"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("Authorization", "Bearer <token>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.asi1.ai/v1/responses/response_id/cancel")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.asi1.ai/v1/responses/response_id/cancel")
  .header("Authorization", "Bearer <token>")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.asi1.ai/v1/responses/response_id/cancel', [
  'headers' => [
    'Authorization' => 'Bearer <token>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.asi1.ai/v1/responses/response_id/cancel");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Authorization": "Bearer <token>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.asi1.ai/v1/responses/response_id/cancel")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```