AHANTU
Sign inGet a key
Docs · v1

API reference

Base URL https://api.ahantu.rw. Answers are JSON, except a batch result, which is a CSV. The full spec is at api.ahantu.rw/openapi.yaml (OpenAPI 3.1), for generating a client or importing into Postman.

On this page

Quick start

  1. Create an account and confirm your email. A test key is waiting in the dashboard.
  2. Call the reverse lookup from your server with that key.
  3. Add a payment method and create a live key when you're ready to go live.
curl "https://api.ahantu.rw/v1/reverse?lat=-1.95250&lng=30.09720&lang=en" \
  -H "Authorization: Bearer $AHANTU_KEY"

# 200 OK
{
  "province": { "name": "City of Kigali", "code": "1" },
  "district": { "name": "Gasabo",         "code": "12" },
  "sector":   { "name": "Kimihurura",     "code": "1208" },
  "cell":     { "name": "Kamukina",       "code": "120801" },
  "village":  { "name": "Juru",           "code": "12080106" },
  "snapped_m": 0,
  "boundaries": "nisr-2022"
}

Keys and environments

Send your key as a bearer token: Authorization: Bearer ahk_…. Every key belongs to one environment and has one type, both readable from its prefix.

PrefixUse it forBurnable
ahk_test_sk_Your server, while building. Real data, not billed, 100 calls a minute.Yes
ahk_live_sk_Your server, in production. Billed per your plan.Yes
ahk_test_pk_ · ahk_live_pk_The autofill widget in a web page or app. Lookups only, locked to your domains.No

Secret keys must never go into an app or a web page. We only show a key once, when you create or roll it.

Reverse lookup

GET /v1/reverse

lat number
Latitude in decimal degrees, e.g. -1.9525.
lng number
Longitude in decimal degrees, e.g. 30.0972.
lang en | rw | fr
Language for level names where they differ, e.g. Umujyi wa Kigali in rw. Defaults to en.
boundaries string
Optional. A boundary release id, to pin your results to one release (see Boundary data). Defaults to the current one.
curl "https://api.ahantu.rw/v1/reverse?lat=-1.95250&lng=30.09720&lang=en" \
  -H "Authorization: Bearer $AHANTU_KEY"

# 200 OK
{
  "province": { "name": "City of Kigali", "code": "1" },
  "district": { "name": "Gasabo",         "code": "12" },
  "sector":   { "name": "Kimihurura",     "code": "1208" },
  "cell":     { "name": "Kamukina",       "code": "120801" },
  "village":  { "name": "Juru",           "code": "12080106" },
  "snapped_m": 0,
  "boundaries": "nisr-2022"
}

Each level has its official NISR name and code. Villages don't always meet exactly, along rivers and borders for example, so a point up to 50 m outside every village is moved to the nearest one. snapped_m says how far it moved, and is 0 when the point was inside. boundaries is the release that answered.

GET /v1/search

q string
A place, landmark or street address in Rwanda.
lang en | rw | fr
As above.
boundaries string
As above.

Returns up to five matches in Rwanda, best first, or an empty list when nothing matches. match is the place's name, to show your user so they can confirm it. precise is true for a specific spot (a business, landmark, building or street address) and false for an area or a whole street, where the point is only its centre. When nobody can confirm, accept precise matches and send the rest for review. type is the kind of place, e.g. market, street_address or neighborhood.

curl "https://api.ahantu.rw/v1/search?q=Kigali+Convention+Centre&lang=en" \
  -H "Authorization: Bearer $AHANTU_KEY"

# 200 OK
{
  "results": [
    {
      "match": "Kigali Convention Centre",
      "address": "23VV+MQ9, Convention Ctr Roundabout, Kigali",
      "type": "convention_center",
      "precise": true,
      "lat": -1.9545556, "lng": 30.0938534,
      "province": { "name": "City of Kigali", "code": "1" },
      "district": { "name": "Gasabo",         "code": "12" },
      "sector":   { "name": "Kimihurura",     "code": "1208" },
      "cell":     { "name": "Rugando",        "code": "120803" },
      "village":  { "name": "Rebero",         "code": "12080304" },
      "snapped_m": 0,
      "boundaries": "nisr-2022"
    }
  ]
}

Areas

Browse and search the five levels by name and code, for dropdowns, forms and checks. All three take lang and boundaries like the endpoints above.

GET /v1/areas

Without parameters, the five provinces. With a name, a search that forgives typos, best match first, each with the levels above it.

q string
Optional. Part of a name, 2 to 100 characters, e.g. Kimihurura.
level province | district | sector | cell | village
Optional. Only return areas at this level.
limit 1–50
Optional. How many matches to return. Defaults to 10.

GET /v1/areas/{code}

One area by its NISR code (1 digit for a province, 2 for a district, 4 for a sector, 6 for a cell, 8 for a village), with the levels above it. Add outline=true to also get its outline as a GeoJSON MultiPolygon, for drawing it on a map.

GET /v1/areas/{code}/children

The areas one level down, by name: a district's sectors, a sector's cells, a cell's villages.

curl "https://api.ahantu.rw/v1/areas?q=Kimihurura&level=sector" \
  -H "Authorization: Bearer $AHANTU_KEY"

