NewConnect Claude, Gemini, ChatGPT, and other AI agents to API Ninjas via our MCP server

City API

The City API provides useful statistics about tens of thousands of cities around the world.

PlanAvailable Cities
Free~50,000 cities
PremiumMore than 5,000,000 cities, towns, and villages
(4.7)

From 8,495 users

300+

Applications using this API

API Status

Online - All Systems Operational

API Response Times

Average
P50
P75
P90
P95
376ms419ms465ms815ms1134ms

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:

  • name  optional

    Name of city.

  • country  optional

    Country filter. Must be an ISO-3166 alpha-2 country code (e.g. US).

  • min_lat  optional

    Minimum latitude coordinate.

  • max_lat  optional

    Maximum latitude coordinate.

  • min_lon  optional

    Minimum longitude coordinate.

  • max_lon  optional

    Maximum longitude coordinate.

  • min_population  optional

    Minimum city population.

  • max_population  optional

    Maximum city population.

  • limit  optional  premium

    How many results to return. Must be between 1 and 30. Default is 1. To get more than 30 results, use the offset parameter.

  • offset  premium  optional

    Number of results to offset for pagination.

Headers

  • X-Api-Key  required

    API Key associated with your account.

Response

A JSON array of objects, each containing the following fields, or an error if the request is unsuccessful.

  • name

    The name of the city.

  • latitude

    Latitude coordinate of the city.

  • longitude

    Longitude coordinate of the city.

  • country

    2-letter ISO 3166 alpha-2 country code.

  • population

    City population count.

  • is_capital

    Whether the city is a capital city (true or false).

Sample Request Live Demo!

name
country
min_population
max_population
limit premium

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%20Francisco

Headers

X-Api-KeyLog in or sign up to get your API Key

Sample Response

JSON
[
    {
      name:"San Francisco",
      latitude:37.7562,
      longitude:-122.443,
      country:"US",
      population:3592294,
      is_capital:false
    }
]

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

  • 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.
  • Sign up for a free account to instantly get your API key, then pass it in the X-Api-Key header on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.
  • 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.
  • 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.
  • The City API returns useful statistics for cities around the world, including each city's name, 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.
  • Send a GET request to /v1/city with at least one filter such as name, country (an ISO-3166 alpha-2 code like US), or a population range using min_population and max_population. You can also restrict results to a bounding box with min_lat, max_lat, min_lon, and max_lon; see our full list of APIs for related geographic tools.
  • The endpoint returns a JSON array of matching cities, defaulting to 1 result. With a premium plan you can raise the limit to between 1 and 30 per request and page through larger result sets using the offset parameter.
  • 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's latitude and longitude.