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

# Stop Thread Execution

POST https://api.athenaintel.com/api/v0/threads/{thread_id}/stop

Stop a running thread execution. This will stop the thread if it is currently running and mark it as cancelled.

Reference: https://docs.athenaintel.com/api-reference/threads/stop

## Authentication

- `X-API-KEY` header (required) — API Key authentication via header

## Request

### Path parameters

- `thread_id` (string, required) — The unique thread ID to stop

## Response

### 200

Thread cancelled successfully

- `message` (string, required) — Status message about the cancellation
- `status` (string, required) — New status of the thread (always 'cancelled')
- `stopped_at` (string, required) — ISO timestamp when thread was cancelled
- `thread_id` (string, required) — The thread ID that was cancelled

## Errors

### 400 Bad Request Error

Thread is not in a stoppable state

- `map from string to any`

### 401 Unauthorized Error

Unauthorized

- `message` (string, required)

### 404 Not Found Error

Thread not found or access denied

- `message` (string, required)

### 409 Conflict Error

Thread status changed during stop

- `map from string to any`

### 422 Unprocessable Entity Error

Validation Error

- `detail` (list of ValidationError, optional)

### 500 Internal Server Error

Internal server error stopping thread

- `map from string to any`

### 502 Bad Gateway Error

Failed to signal stop to the running agent (Keryx). Please retry.

- `map from string to any`

## Types

### ValidationError

- `loc` (list of ValidationErrorLocItems, required)
- `msg` (string, required)
- `type` (string, required)
- `ctx` (ValidationErrorCtx, optional)
- `input` (any, optional)

### ValidationErrorLocItems

- string
- integer

### ValidationErrorCtx

## Examples

**Response**

```json
{
  "message": "Thread execution has been cancelled successfully.",
  "status": "cancelled",
  "stopped_at": "2024-01-15T10:45:00Z",
  "thread_id": "thread_12345-6789-abcd-efgh"
}
```

**SDK Code**

```python threads_stop_example
import requests

url = "https://api.athenaintel.com/api/v0/threads/thread_id/stop"

headers = {"X-API-KEY": "<apiKey>"}

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

print(response.json())
```

```javascript threads_stop_example
const url = 'https://api.athenaintel.com/api/v0/threads/thread_id/stop';
const options = {method: 'POST', headers: {'X-API-KEY': '<apiKey>'}};

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

```go threads_stop_example
package main

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

func main() {

	url := "https://api.athenaintel.com/api/v0/threads/thread_id/stop"

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

	req.Header.Add("X-API-KEY", "<apiKey>")

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

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

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

}
```

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

url = URI("https://api.athenaintel.com/api/v0/threads/thread_id/stop")

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

request = Net::HTTP::Post.new(url)
request["X-API-KEY"] = '<apiKey>'

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

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

HttpResponse<String> response = Unirest.post("https://api.athenaintel.com/api/v0/threads/thread_id/stop")
  .header("X-API-KEY", "<apiKey>")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.athenaintel.com/api/v0/threads/thread_id/stop', [
  'headers' => [
    'X-API-KEY' => '<apiKey>',
  ],
]);

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

```csharp threads_stop_example
using RestSharp;

var client = new RestClient("https://api.athenaintel.com/api/v0/threads/thread_id/stop");
var request = new RestRequest(Method.POST);
request.AddHeader("X-API-KEY", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift threads_stop_example
import Foundation

let headers = ["X-API-KEY": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.athenaintel.com/api/v0/threads/thread_id/stop")! 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()
```