# POST /lead-gen/searches/:search_id/cancel

**Resource:** [Lead Generation](./lead-gen.md)  
**MCP tool:** `lead_gen_cancel_search`  
**Scopes:** `lead-gen:write`  
**Write operation:** yes

Force-cancel a running lead-gen search and refund any credits that were charged. Use this to clear searches stuck in "running" — typically because the dispatch edge function timed out / was killed before it could mark the row completed or failed, leaving the row orphaned and the user's credits locked up. Only searches in status="running" can be cancelled; completed/failed/cancelled rows return a 400. On success the row flips to status="cancelled" with error_message="Cancelled by user" and credits_charged is refunded via a "refund" ledger transaction. Response includes credits_refunded and credit_balance_after for confirmation.

## Parameters

| Name | In | Type | Required | Description |
|------|----|------|----------|-------------|
| `search_id` | path | string | yes |  |

## Request example

```bash
curl -X POST   "https://api.trustpager.com/functions/v1/api/v1/lead-gen/searches/:search_id/cancel"   -H "Authorization: Bearer YOUR_API_KEY"
```

---
Base URL: `https://api.trustpager.com/functions/v1/api/v1` — Auth: `Authorization: Bearer YOUR_API_KEY`