# Socrata open-data portals · Query dataset

Search public records with Socrata open-data portals · Query dataset from Alexandria through one Spiral API key. Any question that needs actual records or aggregates from an open-data dataset (permit lookups by address or number, inspection results, 311 requests by type, counts by category). Get the portal and 4x4 from search_datasets and field names from describe_dataset first. It runs in the background and returns structured JSON. Pay as you go, with no subscription.

- Provider: Alexandria
- Category: Public Records
- Runs: In the background
- Returns: json
- Tool id: `alexandria` / `socrata-com/open-data/query_dataset`
- Page: https://spiral.ai/tools/alexandria/socrata-com/open-data/query_dataset

## Pricing

$0.00873 per call.

## Limits

- Longest queue wait: 1 hour
- Run deadline: 5 minutes
- Longest run, end to end: 225 minutes
- Largest inline input: 1 MB
- Largest input file: 2 GB
- Largest output: 5 GB

## Input

| Field | Kind | Allowed | Default | Description |
| --- | --- | --- | --- | --- |
| `portal` (required) | text |  | — | The portal: its hostname (data.cityofchicago.org, data.ny.gov, www.dallasopendata.com) or any URL on it. Must be a Socrata domain served by the Socrata Discovery API (US or EU region); anything else fails with invalid_input not_socrata_portal before the host is contacted. |
| `dataset_id` (required) | text |  | — | The dataset's Socrata 4x4 id (for example ydr8-5enu, from search_datasets) or a dataset URL on the same portal: /d/<id>, /<Category>/<Name>/<id>, /resource/<id>.json. |
| `q` | text |  | — | Full-text search across the dataset's text columns. |
| `group` | text |  | — | SoQL $group, e.g. `permit_type` (with an aggregate in select). |
| `limit` | number | 1 to 1000 | 100 | Rows per page (1-1000). A page is also cut at about 1 MB of row data; continue from next_offset. |
| `order` | text |  | — | SoQL $order, e.g. `issue_date DESC`. Defaults to the row id `:id` for stable paging (none for aggregates). |
| `where` | text |  | — | SoQL $where without the keyword. String literals in single quotes ('O''Hare' escapes a quote). E.g. `issue_date >= '2024-01-01' AND permit_type = 'PERMIT - NEW CONSTRUCTION'`, `within_circle(location, 41.88, -87.63, 500)`. |
| `offset` | number | 0 to 100000000 | 0 | Row offset (next_offset of the previous page). |
| `select` | text |  | — | SoQL $select without the keyword: columns, aliases, aggregates. E.g. `permit_, permit_type, issue_date` or `permit_type, count(*) AS n`. |

## Example

```bash
curl https://api.spiral.ai/v1/runs \
  -H "Authorization: Bearer $SPIRAL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "provider": "alexandria",
    "model": "socrata-com/open-data/query_dataset",
    "input": {
      "portal": "<portal>",
      "dataset_id": "<dataset_id>"
    }
  }'
```

Try it in the Playground: https://spiral.ai/start?provider=alexandria&model=socrata-com%2Fopen-data%2Fquery_dataset

## Common questions

### Socrata open-data portals · Query dataset

**How much does Socrata open-data portals · Query dataset cost?**

$0.00873 per call. You pay as you go from one Spiral balance, with no subscription, and a failed run is not charged.

**How do I use Socrata open-data portals · Query dataset through an API?**

Send `POST /v1/runs` with `"provider": "alexandria"`, `"model": "socrata-com/open-data/query_dataset"` and the input fields on this page, using one Spiral API key. It runs in the background: poll the run, or name a webhook to be told when it finishes.

**Do I need an account with Alexandria to use Socrata open-data portals · Query dataset?**

No. Spiral runs it on its own Alexandria account and charges your Spiral balance.

**Can my AI agent use Socrata open-data portals · Query dataset?**

Yes. Agents find and run it through Spiral's MCP server, CLI or agent skill, with the same API key.

