# Exports

> Write every row of a list search, or of one tile of an answer, to a CSV of up to 500,000 rows and get a download link.

Source: https://openpipe.health/docs/api/exports/

## Create an export

```http
POST /api/exports
```

Writes a full result to a CSV file and returns a link to it. Costs 10 credits.

An export is made by reference. You name something the server can already build or already holds, and the server runs the statement. The body takes one of two shapes:

| Shape | Exports |
|---|---|
| `{ "list": …, "params": { … } }` | Every row of a [list search](#export-a-list), not just a page |
| `{ "dashboard": "<id>", "tile": <index> }` | Every row of [one tile of a stored answer](#export-a-tile-of-an-answer) |

**No SQL is accepted.** The body is validated strictly: any field that is not listed on this page, including `sql`, is a `400`.

### Export a list

```sh
curl "$OPH_API/api/exports" \
  -H "Authorization: Bearer $OPH_KEY" -H "Content-Type: application/json" \
  -d '{"list": "providers", "params": {"hcpcs": "27447", "state": "TX", "min_services": 50}}'
```

`list` is `providers`, `facilities` or `groups`. `params` takes the filters of the matching search endpoint, without `limit` and `offset`, and the server builds the statement with the same code as the search. The CSV has the columns the search returns.

| `list` | `params` | Same as |
|---|---|---|
| `providers` | `q`, `state`, `city`, `specialty`, `entity` (`"I"` or `"O"`), `hcpcs`, `min_services` (number), `sort` (`payment`, `patients` or `services`) | [`GET /api/providers`](https://openpipe.health/docs/api/providers.md) |
| `facilities` | `q`, `state`, `city`, `min_beds` (integer), `ownership` (`proprietary` or `non-profit`), `private_equity` (boolean), `sort` (`beds`, `revenue` or `discharges`) | [`GET /api/facilities`](https://openpipe.health/docs/api/facilities.md) |
| `groups` | `q`, `state`, `min_members` (integer), `specialty` | [`GET /api/groups`](https://openpipe.health/docs/api/groups.md) |

Unlike the search endpoints, which take everything as query-string text, `params` is typed JSON: numbers are numbers, `private_equity` is `true` or `false`, `state` is two letters and `hcpcs` is five characters. A wrong type or an unknown filter is a `400`, not an empty result. `params` may be left out or empty, which exports the whole list up to the row limit.

### Export a tile of an answer

```sh
curl "$OPH_API/api/exports" \
  -H "Authorization: Bearer $OPH_KEY" -H "Content-Type: application/json" \
  -d '{"dashboard": "df706628-076f-4fa8-9797-c5f6028915ab", "tile": 0}'
```

| Field | Meaning |
|---|---|
| `dashboard` | The id of a stored answer in this workspace: `id` from [Ask](https://openpipe.health/docs/api/ask.md#json-mode) or from [`GET /api/dashboards`](https://openpipe.health/docs/api/saved.md#list-dashboards) |
| `tile` | The tile's position in the dashboard's `tiles` array, from 0 to 7 |

The server runs the statement stored for that tile when the question was asked, through the same [checks](https://openpipe.health/docs/receipts.md#how-model-written-sql-is-checked) as any model-written SQL, with the export's limits in place of the tile's. A tile shows at most 50 or 100 rows; the export has every row the statement returns. If the statement itself ends in a `LIMIT`, as a ranking usually does, the export stops there too.

An id that does not exist, an id from another workspace and a tile index the dashboard does not have all answer `404` with the same message.

### Response

Returns `201`.

```json
{
  "id": "2f0c6c0e-6d5b-4b55-9d0b-1f3c9d2a7e11",
  "source": { "list": "providers", "params": { "hcpcs": "27447", "state": "TX", "min_services": 50 } },
  "rows": 1384,
  "bytes": 92140,
  "truncated": false,
  "engine": "postgres",
  "ms": 180,
  "url": "https://…/2f0c6c0e-….csv?X-Amz-Signature=…",
  "expiresIn": 3600,
  "usage": { "credits": 10, "creditsUsed": 25, "creditsLimit": 100, "txid": "81250" }
}
```

| Field | Meaning |
|---|---|
| `source` | What was exported: `{ list, params }`, or `{ dashboard, tile, title }` |
| `url` | A signed download link. Anyone with the link can download the file until it expires. |
| `expiresIn` | Seconds until `url` stops working. Always 3600. |
| `truncated` | `true` if more than 500,000 rows matched and the rest were left out |
| `bytes` | Size of the CSV |
| `engine` | `postgres` or `duckdb`. See [which engine ran](https://openpipe.health/docs/receipts.md#which-engine-ran). |

The file is UTF-8 CSV with a header row. Each export gets a new file; nothing is overwritten.

### Limits and charging

| Limit | Value |
|---|---|
| Rows | 500,000 |
| Time | 30 seconds |
| Exports | 10 per minute per workspace |
| Price | 10 credits |

- The balance must cover 10 credits before anything runs, or the answer is `402`.
- The charge is made after the statement has run. An export that is rejected, fails or times out is free.

### Errors

| Status | Message | Cause |
|---|---|---|
| `400` | `Exports do not accept SQL. Send {"dashboard": …} … or {"list": …} …` | The body has a `sql` field |
| `400` | `Send {"dashboard": "<id>", "tile": <index>} … or {"list": …, "params": {...}} …` | Neither shape, or both at once |
| `400` | `Invalid export request. params.state: must be a two-letter USPS state code` | A field of the wrong type or value, or an unknown filter |
| `400` | `"list" must be "providers", "facilities" or "groups".` | |
| `400` | `The export exceeded the 30s time limit. Narrow the list with a filter.` | |
| `400` | The statement's own error | A tile whose stored statement no longer runs |
| `404` | `No stored answer with that id and tile in this workspace.` | The id is unknown, belongs to another workspace, or the dashboard has no tile at that index |
| `409` | `This tile has no result to export yet. Refresh the answer … and export it once the tile has rows.` | The tile failed when the question was asked and has never returned rows. [Refresh the dashboard](https://openpipe.health/docs/api/saved.md#refresh-a-dashboard) (free) first |
| `402`, `429` | | See [Credits](https://openpipe.health/docs/credits.md#running-out) and [Rate limits](https://openpipe.health/docs/api/errors.md#rate-limits) |

## List exports

```http
GET /api/exports
```

Returns your 20 most recent exports, newest first, each with a fresh one-hour link. Not metered.

```json
{
  "rows": [
    { "id": "2f0c6c0e-…", "rows": 1384, "bytes": 92140, "createdAt": "2026-12-05T02:14:09.000Z", "url": "https://…" }
  ]
}
```

If a link has expired, call this endpoint for a new one. You are not charged again.
