> ## 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 within Geometry

> This endpoint searches for features matching tags inside an uploaded WKT geometry, then gives the total count and GeoJSON download size.

This API is especially useful for gauging the size of extracts before sending to clients (desktop or mobile).
Downloading and processing large amounts (10-50MB+) of GeoJSON on mobile or old devices can significantly
impact the end user experience.

<Note>This endpoint requires the [growth plan](https://buntinglabs.com/pricing) because it uses thousands of expensive geometric operations.</Note>

### Body

This request takes a single WKT geometry as the `PUT` request body (ASCII/UTF8 encoded).

Coordinates are in WGS84 (EPSG:4326) and ordered longitude, latitude. All counted geometries
will intersect with the uploaded geometry.

### 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="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 inside a polygon](/openstreetmap-api/extract-within-geometry).
</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 -X PUT \
       --url "https://osm.buntinglabs.com/v1/osm/count?api_key=YOUR_API_KEY&tags=name%3DNew%20Mexico%20State%20Capitol" \
       --data "POLYGON((-109.0448 36.9971,-109.0489 31.3337,-108.2140 31.3349,-108.2071 31.7795,-106.5317 31.7830,-106.6223 32.0034,-103.0696 31.9999,-103.0023 36.9982,-109.0475 36.9982,-109.0448 36.9971))"
  ```

  ```javascript JavaScript
  const params = new URLSearchParams({
    api_key: "YOUR_API_KEY",
    tags: "name=New Mexico State Capitol"
  });
  const body = "POLYGON((-109.0448 36.9971,-109.0489 31.3337,-108.2140 31.3349,-108.2071 31.7795,-106.5317 31.7830,-106.6223 32.0034,-103.0696 31.9999,-103.0023 36.9982,-109.0475 36.9982,-109.0448 36.9971))";

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

  ```python Python
  import requests

  params = {
    "api_key": "YOUR_API_KEY",
    "tags": "name=New Mexico State Capitol"
  }
  data = "POLYGON((-109.0448 36.9971,-109.0489 31.3337,-108.2140 31.3349,-108.2071 31.7795,-106.5317 31.7830,-106.6223 32.0034,-103.0696 31.9999,-103.0023 36.9982,-109.0475 36.9982,-109.0448 36.9971))"

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

<ResponseExample>
  ```json Response
  {
    "feature_count": 1,
    "response_bytes": 2342
  }
  ```
</ResponseExample>
