Every geographic endpoint accepts two query parameters that let you shape the response payload without changing the URL: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.
?fields=— return only the fields you ask for. Trim large list responses down to what your UI actually renders.?sort=— order list results by one or more fields, ascending or descending.
Availability: Both parameters require the Supporter plan or above. Detail endpoints accept
?fields=; list endpoints accept both ?fields= and ?sort=.Filtering and sorting are applied server-side after cache, so a typical request still takes under 10 ms even on large responses. The full payload is cached once; each
?fields=/?sort= permutation receives its own ETag.?fields= — request only the columns you need
Pass a comma-separated list of field names. The response includes only those fields, plus id (always returned so responses are never empty).
200 - Trimmed response
Behaviour rules
| Input | Behaviour |
|---|---|
| Field name is unknown for that entity | 400 Bad Request listing valid fields |
| Field is valid but outside your tier | Silently dropped — response stays a 200, that field just doesn’t appear |
Field list is empty (?fields=) | Treated as if the parameter wasn’t sent (no filtering). Still trips the Supporter+ check. |
id not in your list | Added automatically — every response item carries id |
?fields= sent multiple times | 400 Bad Request — repeated params arrive as an array, which is rejected. Send one comma-separated list. |
Per-entity field lists
The fields available to?fields= are the same as the columns returned by each endpoint (after tier gating). For the full lists, see the Tier-Based Field Availability table at the bottom of every endpoint page.
?sort= — order list results
Pass a comma-separated list of field or field:asc|desc tokens. Sort is applied to the list after filtering.
200 - Top of response
Multi-field sort
Chain fields with commas — earlier tokens take precedence on ties.Sortable fields per entity
Only fields with comparable scalar values are sortable. Translation blobs, JSON columns, and similar non-scalar columns are not.| Entity | Sortable fields |
|---|---|
| countries | id, name, iso2, iso3, population, gdp, area_sq_km, latitude, longitude |
| states | id, name, iso2, country_code, population, latitude, longitude |
| cities | id, name, state_code, country_code, population, latitude, longitude |
| regions | id, name |
| subregions | id, name, region_id |
Behaviour rules
| Input | Behaviour |
|---|---|
| Field is not in the sortable list above | 400 Bad Request listing the valid fields |
Field is sortable but outside your tier (e.g. population on Starter) | 400 Bad Request — sort surfaces a clear error instead of silently dropping, so you don’t get nonsense order |
Direction is anything other than asc or desc (case-insensitive) | 400 Bad Request |
Token has more than one : (e.g. name:asc:extra) | 400 Bad Request — guards against silently swallowed typos |
Empty ?sort= | Treated as if the parameter wasn’t sent. Still trips the Supporter+ check. |
?sort= sent on a detail endpoint (e.g. /countries/IN) | Ignored — sort only applies to list endpoints |
Numeric strings (latitude, longitude) | Compared numerically, not lexicographically. "9.0" sorts before "10.0". |
null values | Sorted first in asc, last in desc |
Whitespace
Whitespace inside a sort token is tolerated. Bothsort=name:desc and sort=name: desc are valid.
Combining ?fields= and ?sort=
You can use both together. Sort is applied first, then fields are trimmed.
?fields= — the sort happens on the full row, then unwanted columns are dropped.
Caching
| Header | Meaning |
|---|---|
Cache-Control: public, max-age=86400 | The underlying full payload is cached server-side and at the edge for 24 h |
ETag | Each ?fields=/?sort= permutation gets its own ETag so conditional requests work per-permutation |
X-Cache: HIT / MISS | Whether the underlying entity payload was served from cache. Filtering and sorting always run on the response — they’re cheap relative to network round-trip. |
Error responses
400 - Unknown field in ?fields=
400 - Non-sortable field
400 - Sort field outside tier
400 - Malformed sort token
403 - Feature not on plan
When to use which parameter
Cutting payload for a dropdown / typeahead
Cutting payload for a dropdown / typeahead
Use
?fields= to keep only the columns the UI renders. A country selector usually needs id, name, iso2, emoji — that’s roughly 1 KB per request instead of 50+ KB for the full response.Ordering a list for display
Ordering a list for display
Use
?sort= to push the work server-side. Sorting 150,000 cities by population in your client is slow and ships a lot of data you’ll discard.Both at once for a paginated table
Both at once for a paginated table
Combine
?fields= and ?sort= to ship exactly the rendered columns in the rendered order. Pair with client-side slicing for pagination.Related Topics
- Authentication — how to send
X-CSCAPI-KEY - Pricing — which plans include filtering and sorting
- Every endpoint page links back to this guide