REST API Documentation

Complete API reference for countries, cities, rankings and search endpoints. Code examples in JavaScript and Python. Authentication, rate limits. Free tier available.

Base URL

https://bamwor.com/api/v1

Authentication

Include your API key in every request using one of these methods:

Header
X-API-Key: bw_live_your_key_here
# or
Authorization: Bearer bw_live_your_key_here

Anonymous requests (no key) are allowed with lower limits: 10/min, 100/day.

Anonymous responses: restricted stats return { "value": null, "restricted": true } instead of actual values. Free stats (population, area_sq_km, gdp_per_capita) include "restricted": false. Get a free API key for full access to all 25+ statistics.

Rate Limits

PlanPer minutePer dayPrice
Anonymous10100Free (no key)
Free301,000$0
Pro6010,000$19.99/mo
Premium30050,000$39.99/mo
Enterprise600500,000Custom

Rate limit headers are included in every response: X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset.

Anonymous requests have a mandatory 5-second cooldown between requests. Get a free API key at /developers/quickstart for instant access with no cooldown.

Pagination

Paginated endpoints accept page and per_page query parameters. Default: page=1, per_page=25 (max 100).

Response format
{
  "data": [...],
  "pagination": {
    "page": 1,
    "per_page": 25,
    "total": 261,
    "total_pages": 11
  },
  "meta": {
    "request_id": "req_abc123",
    "timestamp": "2026-03-11T10:00:00.000Z",
    "cached": true
  }
}

Error Handling

Error response
{
  "error": {
    "code": "NOT_FOUND",
    "message": "Country \"xyz\" not found.",
    "status": 404
  },
  "meta": {
    "request_id": "req_abc123",
    "timestamp": "2026-03-11T10:00:00.000Z"
  }
}
StatusCodeDescription
400BAD_REQUESTInvalid parameters
401INVALID_API_KEYInvalid or missing API key
403API_KEY_DISABLEDAPI key has been disabled
404NOT_FOUNDResource not found
429RATE_LIMIT_EXCEEDEDToo many requests
500INTERNAL_ERRORServer error

Endpoint Reference

GET/api/v1/countries

Paginated list of all countries with basic stats.

NameTypeRequiredDescription
pageintegerNoPage number (default: 1)
per_pageintegerNoItems per page (default: 25, max: 100)
regionstringNoFilter by region slug (e.g. south-america)
sortstringNoSort by: name, population, area (default: name)
curl
curl -H "X-API-Key: bw_live_your_key" \
  "https://bamwor.com/api/v1/countries?sort=population&per_page=5"
Response
{
  "data": [
    {
      "iso_code": "CH",
      "names": { "en": "China", "es": "China", "pt": "China", "it": "Cina" },
      "slugs": { "en": "china", "es": "china", "pt": "china", "it": "cina" },
      "coordinates": { "latitude": 35.0, "longitude": 105.0 },
      "region": { "slug": "east-southeast-asia", "name": "East & Southeast Asia" },
      "population": 1416043270,
      "area_sq_km": 9596960,
      "category": "country"
    }, ...
  ],
  "pagination": { "page": 1, "per_page": 5, "total": 261, "total_pages": 53 }
}
GET/api/v1/countries/:slug

Full country detail with all statistics.

NameTypeRequiredDescription
slugstringYesCountry slug in any language (e.g. argentina, japon), ISO code (AR, JP, US), or alias (usa, uk, vatican-city, uae)
curl
curl -H "X-API-Key: bw_live_your_key" \
  https://bamwor.com/api/v1/countries/japan
