City API
The City API provides useful statistics about tens of thousands of cities around the world.
| Plan | Available Cities |
|---|---|
| Free | ~50,000 cities |
| Premium | More than 5,000,000 cities, towns, and villages |
From 8,495 users
Applications using this API
API Status
API Response Times
Average | P50 | P75 | P90 | P95 |
|---|---|---|---|---|
| 376ms | 419ms | 465ms | 815ms | 1134ms |
Similar APIs
Didn't find what you were looking for? Suggest an improvement
/v1/city GET
https://api.api-ninjas.com/v1/city
Get city data from either a name or population range. Returns a list of cities that satisfies the parameters.
Parameters
At least one of the following parameters (other than limit and offset) must be set:
nameoptionalName of city.
countryoptionalCountry filter. Must be an ISO-3166 alpha-2 country code (e.g.
US).min_latoptionalMinimum latitude coordinate.
max_latoptionalMaximum latitude coordinate.
min_lonoptionalMinimum longitude coordinate.
max_lonoptionalMaximum longitude coordinate.
min_populationoptionalMinimum city population.
max_populationoptionalMaximum city population.
limitoptional premiumHow many results to return. Must be between
1and30. Default is1. To get more than 30 results, use theoffsetparameter.offsetpremium optionalNumber of results to offset for pagination.
Headers
X-Api-KeyrequiredAPI Key associated with your account.
Response
A JSON array of objects, each containing the following fields, or an error if the request is unsuccessful.
nameThe name of the city.
latitudeLatitude coordinate of the city.
longitudeLongitude coordinate of the city.
country2-letter ISO 3166 alpha-2 country code.
populationCity population count.
is_capitalWhether the city is a capital city (
trueorfalse).
Sample Request Live Demo!
Try our APIs in the API playground
Sign up for a free API key to get started — no credit card required.
https://api.api-ninjas.com/v1/city?name=San%20FranciscoHeaders
X-Api-KeyLog in or sign up to get your API KeySample Response
Code Examples
1
2
curl -X GET "https://api.api-ninjas.com/v1/city?name=London" \
-H "X-Api-Key: YOUR_API_KEY"If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.
Frequently Asked Questions
Can I use the City API for commercial purposes?
Yes, but you must have a premium subscription. Commercial use of the City API is not permitted on the free tier. See our pricing page to choose a plan that fits your needs.How do I get an API key and start using the City API?
Sign up for a free account to instantly get your API key, then pass it in theX-Api-Keyheader on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.What happens if I exceed my quota for the month?
Your API requests will simply be denied once you hit your monthly quota — you will never be charged more than the plan you signed up for. To increase your quota, you can upgrade your plan any time on our pricing page.What happens if a request to the City API fails?
The API responds with a standard HTTP status code and a JSON error message describing the problem. See our error codes reference for the full list of codes and how to resolve each one, or contact support if you need help.What data does the City API provide and how many cities are covered?
The City API returns useful statistics for cities around the world, including each city'sname,latitude,longitude,country(ISO 3166 alpha-2 code),population, and whether it is a capital (is_capital). The free plan covers roughly 50,000 cities, while premium plans unlock more than 5,000,000 cities, towns, and villages.How do I look up cities by name, country, or population range?
Send a GET request to/v1/citywith at least one filter such asname,country(an ISO-3166 alpha-2 code likeUS), or a population range usingmin_populationandmax_population. You can also restrict results to a bounding box withmin_lat,max_lat,min_lon, andmax_lon; see our full list of APIs for related geographic tools.How many results does a single City API request return?
The endpoint returns a JSON array of matching cities, defaulting to1result. With a premium plan you can raise thelimitto between1and30per request and page through larger result sets using theoffsetparameter.What are some use cases for the City API?
The City API is useful for populating location dropdowns, finding the largest cities in a country, or mapping cities within a geographic region by latitude and longitude. It pairs well with the Country API for national statistics, the Geocoding API to convert place names to coordinates, and the Weather API to fetch conditions for a returned city'slatitudeandlongitude.