> ## Documentation Index
> Fetch the complete documentation index at: https://docs.countrystatecity.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Make your first request and build a country, state and city picker in under five minutes

This guide takes you from zero to a working cascading location picker, the most common way developers use the CSC API.

**1. Get your API key**

Sign up at [app.countrystatecity.in](https://app.countrystatecity.in) and copy your key from the dashboard. The free Community plan is enough for this guide.

> [!WARNING]
>
> Keep your key on the server. See [Authentication](https://docs.countrystatecity.in/api/authentication.md) for safe usage patterns.

**2. Make your first request**

Every request needs the `X-CSCAPI-KEY` header.

```bash theme={null}
curl 'https://api.countrystatecity.in/v1/countries' \
  -H 'X-CSCAPI-KEY: YOUR_API_KEY'
```

You will get back an array of countries, each with an `iso2` code such as `IN` or `US`.

**3. Load states for the selected country**

Pass the country's `iso2` code in the path.

```bash theme={null}
curl 'https://api.countrystatecity.in/v1/countries/IN/states' \
  -H 'X-CSCAPI-KEY: YOUR_API_KEY'
```

**4. Load cities for the selected state**

Pass both the country and state `iso2` codes.

```bash theme={null}
curl 'https://api.countrystatecity.in/v1/countries/IN/states/MH/cities' \
  -H 'X-CSCAPI-KEY: YOUR_API_KEY'
```

## Put it together

```javascript Node.js theme={null}
const BASE = 'https://api.countrystatecity.in/v1';
const apiKey = process.env.CSC_API_KEY;
if (!apiKey) throw new Error('Set CSC_API_KEY on the server');
const headers = { 'X-CSCAPI-KEY': apiKey };

/** Read a JSON response, failing on HTTP errors. */
async function get(path) {
  const response = await fetch(`${BASE}${path}`, { headers });
  if (!response.ok) throw new Error(`CSC request failed: HTTP ${response.status}`);
  return response.json();
}

const countries = await get('/countries');
const states = await get('/countries/IN/states');
const cities = await get('/countries/IN/states/MH/cities');

console.log(countries.length, states.length, cities.length);
```

```python Python theme={null}
import os
import requests

BASE = "https://api.countrystatecity.in/v1"
HEADERS = {"X-CSCAPI-KEY": os.environ["CSC_API_KEY"]}

def get(path):
    """Read JSON after checking the HTTP response."""
    response = requests.get(f"{BASE}{path}", headers=HEADERS, timeout=30)
    response.raise_for_status()
    return response.json()

countries = get("/countries")
states = get("/countries/IN/states")
cities = get("/countries/IN/states/MH/cities")

print(len(countries), len(states), len(cities))
```

```php PHP theme={null}
<?php
$base = 'https://api.countrystatecity.in/v1';
$ctx = stream_context_create(['http' => [
    'header' => 'X-CSCAPI-KEY: ' . getenv('CSC_API_KEY'),
]]);

$get = fn ($path) => json_decode(file_get_contents($base . $path, false, $ctx), true);

$countries = $get('/countries');
$states = $get('/countries/IN/states');
$cities = $get('/countries/IN/states/MH/cities');
```

> [!TIP]
>
> Country, state and city lists change rarely. Cache responses for at least 24 hours to stay well within your plan's rate limits. See [Errors and Rate Limits](https://docs.countrystatecity.in/api/errors.md).

## Next steps

> [card] [Try it in the playground](https://docs.countrystatecity.in/api/endpoints/get-all-countries.md)
>
> Send live requests from any endpoint page with your own key.

> [card] [Use an SDK](https://docs.countrystatecity.in/api/sdks.md)
>
> Official npm, Python and TypeScript packages.

> [card] [Trim responses](https://docs.countrystatecity.in/api/field-filtering-and-sorting.md)
>
> Return only the fields you need and sort results.

> [card] [Self-host the data](https://docs.countrystatecity.in/database/overview.md)
>
> Prefer no API calls? Download the full database.


## Related topics

- [Country State City API](https://docs.countrystatecity.in/api/introduction.md)
- [TypeScript SDK](https://docs.countrystatecity.in/api/sdks/typescript.md)
- [Country State City](https://docs.countrystatecity.in/index.md)
- [Database Overview](https://docs.countrystatecity.in/database/overview.md)
- [CSC Tools Overview](https://docs.countrystatecity.in/tools/overview.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.