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
- Create an account and confirm your email. A test key is waiting in the dashboard.
- Call the reverse lookup from your server with that key.
- 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.
| Prefix | Use it for | Burnable |
|---|---|---|
| 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-1.9525.lng number30.0972.lang en | rw | frUmujyi wa Kigali in rw. Defaults to en.boundaries stringcurl "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.
Search
GET /v1/search
q stringlang en | rw | frboundaries stringReturns 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 stringKimihurura.level province | district | sector | cell | villagelimit 1–50GET /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": "…" } }.
| 400 | invalid_coordinates | lat or lng is missing or not a number. |
| 400 | invalid_lang | lang isn't en, rw or fr. |
| 400 | invalid_query | q is empty or too long (search: 1 to 200 characters; areas: 2 to 100). |
| 400 | invalid_code | An area code isn't 1, 2, 4, 6 or 8 digits. |
| 400 | invalid_level | level isn't province, district, sector, cell or village. |
| 400 | invalid_limit | limit isn't between 1 and 50. |
| 400 | invalid_file | A batch file has no data rows, or a form upload has no field named file. |
| 400 | missing_columns | A batch file has no lat and lng columns. |
| 401 | missing_key | No Authorization header was sent. |
| 401 | invalid_key | The key doesn't exist or was revoked. |
| 401 | key_burned | Someone burned this key. Create a replacement in the dashboard. |
| 403 | domain_not_allowed | A publishable key was used on a site that isn't on its domain list. |
| 403 | secret_key_required | Batch upload was called with a publishable key. |
| 403 | plan_required | Batch upload with a live key needs the Business or Enterprise plan. |
| 404 | outside_rwanda | The point is outside Rwanda. |
| 404 | area_not_found | No area has that code. |
| 404 | unknown_boundaries | No boundary release has that id. |
| 413 | too_many_rows | A batch file has more rows than your key allows. Split it. |
| 413 | file_too_large | A batch file is over 20 MB. |
| 429 | rate_limited | Too many calls. Wait for the Retry-After seconds. |
| 429 | plan_limit_reached | This month's included live calls are used up. Upgrade your plan in the dashboard. |
| 500 | server_error | Something failed on our side. Safe to retry. |
| 503 | search_unavailable | Search 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 keys | 100 calls a minute |
| Live, Free plan | 10 calls a second |
| Live, Business plan | 50 calls a second |
| Live, Enterprise / Government | 200 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.