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

# How a search works

> Submit, poll, buy: the three steps, the three statuses and what each response carries.

A search runs in the background and takes about two to three minutes. The API gives you a `request_id`
straight away, and you ask for the outcome when you are ready.

## The three steps

#### Submit

[`POST /searches`](/api-reference/audience-search/submit-search) takes your objective and an
`Idempotency-Key`. It charges the search fee and answers `202` with the `request_id`. The response
also carries a `Location` header with the URL to poll.

#### Poll

[`GET /searches/{request_id}`](/api-reference/audience-search/get-search) tells you where the search is.
Wait 10 seconds between reads. The `Retry-After` header says so while the search is running.

#### Buy

[`POST /results`](/api-reference/audience-search/buy-results) returns the full, unmasked phone
numbers of a `DONE` search and charges for them once.

## Statuses

| Status        | Meaning                                                               | What to do                                                                           |
| ------------- | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
| `IN_PROGRESS` | The search is queued or running                                       | Keep polling                                                                         |
| `DONE`        | The search finished. `result` lists every match, phone numbers masked | Decide whether to buy                                                                |
| `FAILED`      | The search could not finish. `error` says why                         | Your fee is refunded. Submit again with a new `Idempotency-Key` if you want to retry |

`DONE` and `FAILED` never change. A failed search is a successful read, so the HTTP status is `200`.

## What a finished search shows

```json
{
  "status": "success",
  "data": {
    "request_id": "3f1c2a7e-8b41-4c1d-9a55-6d2f0e7b9c10",
    "status": "DONE",
    "created_at": "2026-12-02T09:30:00Z",
    "result": {
      "query_id": "q_7d2e1f4a",
      "matched_count": 2,
      "returned_count": 2,
      "users": [
        {
          "identifier": "u_91a0c4",
          "phone_number": "091*****728",
          "match_score": 0.93,
          "category": "investment",
          "match_explanation": "Trades gold regularly."
        }
      ],
      "search_cost_toman": 50000,
      "results_unit_price_toman": 400,
      "results_cost_toman": 800,
      "results_charged": false,
      "searched_at": "2026-12-02T09:32:41Z",
      "processing_time_ms": 161000
    },
    "error": null
  },
  "error": null
}
```

* Phone numbers show their first and last three digits. A number that cannot be masked safely comes
  back `null` or fully starred, never in the clear.
* `results_cost_toman` is what [Buy results](/api-reference/audience-search/buy-results) will charge.
* `results_charged` turns `true` once you have bought the results.
* A search that matched nobody is a real answer: `matched_count` is `0` and the fee is not refunded.

## What a failed search shows

```json
{
  "status": "success",
  "data": {
    "request_id": "3f1c2a7e-8b41-4c1d-9a55-6d2f0e7b9c10",
    "status": "FAILED",
    "created_at": "2026-12-02T09:30:00Z",
    "result": null,
    "error": {
      "code": 5021,
      "message": "The audience service failed or timed out",
      "refunded": true
    }
  },
  "error": null
}
```

| `error.code` | Meaning                                          |
| ------------ | ------------------------------------------------ |
| `5021`       | The audience service failed or timed out         |
| `5000`       | An internal failure, or the search was abandoned |

`refunded` is `true` once your fee is back in the wallet. If it is `false`, the refund is not confirmed
yet: read the search again.

## One search at a time

An account runs one search at a time. Submitting a second one while the first is `IN_PROGRESS` answers
`409` with code `4092`, and nothing is charged. Wait for the first to finish.

## How long results are kept

A finished search can be read and bought for 7 days. After that, both calls answer `404` (code `4043`).