Response
{
  "data": {
    "gec_code": "JA",
    "iso_code": "JA",
    "names": { "en": "Japan", "es": "Japón", "pt": "Japão", "it": "Giappone" },
    "population": 123719238,
    "population_year": 2025,
    "area_sq_km": 377915,
    "stats": {
      "population": { "value": 123719238, "unit": "people", "year": 2025, "source": "CIA World Factbook" },
      "gdp_ppp": { "value": 6025000000000, "unit": "USD", "year": 2023, "source": "CIA World Factbook" },
      "ibeu": { "value": 56.32, "unit": "index score", "year": 2026, "source": "Bamwor Proprietary Index" },
      ...
    },
    "flag_url": "/flags/ja.png",
    "map_url": "/maps/ja.png"
  }
}
// gec_code: FIPS 10-4 country code (2 chars, differs from ISO 3166-1)
// population_year: year of the population estimate
// stats include 9 Bamwor indices (ibeu, ibcp, ibda, ibcx, ibee, ibfm, ibdi, ibed, ibsa)
GET/api/v1/countries/:slug/cities

Paginated cities within a country.

NameTypeRequiredDescription
slugstringYesCountry slug
sortstringNoSort by: population, name (default: population)
min_populationintegerNoMinimum population filter
provincestringNoFilter by province/admin1 name
pageintegerNoPage number
per_pageintegerNoItems per page (max: 100)
curl
curl -H "X-API-Key: bw_live_your_key" \
  "https://bamwor.com/api/v1/countries/brazil/cities?min_population=500000"
Response
{
  "data": [
    {
      "id": 3448439,
      "names": { "en": "São Paulo", "es": "São Paulo", ... },
      "coordinates": { "latitude": -23.5475, "longitude": -46.6361 },
      "population": 11967825,
      "province": "São Paulo"
    }, ...
  ],
  "pagination": { "page": 1, "per_page": 25, "total": 17 }
}
GET/api/v1/cities/:id

City detail by GeoNames ID.

NameTypeRequiredDescription
idintegerYesGeoNames ID (e.g. 3435910 for Buenos Aires)
curl
curl -H "X-API-Key: bw_live_your_key" \
  https://bamwor.com/api/v1/cities/3435910
Response
{
  "data": {
    "id": 3435910,
    "names": { "en": "Buenos Aires", ... },
    "coordinates": { "latitude": -34.6132, "longitude": -58.3772 },
    "population": 13076300,
    "elevation": 31,
    "timezone": "America/Argentina/Buenos_Aires",
    "province": "Buenos Aires F.D.",
    "country": { "name": "Argentina", "slug": "argentina", "iso_code": "AR" }
  }
}
GET/api/v1/cities/:id/nearby

Find cities near a given city using PostGIS radius search.

NameTypeRequiredDescription
idintegerYesOrigin city GeoNames ID
radiusintegerNoRadius in km (default: 50, max: 200)
limitintegerNoMax results (default: 10, max: 50)
curl
curl -H "X-API-Key: bw_live_your_key" \
  "https://bamwor.com/api/v1/cities/3435910/nearby?radius=100&limit=5"
Response
{
  "data": [
    {
      "id": 3432043,
      "names": { "en": "La Plata", ... },
      "coordinates": { "latitude": -34.9215, "longitude": -57.9545 },
      "population": 694167,
      "distance_km": 56.2
    }, ...
  ],
  "pagination": { "page": 1, "per_page": 5, "total": 5, "total_pages": 1 }
}
GET/api/v1/search

Search countries and cities by name in any of the 4 supported languages.

NameTypeRequiredDescription
qstringYesSearch query (min 2 chars, max 100)
typestringNoFilter: all, country, city (default: all)
limitintegerNoMax results (default: 20, max: 50)
curl
curl -H "X-API-Key: bw_live_your_key" \
  "https://bamwor.com/api/v1/search?q=tokyo&type=city"
Response
{
  "data": [
    {
      "type": "city",
      "id": 1850147,
      "names": { "en": "Tokyo", "es": "Tokio", "pt": "Tóquio", "it": "Tokyo" },
      "coordinates": { "latitude": 35.6895, "longitude": 139.6917 },
      "population": 8336599,
      "country_code": "JA"
    }
  ]
}
GET/api/v1/rankings

List all available ranking metrics.

curl
curl -H "X-API-Key: bw_live_your_key" \
  https://bamwor.com/api/v1/rankings
