Farun API Reference
This is the complete reference for the Farun self-hosted server. It exposes vector tile serving, address and place search powered by Elasticsearch, and a full routing engine backed by Valhalla - covering turn-by-turn directions, isochrones, elevation profiles, time/distance matrices, optimised routes, and map matching.
your-host throughout
this reference with your actual server address or IP. Interactive
API docs are available at http://your-host/docs (Swagger) and http://your-host/redoc.
Endpoint index
/health /sources /tiles/{source} /tiles/{source}/{z}/{x}/{y} /static /search /search/reverse /search/detail/{doc_id} /costings /costing/options/{costing} /route /isochrone /elevation /matrix /optimised_route /map_match /map_match/attributes Base URL & Configuration
All endpoints are relative to the server root. No path
prefix. Default port is 3000, configurable
via the PORT environment variable.
# Self-hosted Farun Tile + Routing Server
http://your-host # replace with your actual host
# Default port (configurable via PORT env var)
http://your-host:3000
# FastAPI auto-generated interactive docs also available at:
http://your-host/docs # Swagger UI
http://your-host/redoc # ReDoc Environment variables
PORT 3000 HOST 0.0.0.0 MBTILES_DIR ./mbtiles TILE_CACHE_MAX_AGE 86400 STATIC_CACHE_DIR /app/static_cache ES_URL http://localhost:9200 ES_INDEX sa_addresses ES_TIMEOUT 5 VALHALLA_URL http://localhost:8002 VALHALLA_TIMEOUT 30 Status Codes
200 204 400 404 422 500 503 504 /health Server liveness check. No parameters. Suitable for load-balancer health probes.
curl http://your-host/health Response (200 OK)
status string uptime string { "status": "ok", "uptime": "142s" } /sources
Lists all .mbtiles files loaded from MBTILES_DIR, with metadata and tile URL templates.
curl http://your-host/sources Source object fields
id string name string description string format string minzoom integer maxzoom integer bounds string center string tiles string tilejson string {
"sources": [{
"id": "south_africa",
"name": "South Africa Streets",
"description": "OSM extract",
"format": "pbf",
"minzoom": 0,
"maxzoom": 14,
"bounds": "16.3,-34.9,32.9,-22.1",
"center": "25.0,-29.0,6",
"tiles": "http://your-host/tiles/south_africa/{z}/{x}/{y}",
"tilejson": "http://your-host/tiles/south_africa"
}]
} /tiles/{source}
Returns a TileJSON 3.0.0 document. The recommended way
to integrate with MapLibre GL or Mapbox GL - pass this
URL as the source url and the renderer auto-configures
itself.
Path parameters
sourcestring · required /sources).
Returns 404 if not found.
curl http://your-host/tiles/south_africa Additional response fields vs /sources
tilejson string scheme string attribution string version string vector_layers object[] /tiles/{source}/{z}/{x}/{y} Fetches a single Mapbox Vector Tile (PBF). XYZ convention - TMS y-flip is handled internally. In-memory LRU cache of 200,000 tiles.
Path parameters
source string · required z integer · required x integer · required y integer · required curl -o tile.pbf http://your-host/tiles/south_africa/10/567/432 Response headers (200)
Content-Type application/x-protobuf Content-Encoding gzip - Only present when tile data is already gzip-compressed in MBTiles Cache-Control public, max-age=86400 - Controlled by TILE_CACHE_MAX_AGE env var Access-Control-Allow-Origin * - CORS open for all origins Vary Accept-Encoding Status codes
200 204 400 404 /static Looks up and returns a pre-rendered JPEG from the static cache directory. Cache lookup only - does not render on demand. Returns 404 if no matching image exists.
Request body (JSON)
center float[2] · required zoom float · required tile_source string · required width integer · optional height integer · optional bearing float · optional curl -X POST http://your-host/static \
-H 'Content-Type: application/json' \
-d '{"center":[18.4241,-33.9249],"zoom":12,"tile_source":"south_africa"}' \
--output map.jpg Status codes
200 404 422 /search Autocomplete-optimised full-text search powered by Elasticsearch. Sub-20ms latency. Safe to call on every keystroke after 2 characters.
Query parameters
q string · required types string · optional lat float · optional lon float · optional size integer · optional # Basic search
curl 'http://your-host/search?q=Cape+Town'
# With type filter + proximity bias
curl 'http://your-host/search?q=Bree+Street&types=street,address&lat=-33.92&lon=18.42&size=5' Result object fields
id string score float doc_type string display_name string name string housenumber string street string suburb string city string postcode string province string country string place_class string highway string category string brand string phone string location object osm_id string /search/detail/{id} only when a user selects
a result. This keeps list response payloads small.
{
"query": "Cape Town",
"total": 142,
"took_ms": 8,
"results": [{
"id": "abc123",
"score": 24.871,
"doc_type": "place",
"display_name": "Cape Town, Western Cape, ZA",
"location": { "lat": -33.9249, "lon": 18.4241 }
}]
} /search/reverse Finds the nearest addresses or places to a coordinate. Only documents within 2 km are considered. Results sorted by distance ascending.
Query parameters
lat float · required lon float · required size integer · optional types string · optional curl 'http://your-host/search/reverse?lat=-33.9249&lon=18.4241&size=3&types=address' Additional response field
distance_mfloat {
"lat": -33.9249, "lon": 18.4241, "took_ms": 5,
"results": [{
"id": "xyz789",
"doc_type": "address",
"display_name": "12 Bree Street, Cape Town, 8000",
"distance_m": 34.2,
"location": { "lat": -33.9247, "lon": 18.4238 }
}]
} /search/detail/{doc_id}
Returns the full document for a single result ID -
including the GeoJSON geometry and wikidata fields that are excluded from list responses. Call only
when a user selects a result.
Path parameters
doc_idstring · required id field in /search or /search/reverse.
curl http://your-host/search/detail/abc123 Additional fields beyond list result
geometry object | null wikidata string | null {
"id": "abc123", "doc_type": "place",
"display_name": "Cape Town, Western Cape, ZA",
"location": { "lat": -33.9249, "lon": 18.4241 },
"geometry": { "type": "Point", "coordinates": [18.4241, -33.9249] },
"wikidata": "Q5465"
} /costings
Returns all available transport modes (costings) and
their descriptions. Use these IDs as the costing field in routing requests.
curl http://your-host/costings {
"costings": [
{ "id": "auto", "name": "Car", "description": "Fastest car route" },
{ "id": "auto_shorter", "name": "Car (shortest)", "description": "Shortest distance" },
{ "id": "truck", "name": "Truck/HGV", "description": "Heavy goods" },
{ "id": "bicycle", "name": "Bicycle", "description": "Cycling" },
{ "id": "pedestrian", "name": "Walking", "description": "On foot" },
{ "id": "motorcycle", "name": "Motorcycle", "description": "Motorbike" },
{ "id": "motor_scooter", "name": "Scooter", "description": "Scooter" },
{ "id": "bus", "name": "Bus", "description": "Bus" },
{ "id": "taxi", "name": "Taxi", "description": "Taxi" }
]
} /costing/options/{costing}
Returns the full JSON Schema of available options for a
transport mode. Use the returned field names as keys in
the costing_options body of routing requests.
Path parameters
costingstring · required auto, bicycle, pedestrian, truck, motorcycle, motor_scooter "costing_options": { "auto": { "use_highways": 0.5 } } - keyed by the costing mode name.
/route Turn-by-turn directions between two or more waypoints. Returns route geometry, step instructions, distance, and duration. Supports up to 3 alternative routes.
Request body (JSON)
locations Location[] · required costing string · required costing_options object · optional directions_options object · optional alternates integer · optional avoid_locations object[] · optional avoid_polygons float[][][] · optional shape_format string · optional date_time object · optional elevation_interval float · optional Location Object
lon float · required lat float · required type string · optional heading float · optional heading_tolerance float · optional name string · optional street string · optional waiting_secs integer · optional search_radius integer · optional preferred_side string · optional curl -X POST http://your-host/route \
-H 'Content-Type: application/json' \
-d '{
"locations": [
{"lon": 18.4241, "lat": -33.9249},
{"lon": 18.8602, "lat": -33.9321}
],
"costing": "auto"
}' /isochrone Generates reachability polygons from a single origin point. Contours can be time-based (minutes) or distance-based (kilometres) - not both in the same request. Returns GeoJSON FeatureCollection.
Request body (JSON)
locations Location[1] · required costing string · required contours object[] · required costing_options object · optional polygons boolean · optional denoise float · optional generalize float · optional show_locations boolean · optional # Time-based (minutes)
curl -X POST http://your-host/isochrone \
-H 'Content-Type: application/json' \
-d '{
"locations": [{"lon": 18.4241, "lat": -33.9249}],
"costing": "auto",
"contours": [{"time": 15}, {"time": 30}, {"time": 45}],
"polygons": true,
"generalize": 50
}'
# Distance-based (kilometres)
curl -X POST http://your-host/isochrone \
-H 'Content-Type: application/json' \
-d '{
"locations": [{"lon": 18.4241, "lat": -33.9249}],
"costing": "pedestrian",
"contours": [{"distance": 2}, {"distance": 5}]
}' /elevation Returns terrain elevation for a series of coordinates along a path. Input can be a coordinate array or an encoded polyline string.
Request body (JSON)
shape object[] · optional* encoded_polyline string · optional* range boolean · optional height_precision integer · optional resample_distance float · optional shape_format string · optional # Shape as coordinate array
curl -X POST http://your-host/elevation \
-H 'Content-Type: application/json' \
-d '{
"shape": [
{"lon": 18.4241, "lat": -33.9249},
{"lon": 18.5000, "lat": -33.9500},
{"lon": 18.8602, "lat": -33.9321}
],
"range": true
}'
# Encoded polyline (polyline6)
curl -X POST http://your-host/elevation \
-H 'Content-Type: application/json' \
-d '{"encoded_polyline": "qp~IvskA...", "range": true}' /matrix Computes a many-to-many time and distance matrix between any number of source and target locations. Returns travel time and distance for every source→target pair.
Request body (JSON)
sources Location[] · required targets Location[] · required costing string · required costing_options object · optional units string · optional curl -X POST http://your-host/matrix \
-H 'Content-Type: application/json' \
-d '{
"sources": [{"lon": 18.4241, "lat": -33.9249}],
"targets": [
{"lon": 18.8602, "lat": -33.9321},
{"lon": 18.5500, "lat": -33.9800}
],
"costing": "auto",
"units": "kilometers"
}' /optimised_route Solves the Travelling Salesman Problem - finds the optimal visit order for a set of locations to minimise total route cost. Returns a full route with the reordered stops.
Request body (JSON)
locations Location[] · required costing string · required costing_options object · optional directions_options object · optional curl -X POST http://your-host/optimised_route \
-H 'Content-Type: application/json' \
-d '{
"locations": [
{"lon": 18.4241, "lat": -33.9249},
{"lon": 18.8602, "lat": -33.9321},
{"lon": 18.5500, "lat": -33.9800},
{"lon": 18.6700, "lat": -34.0100}
],
"costing": "auto"
}' /map_match Snaps a raw GPS trace to the most likely path on the road network. Returns a cleaned route with turn-by-turn directions. Useful for post-processing recorded vehicle or device tracks.
Request body (JSON)
shape object[] · optional* encoded_polyline string · optional* costing string · required shape_match string · optional costing_options object · optional directions_options object · optional trace_options object · optional units string · optional curl -X POST http://your-host/map_match \
-H 'Content-Type: application/json' \
-d '{
"shape": [
{"lon": 18.4241, "lat": -33.9249, "time": 0},
{"lon": 18.5000, "lat": -33.9500, "time": 30},
{"lon": 18.8602, "lat": -33.9321, "time": 90}
],
"costing": "auto",
"shape_match": "map_snap"
}' /map_match/attributes
Same input as /map_match but returns detailed
edge-level attributes for each matched road segment - speed
limits, surface type, road class, and more. Useful for road
quality analysis and insurance telematics.
Accepts the same request body as /map_match.