Getting Started
How do I get an API key?
How do I get an API key?
- Visit app.countrystatecity.in
- Sign up or log in to your account
- Create your API key instantly
How quickly can I start using the API?
How quickly can I start using the API?
Do you provide SDKs for different programming languages?
Do you provide SDKs for different programming languages?
- JavaScript/Node.js
- Python
- PHP
- Java
- C#
- Go
- Ruby
Authentication & Security
How do I authenticate API requests?
How do I authenticate API requests?
Is it safe to use my API key in client-side applications?
Is it safe to use my API key in client-side applications?
- Use server-side applications or serverless functions
- Store API keys in environment variables
- Implement your own backend API that securely calls our API
- Use build-time environment variables for static sites
- API keys in client-side code are visible to anyone
- Malicious users could extract and abuse your API key
- This could lead to unexpected usage and charges
Can I rotate or regenerate my API key?
Can I rotate or regenerate my API key?
- Log into your account
- Navigate to API key management
- Generate a new key
- Update your applications with the new key
- Revoke the old key once migration is complete
What happens when I exceed my rate limit?
What happens when I exceed my rate limit?
429 Too Many Requests response:details.resetAt is an ISO 8601 UTC timestamp — next UTC midnight for a daily limit, the 1st of next UTC month for a monthly limit. Use it to schedule your retry instead of guessing a backoff window.Best practices for handling rate limits:- Read
details.resetAtand wait until then before retrying - Cache responses to reduce API calls
- Monitor usage proactively via the
X-CSC-Daily-Used/X-CSC-Daily-Limitresponse headers on successful requests — they aren’t returned on the429itself - Consider upgrading your plan if limits are consistently hit — plans start at $5/month for higher limits. Visit https://app.countrystatecity.in/pricing to compare plans.
What does a 403 Forbidden response mean?
What does a 403 Forbidden response mean?
403 means your API key authenticated fine, but the request itself isn’t allowed — most commonly because the endpoint, parameter, or feature you’re using isn’t included in your plan:details.requiredTier for the minimum plan that unlocks it, and details.upgradeUrl to upgrade directly.requiredTier can be null. That means there is no higher active plan the API can safely recommend, or the live plan catalogue could not be read. The gate is still real. Use details.upgradeUrl (or the pricing page) to compare the available plans.How can I optimize my API usage to stay within limits?
How can I optimize my API usage to stay within limits?
- Cache country/state data for 24+ hours (rarely changes)
- Cache city data for 12+ hours
- Implement local fallbacks for critical data
- Fetch broader datasets when possible (all countries vs individual requests)
- Use hierarchical endpoints strategically
- Batch related requests together
Data & Endpoints
What data is included for countries, states, and cities?
What data is included for countries, states, and cities?
- ISO2 and ISO3 codes
- Country name and native name
- Phone code and currency information
- Flag emoji and region information
- Latitude and longitude coordinates
- State name and ISO2 code
- Country association
- State type (state, province, region, etc.)
- Latitude and longitude coordinates
- City name and unique ID
- Country and state association
- Latitude and longitude coordinates
- Timezone information (when available)
How often is the geographical data updated?
How often is the geographical data updated?
- Country data: Updated as needed for political changes, currency updates, etc.
- State/Province data: Updated for administrative boundary changes
- City data: Regular additions and corrections based on authoritative sources
Can I get all countries, states, and cities in one request?
Can I get all countries, states, and cities in one request?
/countries- All countries/countries/{countryCode}/states- States within a country/countries/{countryCode}/cities- Cities within a country/countries/{countryCode}/states/{stateCode}/cities- Cities within a state
- Faster response times for specific data
- Reduced bandwidth usage
- Better caching opportunities
- More manageable response sizes
Do you provide latitude and longitude coordinates?
Do you provide latitude and longitude coordinates?
- ✅ Countries: Approximate center coordinates
- ✅ States/Provinces: Administrative center coordinates
- ✅ Cities: City center coordinates
Are country and currency codes standardized?
Are country and currency codes standardized?
- ISO 3166-1 alpha-2 (2-letter codes like “US”, “GB”)
- ISO 3166-1 alpha-3 (3-letter codes like “USA”, “GBR”)
- ISO 4217 standard (3-letter codes like “USD”, “EUR”)
- ITU-T E.164 standard international calling codes
Integration & Development
Can I use this API with CORS from a browser application?
Can I use this API with CORS from a browser application?
- Server-side proxy: Create your own API endpoint that calls our API
- Serverless functions: Use services like Vercel Functions, Netlify Functions, or AWS Lambda
- Static site generation: Fetch data at build time for static sites
- API keys are visible in browser developer tools
- Risk of key theft and unauthorized usage
- Potential CORS restrictions
How do I handle cascading dropdowns (Country → State → City)?
How do I handle cascading dropdowns (Country → State → City)?
Complete Example
What's the best way to handle errors in my integration?
What's the best way to handle errors in my integration?
- Always check response status codes
- Implement retry logic for temporary failures
- Provide meaningful error messages to users
- Log errors for debugging purposes
Can I cache API responses locally?
Can I cache API responses locally?
- Countries: 24-48 hours (very stable data)
- States: 12-24 hours (occasionally updated)
- Cities: 6-12 hours (more frequently updated)
Troubleshooting
Why am I getting empty results for certain countries/states?
Why am I getting empty results for certain countries/states?
- Incorrect country/state codes: Verify you’re using the correct ISO codes
- Case sensitivity: Country codes should be uppercase (“US”, not “us”)
- State code format: Use 2-letter state codes when available
- Data availability: Some territories may have incomplete subdivision data
The API response seems slow. How can I improve performance?
The API response seems slow. How can I improve performance?
- Implement caching (most important)
- Use specific endpoints instead of filtering large datasets
- Parallel requests for independent data
- CDN/Edge caching for static geographical data
- Use HTTP/2 for multiplexed requests
- Implement connection pooling
- Add response compression
I'm seeing inconsistent data between requests. What's wrong?
I'm seeing inconsistent data between requests. What's wrong?
- Browser caching: Different cache states in development
- API versioning: Ensure you’re using the same API version
- Mixed endpoints: Don’t mix different API base URLs
- Concurrent updates: Our data is occasionally updated
How do I test my API integration?
How do I test my API integration?
- Start with cURL to verify basic connectivity
- Test each endpoint individually
- Verify error handling with invalid inputs