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.
API Key Authentication
The Country State City API uses API key authentication for all endpoints. Your API key must be included in every request using theX-CSCAPI-KEY header.
Get Your API Key
Register at our portal to obtain your API key.
API keys are generated instantly and are ready to use immediately.
Security Best Practices
✅ Do This
- Store API keys in environment variables
- Use server-side configurations
- Rotate keys regularly
- Monitor API key usage
- Implement proper error handling
❌ Don’t Do This
- Hard-code API keys in source code
- Commit API keys to version control
- Share API keys in plain text
- Use the same key across all environments
- Ignore authentication errors
Environment Variables
Store your API key securely using environment variables:- Node.js
- Python
- PHP
.env
app.js
Authentication Errors
When authentication fails, the API returns a401 Unauthorized status with an error message:
Common Authentication Issues
401 Unauthorized Error
401 Unauthorized Error
Headers Not Being Sent
Headers Not Being Sent
Cause: HTTP client configuration issuesSolution:
- Verify headers are properly set
- Check for typos in header name
- Ensure headers aren’t being stripped by proxies
- Test with a simple cURL command first
CORS Issues in Browser
CORS Issues in Browser
Cause: Browser blocking cross-origin requestsSolution:
- Make API calls from your server instead
- Use a proxy server for development
- Never use API keys in browser applications