NewConnect Claude, Cursor, 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
320ms339ms363ms593ms978ms

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 this API endpoint with all available parameters in our API playground

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

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.