Response
{
  "data": [
    { "slug": "population", "label": "Population", "url": "/api/v1/rankings/population" },
    { "slug": "area", "label": "Area (sq km)", "url": "/api/v1/rankings/area" },
    { "slug": "gdp", "label": "GDP (nominal)", "url": "/api/v1/rankings/gdp" },
    { "slug": "hdi", "label": "Human Development Index", "url": "/api/v1/rankings/hdi" },
    ...
  ]
}
GET/api/v1/rankings/:slug

Paginated country ranking by a specific metric.

NameTypeRequiredDescription
slugstringYesMetric: population, area, density, gdp, gdp-per-capita, hdi, life-expectancy, ibeu, ibcp, ibda, ibcx, ibee, ibfm, ibdi, ibed, ibsa (16 total)
regionstringNoFilter by region slug
countries_onlybooleanNoWhen true, excludes non-country entities (World, EU, territories). Default: false
pageintegerNoPage number
per_pageintegerNoItems per page (default: 50)
curl
curl -H "X-API-Key: bw_live_your_key" \
  "https://bamwor.com/api/v1/rankings/population?region=south-america&per_page=5"
Response
{
  "data": [
    {
      "rank": 1,
      "country": {
        "iso_code": "BR",
        "names": { "en": "Brazil", ... },
        "region": { "slug": "south-america", "name": "South America" }
      },
      "value": 220051512,
      "unit": null,
      "year": 2025
    }, ...
  ],
  "pagination": { "page": 1, "per_page": 5, "total": 14 }
}

Country Sections (Narrative Content)

Access detailed narrative content for any country — government structure, economy overview, demographics, military, infrastructure, and more. Data sourced from the CIA World Factbook. This country profile API endpoint serves the same structured content that powered the World Factbook — ideal for building country encyclopedias, educational apps, and AI agents.

Access: Premium and Enterprise plans. Demo countries (Colombia, Italy, Australia) available on all plans including anonymous.

GET/api/v1/countries/:slug/sections

Narrative country profile with 13 sections: introduction, geography, people-and-society, government, economy, energy, communications, transportation, military-and-security, terrorism, transnational-issues, space, environment.

NameTypeRequiredDescription
slugstringYesCountry slug, ISO code (AR, JP), or alias (usa, uk)
sectionstringNoSpecific section key (e.g. government, economy). Omit for all sections.
langstringNoLanguage: en, es, pt, it (default: en)
curl
curl -H "X-API-Key: bw_live_your_key" \
  "https://bamwor.com/api/v1/countries/argentina/sections?section=government"
Response
{
  "data": {
    "country": { "name": "Argentina", "slug": "argentina", "iso_code": "AR" },
    "sections": {
      "government": {
        "Country name": { "conventional long form": { "text": "Argentine Republic" }, ... },
        "Government type": { "text": "presidential republic" },
        "Capital": { "name": { "text": "Buenos Aires" }, ... },
        ...
      }
    },
    "section_count": 1
  }
}
// Non-premium: 403 PREMIUM_REQUIRED (demo: colombia, italy, australia)

API Key Management

POST/api/v1/keys

Register a new free API key.

NameTypeRequiredDescription
emailstringYesYour email address
namestringNoApp or project name
curl
curl -X POST https://bamwor.com/api/v1/keys \
  -H "Content-Type: application/json" \
  -d '{"email": "[email protected]", "name": "My App"}'
Response
{
  "data": {
    "api_key": "bw_live_a1b2c3d4e5f6...",
    "plan": "free",
    "limits": { "per_minute": 30, "per_day": 1000 },
    "message": "Store this key securely — it cannot be retrieved later."
  }
}
GET/api/v1/keys/usage

Check your current API key usage and remaining limits.

curl
curl -H "X-API-Key: bw_live_your_key" \
  https://bamwor.com/api/v1/keys/usage
Response
{
  "data": {
    "plan": "free",
    "usage": {
      "minute": { "used": 5, "limit": 30, "resets_in": 42 },
      "day": { "used": 127, "limit": 1000, "resets_in": 54321 }
    }
  }
}