> ## Documentation Index
> Fetch the complete documentation index at: https://docs.buntinglabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Count Features

> This endpoint counts the features in OpenStreetMap that match the given tags and reside in a bounding box.

### Request Parameters

<ParamField query="tags" type="string" placeholder="leisure=park" required>
  All features counted will satisfy each of the passed tags given by this parameter.
  `tags` is formatted as a list of tags, each like `key=value`.

  You can create a tag list by forming an array of `key=value` items and joining
  them into one string with the `&` character.

  This list must be URL encoded because both `=` and `&` are reserved characters in URI.

  An example list of tags could be `leisure=park` and `name=Westglen Park`. This matches parks
  that have the name Westglen Park. To set this parameter,
  we'll URL encode `leisure=park&name=Westglen Park`.

  Documentation on tags can be found on the [TagInfo](https://taginfo.openstreetmap.org) resource website.
</ParamField>

<ParamField query="bbox" type="string" default="None" placeholder="-97.45,37.59,-97.22,37.76">
  This is the bounding box for counted features. The coordinates (in EPSG:4326) of
  the bounding box are required to be in (minimum longitude, minimum latitude,
  maximum longitude, maximum latitude) order. Coordinates are expressed as signed floats
  joined by commas.

  An example bounding box in the US could be `-108.984375,32.026706,-103.051758,37.195331`.

  You can create a bounding box [on bboxfinder](http://bboxfinder.com), or in shapely by
  invoking the `bounds` property on a geometry.
</ParamField>

<ParamField query="api_key" type="string" placeholder="demo" required>
  Your account's API key. You can create an API key by
  [registering for an account](https://buntinglabs.com/account/register)
  and copy and paste it from your [account dashboard](https://buntinglabs.com/dashboard).
</ParamField>

### Response

When features are successfully counted, a 200 OK response will be
issued, with `Content-Type: application/json`. The body will have a property `feature_count`
which will be an unsigned integer representing the number of features matching the tags and bounding box.

<ResponseField name="feature_count" type="number">
  The number of features matching the filter tags and bounding box.
</ResponseField>

<ResponseField name="response_bytes" type="number">
  The size of the GeoJSON response, in bytes, that one would get if the same query
  were used to [extract features from OSM](/openstreetmap-api/extract).
</ResponseField>

In the event of an error, an error response will be issued, usually with a 5xx error code.
The error will be JSON-formatted, with an `error` field describing the cause.

<ResponseField name="error" type="string">
  The error message if the extract request parameters were incorrectly formatted.

  This response field will not be present if the extract succeeds.
</ResponseField>

### Data License

This API serves [OpenStreetMap](https://www.openstreetmap.org/) data, which is
freely available and is licensed under the
[Open Data Commons Open Database License (ODbL)](https://www.openstreetmap.org/copyright).

<RequestExample>
  ```bash cURL
  curl --get 'https://osm.buntinglabs.com/v1/osm/count' \
       --data "tags=name%3DMcDonald%27s" \
       --data "api_key=demo" \
       --data "bbox=-118.663330,33.580303,-117.507019,34.311681"
  ```

  ```javascript JavaScript
  const params = new URLSearchParams({
    tags: "name=McDonald's",
    api_key: "demo",
    bbox: "-118.663330,33.580303,-117.507019,34.311681"
  });

  fetch(`https://osm.buntinglabs.com/v1/osm/count?${params}`)
    .then(response => response.json())
    .then(data => console.log(data));
  ```

  ```python Python
  import requests

  params = {
    "tags": "name=McDonald's",
    "api_key": "demo",
    "bbox": "-118.663330,33.580303,-117.507019,34.311681"
  }

  response = requests.get("https://osm.buntinglabs.com/v1/osm/count", params=params)
  print(response.json())
  ```
</RequestExample>

<ResponseExample>
  ```json Response
  {
    "feature_count": 307,
    "response_bytes": 219459
  }
  ```
</ResponseExample>
