> For the complete documentation index, see [llms.txt](https://docs.predicthq.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.predicthq.com/api/places/get-place-hierarchies.md).

# Get place hierarchies

Get the list of hierarchies for a Place.

{% hint style="info" %}
This endpoint is in Beta.
{% endhint %}

The available filters and the response data are subject to change.

This endpoint allows you to get the full place hierarchies for:

* a given coordinate
* list of `place_id`.

A place hierarchy is a list of place identifiers and types from the `planet` level down to the `level` specified in your query (note that `level` defaults to `locality` if not specified in your query).

The response might include more than one hierarchy for a given coordinate. The reason for this is that we try to match the closest place's hierarchy but we also include the closest major city's hierarchy within a radius of 50km. This only applies if the `level` is below `region` and, if it exists, the major city's hierarchy is always the second item in the list.

For instance, if you specify `?location.origin=47.615337,-122.203981`, which is a coordinate located in Bellevue, Washington, you get two hierarchies, one for Bellevue but also one for [Seattle](https://en.wikipedia.org/wiki/Seattle).

## Get Place Hierarchies

> Return the administrative hierarchy chain for one or more places.\
> \
> Exactly one of \`location.place\_id\` or \`location.origin\` must be provided — supplying both\
> or neither returns \`400\`.\
> \
> \*\*By place ID\*\* (\`location.place\_id\`):\
> Returns stored hierarchies for the given place IDs. Results are paginated over the matched\
> places. The \`country\` filter is not applied in this mode.\
> \
> \*\*By coordinates\*\* (\`location.origin\`):\
> Finds the nearest locality to the given \`lat,lon\` and returns its hierarchy chain.\
> \
> \- When \`level\` is \`region\` or above (\`planet\`, \`continent\`, \`country\`, \`region\`),\
> &#x20; only nearby localities are considered.\
> \- When \`level\` is more granular than \`region\` (\`county\`, \`localadmin\`, \`locality\`,\
> &#x20; \`neighbourhood\`) or not specified, the search is extended to include major and metro\
> &#x20; areas within the same region as the nearest locality.\
> \- If no locality is found at the exact coordinates, a \*\*500 km fallback radius\*\* is\
> &#x20; applied before giving up.\
> \- Use \`country\` (comma-separated ISO 3166-1 alpha-2 codes) to restrict the coordinate\
> &#x20; lookup to specific countries.\
> \
> Use \`level\` to scope which hierarchy levels are returned.\
> \
> Results are paginated with \`offset\` and \`limit\`.

```json
{"openapi":"3.1.0","info":{"title":"PredictHQ Places API","version":"1.0.0"},"tags":[{"name":"Hierarchies"}],"servers":[{"url":"https://api.predicthq.com"}],"security":[{"BearerAuth":[]}],"components":{"securitySchemes":{"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"$API_KEY","description":"Enter your PredictHQ API key. The Bearer prefix is added automatically.\n\nWhen calling the API directly, send: `Authorization: Bearer <YOUR_API_KEY>` as documented at [https://docs.predicthq.com/api/overview/authenticating](https://docs.predicthq.com/api/overview/authenticating)\n"}},"schemas":{"BaseLevel":{"description":"Administrative level of a place in the Geonames hierarchy.","type":"string","enum":["planet","continent","country","region","county","localadmin","locality","neighbourhood"],"title":"BaseLevel"},"HierarchiesResponse":{"type":"object","properties":{"count":{"description":"Total number of hierarchy chains matching the query","type":"integer","title":"Count"},"next":{"description":"URL to next page","anyOf":[{"type":"string"},{"type":"null"}]},"previous":{"description":"URL to previous page","anyOf":[{"type":"string"},{"type":"null"}]},"place_hierarchies":{"description":"Array of hierarchy chains, each an ordered list from broadest to most specific administrative level","type":"array","items":{"items":{"$ref":"#/components/schemas/HierarchyDetails"},"type":"array"},"title":"Place Hierarchies"}},"required":["count","place_hierarchies"],"title":"HierarchiesResponse"},"HierarchyDetails":{"type":"object","properties":{"type":{"description":"Administrative level of this hierarchy entry, e.g. `country`, `region`, `locality`","$ref":"#/components/schemas/BaseLevel"},"place_id":{"description":"Unique PredictHQ place identifier for this hierarchy entry","type":"string","title":"Place Id"}},"required":["type","place_id"],"title":"HierarchyDetails"},"ErrorResponse":{"type":"object","properties":{"error":{"description":"Error message","type":"string","title":"Error"}},"required":["error"],"title":"ErrorResponse"},"HTTPValidationError":{"type":"object","properties":{"error":{"description":"Error summary message","type":"string","title":"Error"},"details":{"description":"List of validation error details","type":"array","items":{"$ref":"#/components/schemas/ValidationErrorDetail"},"title":"Details"}},"required":["error","details"],"title":"HTTPValidationError"},"ValidationErrorDetail":{"type":"object","properties":{"field":{"description":"The field that failed validation","type":"string","title":"Field"},"msg":{"description":"The validation error message","type":"string","title":"Message"},"type":{"description":"The type of validation error","type":"string","title":"Error Type"}},"required":["field","msg","type"],"title":"ValidationErrorDetail"},"QueryValidationError":{"type":"object","properties":{"error":{"description":"List of query parameter validation errors","type":"array","items":{"$ref":"#/components/schemas/ValidationErrorDetail"},"title":"Error"}},"required":["error"],"title":"QueryValidationError"}},"parameters":{"OffsetParam":{"name":"offset","in":"query","description":"Zero-based index of the first result to return.","required":false,"schema":{"type":"integer","default":0,"minimum":0}},"LimitParam":{"name":"limit","in":"query","description":"Maximum number of results to return per page.","required":false,"schema":{"type":"integer","default":10,"maximum":10000,"minimum":1}}}},"paths":{"/v1/places/hierarchies":{"get":{"operationId":"list_place_hierarchies","summary":"Get Place Hierarchies","description":"Return the administrative hierarchy chain for one or more places.\n\nExactly one of `location.place_id` or `location.origin` must be provided — supplying both\nor neither returns `400`.\n\n**By place ID** (`location.place_id`):\nReturns stored hierarchies for the given place IDs. Results are paginated over the matched\nplaces. The `country` filter is not applied in this mode.\n\n**By coordinates** (`location.origin`):\nFinds the nearest locality to the given `lat,lon` and returns its hierarchy chain.\n\n- When `level` is `region` or above (`planet`, `continent`, `country`, `region`),\n  only nearby localities are considered.\n- When `level` is more granular than `region` (`county`, `localadmin`, `locality`,\n  `neighbourhood`) or not specified, the search is extended to include major and metro\n  areas within the same region as the nearest locality.\n- If no locality is found at the exact coordinates, a **500 km fallback radius** is\n  applied before giving up.\n- Use `country` (comma-separated ISO 3166-1 alpha-2 codes) to restrict the coordinate\n  lookup to specific countries.\n\nUse `level` to scope which hierarchy levels are returned.\n\nResults are paginated with `offset` and `limit`.","parameters":[{"name":"location.place_id","in":"query","description":"A comma-separated list of place_id in the form `{place_id1},{place_id2}`,....\n\nPlease note that you must specify either `location.origin` or `location.place_id` in your request.\n\n\nE.g. `?location.place_id=5809844,6252001`","required":false,"schema":{"type":"array","items":{"type":"string"},"title":"Location.Place Id"},"explode":false,"style":"form"},{"name":"country","in":"query","description":"An [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) country code.\n\n\nE.g. `?country=US`","required":false,"schema":{"type":"array","items":{"type":"string"},"title":"Country"}},{"name":"level","in":"query","description":"Administrative level at which to return hierarchy results. Defaults to `locality`.\n\n- `planet` — Earth (top level)\n- `continent` — Continent (e.g. North America, Europe)\n- `country` — Sovereign nation\n- `region` — Administrative level 1 (e.g. US state, Australian state)\n- `county` — Administrative level 2 (e.g. US county)\n- `localadmin` — Local administrative area (e.g. a municipality)\n- `locality` — Populated place (e.g. a city or town)\n- `neighbourhood` — Subdivision of a locality","required":false,"schema":{"$ref":"#/components/schemas/BaseLevel","title":"Level"}},{"name":"location.origin","in":"query","description":"A coordinate in the form `{latitude},{longitude}`.\n\n\nPlease note that you must specify either `location.origin` or `location.place_id` in your request.\n\n\nE.g. `?location.origin=47.615337,-122.203981`","required":false,"schema":{"type":"string","title":"Location.Origin"},"explode":false,"style":"form"},{"$ref":"#/components/parameters/OffsetParam"},{"$ref":"#/components/parameters/LimitParam"}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HierarchiesResponse"}}}},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/ErrorResponse"},{"$ref":"#/components/schemas/HTTPValidationError"},{"$ref":"#/components/schemas/QueryValidationError"}]}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"tags":["Hierarchies"]}}}}
```

## Examples

The following examples get place hierarchies:

{% tabs %}
{% tab title="curl" %}

```bash
curl -X GET "https://api.predicthq.com/v1/places/hierarchies/?location.origin=47.615337,-122.203981" \
     -H "Accept: application/json" \
     -H "Authorization: Bearer $API_TOKEN"
```

{% endtab %}

{% tab title="python" %}

```python
import requests

response = requests.get(
    url="https://api.predicthq.com/v1/places/hierarchies/",
    headers={
      "Authorization": "Bearer $API_TOKEN",
      "Accept": "application/json"
    },
    params={
        "location.place_id": "5809844,6252001"
    }
)

print(response.json())
```

{% endtab %}
{% endtabs %}

## OpenAPI spec

Read the [OpenAPI spec for the Places API](https://api.predicthq.com/docs/?urls.primaryName=Places+API).

## Guides

The following guides are relevant to this API:

* [Understanding place hierarchies](/getting-started/guides/geolocation-guides/understanding-place-hierarchies.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.predicthq.com/api/places/get-place-hierarchies.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