# 200 OK
{
  "areas": [
    {
      "code": "1208", "level": "sector", "name": "Kimihurura",
      "province": { "name": "City of Kigali", "code": "1" },
      "district": { "name": "Gasabo",         "code": "12" },
      "sector":   { "name": "Kimihurura",     "code": "1208" }
    }
  ],
  "boundaries": "nisr-2022"
}

curl "https://api.ahantu.rw/v1/areas/1208/children" \
  -H "Authorization: Bearer $AHANTU_KEY"

# 200 OK
{
  "parent": "1208",
  "areas": [
    { "code": "120801", "level": "cell", "name": "Kamukina" },
    { "code": "120802", "level": "cell", "name": "Kimihurura" },
    { "code": "120803", "level": "cell", "name": "Rugando" }
  ],
  "boundaries": "nisr-2022"
}

What counts as a call

Every request to /v1 that answers 200 is one call: a reverse lookup, a search or an areas request. Errors are free, including outside_rwanda, bad input, rejected keys and our own failures. In a batch file, each matched row is one call. Test keys are never billed. Live calls count against your plan's monthly allowance, which you can see in the dashboard under Usage.

Errors

Errors use the HTTP status and a body like { "error": { "code": "outside_rwanda", "message": "…" } }.

400invalid_coordinateslat or lng is missing or not a number.
400invalid_langlang isn't en, rw or fr.
400invalid_queryq is empty or too long (search: 1 to 200 characters; areas: 2 to 100).
400invalid_codeAn area code isn't 1, 2, 4, 6 or 8 digits.
400invalid_levellevel isn't province, district, sector, cell or village.
400invalid_limitlimit isn't between 1 and 50.
400invalid_fileA batch file has no data rows, or a form upload has no field named file.
400missing_columnsA batch file has no lat and lng columns.
401missing_keyNo Authorization header was sent.
401invalid_keyThe key doesn't exist or was revoked.
401key_burnedSomeone burned this key. Create a replacement in the dashboard.
403domain_not_allowedA publishable key was used on a site that isn't on its domain list.
403secret_key_requiredBatch upload was called with a publishable key.
403plan_requiredBatch upload with a live key needs the Business or Enterprise plan.
404outside_rwandaThe point is outside Rwanda.
404area_not_foundNo area has that code.
404unknown_boundariesNo boundary release has that id.
413too_many_rowsA batch file has more rows than your key allows. Split it.
413file_too_largeA batch file is over 20 MB.
429rate_limitedToo many calls. Wait for the Retry-After seconds.
429plan_limit_reachedThis month's included live calls are used up. Upgrade your plan in the dashboard.
500server_errorSomething failed on our side. Safe to retry.
503search_unavailableSearch is down for a moment. Reverse lookups and areas still work.

Rate limits

Limits apply to each key. Short bursts of up to twice the per-second rate are fine.

Test keys100 calls a minute
Live, Free plan10 calls a second
Live, Business plan50 calls a second
Live, Enterprise / Government200 calls a second

Every response carries RateLimit-Remaining; a 429 carries Retry-After, in seconds. There's also a limit of 600 calls a minute from one IP address, whatever the key, to slow down abuse.

Burning a key

Anyone holding a secret key can switch it off with POST /v1/keys/burn, using the key itself as the bearer token. It can't read anything else. The owner is emailed and the key returns 401 key_burned from then on. There's also a burn form.

Autofill widget

Uses a publishable key and only works on the domains you list for that key. It shows a small "Addresses by AHANTU" badge under the results; set badge: false to hide it. Load it from cdn.ahantu.rw/v0/widget.js to get fixes automatically but never a breaking change.

<input id="address" />
<input id="province" /> <input id="district" /> <input id="sector" />
<input id="cell" /> <input id="village" />

<script src="https://cdn.ahantu.rw/v0/widget.js"></script>
<script>
  Ahantu.autofill("#address", {
    key: "ahk_live_pk_…",   // publishable key, locked to your domain
    lang: "rw",
    fields: {
      province: "#province", district: "#district",
      sector: "#sector", cell: "#cell", village: "#village"
    }
  });
</script>

Batch upload

In the dashboard, upload a CSV with lat and lng columns (or latitude and longitude). You get it back with province, district, sector, cell and village columns, plus a list of rows we couldn't match and why. Files are deleted after 7 days.

From your server, send the CSV to POST /v1/batch with a secret key, either as a form field named file or as the raw body (add ?name=stores.csv to keep its name). Check GET /v1/batch/{id} until its status is done, then download GET /v1/batch/{id}/result.

Files can be up to 20 MB. Test keys take up to 100 rows per file on any plan. With live keys, the Business plan takes up to 50,000 rows per file, as long as they fit in what's left of the month's allowance, and Enterprise has no row limit. Free can't batch upload with live keys. Each matched row counts as one call.

Boundary data

Every response names the boundary release it used, e.g. "boundaries": "nisr-2022", the NISR boundaries currently in use, with official codes for each level. When boundaries change we publish a new release and keep the old one available for a while: send boundaries=nisr-2022 on any request to keep getting answers from it.